[2] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
[74] | 3 | # Base subroutines for the Project-Builder project
|
---|
[2] | 4 | #
|
---|
| 5 | # $Id$
|
---|
| 6 | #
|
---|
| 7 |
|
---|
[18] | 8 | use strict;
|
---|
[5] | 9 | use lib qw (lib);
|
---|
[2] | 10 | use File::Basename;
|
---|
[9] | 11 | use File::Path;
|
---|
[2] | 12 | use File::Temp qw /tempdir/;
|
---|
[8] | 13 | use Data::Dumper;
|
---|
[2] | 14 |
|
---|
[199] | 15 | use ProjectBuilder::Changelog qw (pb_changelog);
|
---|
| 16 |
|
---|
[49] | 17 | $ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
|
---|
[5] | 18 |
|
---|
[74] | 19 | sub pb_env_init {
|
---|
[2] | 20 |
|
---|
[273] | 21 | my $proj=shift || undef;
|
---|
| 22 | my $pbinit=shift || undef;
|
---|
[5] | 23 | my $ver;
|
---|
| 24 | my $tag;
|
---|
[2] | 25 |
|
---|
[107] | 26 | # For the moment not dynamic
|
---|
| 27 | my $debug = 0; # Debug level
|
---|
| 28 | my $LOG = *STDOUT; # Where to log
|
---|
| 29 |
|
---|
[8] | 30 | #
|
---|
[5] | 31 | # Check project name
|
---|
[49] | 32 | # Could be with env var PBPROJ
|
---|
| 33 | # or option -p
|
---|
| 34 | # if not define take the first in conf file
|
---|
[8] | 35 | #
|
---|
[5] | 36 | if ((defined $ENV{'PBPROJ'}) &&
|
---|
| 37 | (not (defined $proj))) {
|
---|
| 38 | $proj = $ENV{'PBPROJ'};
|
---|
| 39 | }
|
---|
[69] | 40 |
|
---|
[49] | 41 | #
|
---|
[313] | 42 | # We get the pbconf file for that project
|
---|
[69] | 43 | # and use its content
|
---|
| 44 | #
|
---|
[313] | 45 | my ($pbconf) = pb_conf_read("$ENV{'PBETC'}","pbconf");
|
---|
| 46 | print "DEBUG pbconf: ".Dumper($pbconf)."\n" if ($debug >= 1);
|
---|
[69] | 47 |
|
---|
[313] | 48 | my %pbconf = %$pbconf;
|
---|
[69] | 49 | if (not defined $proj) {
|
---|
| 50 | # Take the first as the default project
|
---|
[313] | 51 | $proj = (keys %pbconf)[0];
|
---|
| 52 | if (($debug >= 0) and (defined $proj)) {
|
---|
| 53 | print $LOG "WARNING: using $proj as default project as none has been specified\n"
|
---|
| 54 | print $LOG "Please create a pbconf reference for project $proj in $ENV{'PBETC'}\nif you want to use another project\n";
|
---|
| 55 | }
|
---|
[69] | 56 | }
|
---|
[313] | 57 | die "No project defined - use env var PBPROJ or -p proj or a pbconf entry in $ENV{'PBETC'}" if (not (defined $proj));
|
---|
[69] | 58 |
|
---|
[313] | 59 | # That's always the environment variable that will be used
|
---|
| 60 | $ENV{'PBPROJ'} = $proj;
|
---|
| 61 |
|
---|
| 62 | if (not defined ($pbconf{$ENV{'PBPROJ'}})) {
|
---|
| 63 | die "Please create a pbconf reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n";
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[69] | 66 | #
|
---|
[313] | 67 | # Detect the root dir for hosting all the content generated with pb
|
---|
[69] | 68 | #
|
---|
[314] | 69 | # Tree will look like this:
|
---|
| 70 | #
|
---|
| 71 | # maint pbdir dev dir (optional)
|
---|
| 72 | # | |
|
---|
| 73 | # ------------------------ --------------------
|
---|
| 74 | # | | | |
|
---|
| 75 | # pbproj1 pbproj2 pbproj1 pbproj2
|
---|
| 76 | # | |
|
---|
| 77 | # --------------------------------------------- ----------
|
---|
| 78 | # * * | | | | * *
|
---|
| 79 | # 1.0 dev pbconf ... build delivery 1.0 dev
|
---|
| 80 | # | | |
|
---|
| 81 | # ------ pbrc
|
---|
| 82 | # | |
|
---|
| 83 | # 1.0 dev
|
---|
| 84 | # |
|
---|
| 85 | # ----------------------------------
|
---|
| 86 | # | | | |
|
---|
| 87 | # pkg1 pbproj1.pb pbfilter pbcl
|
---|
| 88 | # |
|
---|
| 89 | # -----------------
|
---|
| 90 | # | | |
|
---|
| 91 | # rpm deb pbfilter
|
---|
| 92 | #
|
---|
| 93 | #
|
---|
| 94 | # (*) By default, if no relocation in .pbrc, dev dir is taken in the maint pbdir (when appropriate)
|
---|
| 95 | # Names under a pbproj and the corresponding pbconf should be similar
|
---|
| 96 | #
|
---|
[313] | 97 |
|
---|
[314] | 98 | my ($pbdir) = pb_conf_get_if("pbdir");
|
---|
| 99 | my %pbdir = %$pbdir;
|
---|
| 100 |
|
---|
| 101 | if (not defined $ENV{'PBDIR'}) {
|
---|
| 102 | if (not defined ($pbdir{$ENV{'PBPROJ'}})) {
|
---|
| 103 | print $LOG "WARNING: no pbdir defined, using /var/cache\n";
|
---|
| 104 | print $LOG "Please create a pbdir reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\nif you want to use another directory\n";
|
---|
[313] | 105 | }
|
---|
| 106 | # That's always the environment variable that will be used
|
---|
[314] | 107 | $ENV{'PBDIR'} = $pbdir{$ENV{'PBPROJ'}};
|
---|
[273] | 108 | }
|
---|
[108] | 109 | # Expand potential env variable in it
|
---|
[314] | 110 | eval { $ENV{'PBDIR'} =~ s/(\$ENV.+\})/$1/eeg };
|
---|
[69] | 111 |
|
---|
| 112 | #
|
---|
[313] | 113 | # Set delivery directory
|
---|
[49] | 114 | #
|
---|
[314] | 115 | $ENV{'PBDESTDIR'}="$ENV{'PBDIR'}/$ENV{'PBPROJ'}/delivery";
|
---|
[313] | 116 |
|
---|
| 117 | #
|
---|
| 118 | # Removes all directory existing below the delivery dir
|
---|
| 119 | # as they are temp dir only
|
---|
| 120 | # Files stay and have to be cleaned up manually if needed
|
---|
| 121 | # those files serves as communication channels between pb phases
|
---|
| 122 | # Removing them prevents a following phase to detect what has been done before
|
---|
| 123 | #
|
---|
| 124 | if (-d $ENV{'PBDESTDIR'}) {
|
---|
| 125 | opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
|
---|
| 126 | foreach my $d (readdir(DIR)) {
|
---|
| 127 | next if ($d =~ /^\./);
|
---|
| 128 | next if (-f "$ENV{'PBDESTDIR'}/$d");
|
---|
| 129 | pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
|
---|
[67] | 130 | }
|
---|
[313] | 131 | closedir(DIR);
|
---|
[49] | 132 | }
|
---|
[313] | 133 | if (! -d "$ENV{'PBDESTDIR'}") {
|
---|
| 134 | pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
|
---|
| 135 | }
|
---|
[2] | 136 |
|
---|
[8] | 137 | #
|
---|
[313] | 138 | # Set build directory
|
---|
[8] | 139 | #
|
---|
[314] | 140 | $ENV{'PBBUILDDIR'}="$ENV{'PBDIR'}/$ENV{'PBPROJ'}/build";
|
---|
[313] | 141 | if (! -d "$ENV{'PBBUILDDIR'}") {
|
---|
| 142 | pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | #
|
---|
| 146 | # Set temp directory
|
---|
| 147 | #
|
---|
| 148 | if (not defined $ENV{'TMPDIR'}) {
|
---|
| 149 | $ENV{'TMPDIR'}="/tmp";
|
---|
| 150 | }
|
---|
| 151 | $ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
|
---|
| 152 |
|
---|
| 153 | #
|
---|
| 154 | # Check pbconf compliance
|
---|
| 155 | #
|
---|
[314] | 156 | $ENV{'PBCONF'} = "$ENV{'PBDIR'}/$ENV{'PBPROJ'}/pbconf";
|
---|
[313] | 157 |
|
---|
[314] | 158 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($pbconf{$ENV{'PBPROJ'}});
|
---|
| 159 | my $cms = { $ENV{'PBPROJ'} => $scheme };
|
---|
[313] | 160 |
|
---|
[314] | 161 | if ((not -d "$ENV{'PBCONF'}") || (defined $pbinit)) {
|
---|
| 162 | pb_cms_checkout($cms,$pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONF'});
|
---|
| 163 | } else {
|
---|
| 164 | my $cmsurl = pb_cms_getinfo($cms,$ENV{'PBCONF'});
|
---|
| 165 | if ($cmsurl !~ /^$scheme/) {
|
---|
| 166 | pb_rm_rf("$ENV{'PBCONF'}");
|
---|
| 167 | pb_cms_checkout($cms,$pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONF'});
|
---|
| 168 | } elsif ($cmsurl ne $pbconf{$ENV{'PBPROJ'}}) {
|
---|
| 169 | # The local content doesn't correpond to the repository
|
---|
| 170 | print $LOG "ERROR: Inconsistency detected:\n";
|
---|
| 171 | print $LOG "* $ENV{'PBCONF'} refers to $cmsurl but\n";
|
---|
| 172 | print $LOG "* $ENV{'PBETC'} refers to $pbconf{$ENV{'PBPROJ'}}\n";
|
---|
| 173 | die "Project $ENV{'PBPROJ'} is not Project-Builder compliant.";
|
---|
| 174 | } else {
|
---|
| 175 | # they match - do nothing - there may be local changes
|
---|
[273] | 176 | }
|
---|
[314] | 177 | }
|
---|
[2] | 178 |
|
---|
[314] | 179 | # Check where is our PBROOT (release tag name can't be guessed the first time)
|
---|
| 180 | if (not defined $ENV{'PBROOT'}) {
|
---|
| 181 | if (! -f ("$ENV{'PBDESTDIR'}/pbrc")) {
|
---|
| 182 | opendir(DIR,$ENV{'PBCONF'}) || die "Unable to open directory $ENV{'PBCONF'}: $!";
|
---|
| 183 | my maxmtime = 0;
|
---|
| 184 | foreach my $d (readdir(DIR)) {
|
---|
| 185 | next if ($d =~ /^\./);
|
---|
| 186 | next if (! -d $d);
|
---|
| 187 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
|
---|
| 188 | = stat($d);
|
---|
| 189 | # Keep the most recent
|
---|
| 190 | if ($mtime > $maxmtime) {
|
---|
| 191 | $ENV{'PBROOT'} = "$ENV{'PBCONF'}/$d";
|
---|
| 192 | $maxmtime = $mtime;
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
| 195 | closedir(DIR);
|
---|
| 196 | print $LOG "WARNING: no pbroot defined, using $ENV{'PBROOT'}\n";
|
---|
| 197 | print $LOG "Please -r release if you want to use another release\n";
|
---|
| 198 | } else {
|
---|
| 199 | my ($pbroot) = pb_conf_read_if("$ENV{'PBDESTDIR'}/pbrc","pbroot");
|
---|
| 200 | # That's always the environment variable that will be used
|
---|
| 201 | $ENV{'PBROOT'} = $pbroot{$ENV{'PBPROJ'}};
|
---|
| 202 | }
|
---|
| 203 | } else {
|
---|
| 204 | # transform in full path if relative
|
---|
| 205 | $ENV{'PBROOT'} = "$ENV{'PBCONF'}/$ENV{'PBROOT'}" if ($ENV{'PBROOT'} !~ |/|);
|
---|
| 206 | }
|
---|
| 207 |
|
---|
[74] | 208 | my %version = ();
|
---|
[108] | 209 | my %defpkgdir = ();
|
---|
| 210 | my %extpkgdir = ();
|
---|
| 211 | my %filteredfiles = ();
|
---|
[300] | 212 | my %supfiles = ();
|
---|
[74] | 213 |
|
---|
[314] | 214 | if ((-f "$ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb") and (not defined $pbinit)) {
|
---|
[74] | 215 | # List of pkg to build by default (mandatory)
|
---|
[313] | 216 | my ($defpkgdir) = pb_conf_get("defpkgdir");
|
---|
[74] | 217 | # List of additional pkg to build when all is called (optional)
|
---|
| 218 | # Valid version names (optional)
|
---|
| 219 | # List of files to filter (optional)
|
---|
[313] | 220 | # Project version and tag (optional)
|
---|
| 221 | my ($extpkgdir, $version, $filteredfiles, $supfiles, $pkgv, $pkgt) = pb_conf_get_if("extpkgdir","version","filteredfiles","supfiles","projver","projtag");
|
---|
[74] | 222 | print "DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n" if ($debug >= 1);
|
---|
| 223 | print "DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n" if ($debug >= 1);
|
---|
| 224 | print "DEBUG: version: ".Dumper($version)."\n" if ($debug >= 1);
|
---|
| 225 | print "DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n" if ($debug >= 1);
|
---|
[300] | 226 | print "DEBUG: supfiles: ".Dumper($supfiles)."\n" if ($debug >= 1);
|
---|
[74] | 227 | # Global
|
---|
| 228 | %defpkgdir = %$defpkgdir;
|
---|
[114] | 229 | %extpkgdir = %$extpkgdir if (defined $extpkgdir);
|
---|
[74] | 230 | %version = %$version if (defined $version);
|
---|
| 231 | %filteredfiles = %$filteredfiles if (defined $filteredfiles);
|
---|
[300] | 232 | %supfiles = %$supfiles if (defined $supfiles);
|
---|
[106] | 233 | #
|
---|
| 234 | # Get global Version/Tag
|
---|
| 235 | #
|
---|
| 236 | if (not defined $ENV{'PBVER'}) {
|
---|
[313] | 237 | if ((defined $pkgv) && (defined $pkgv->{$ENV{'PBPROJ'}})) {
|
---|
| 238 | $ENV{'PBVER'}=$pkgv->{$ENV{'PBPROJ'}};
|
---|
[106] | 239 | } else {
|
---|
[314] | 240 | die "No projver found in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
|
---|
[106] | 241 | }
|
---|
[98] | 242 | }
|
---|
[314] | 243 | die "Invalid version name $ENV{'PBVER'} in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb" if (($ENV{'PBVER'} !~ /[0-9.]+/) && (not defined $version) && ($ENV{'PBVER'} =~ /$version{$ENV{'PBPROJ'}}/));
|
---|
[106] | 244 |
|
---|
| 245 | if (not defined $ENV{'PBTAG'}) {
|
---|
[313] | 246 | if ((defined $pkgt) && (defined $pkgt->{$ENV{'PBPROJ'}})) {
|
---|
| 247 | $ENV{'PBTAG'}=$pkgt->{$ENV{'PBPROJ'}};
|
---|
[106] | 248 | } else {
|
---|
[314] | 249 | die "No projtag found in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
|
---|
[106] | 250 | }
|
---|
[98] | 251 | }
|
---|
[314] | 252 | die "Invalid tag name $ENV{'PBTAG'} in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb" if ($ENV{'PBTAG'} !~ /[0-9.]+/);
|
---|
[106] | 253 | } else {
|
---|
[273] | 254 | if (defined $pbinit) {
|
---|
[314] | 255 | open(CONF,"> $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb") || die "Unable to create $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
|
---|
[273] | 256 | print CONF << "EOF";
|
---|
| 257 | #
|
---|
| 258 | # Project Builder configuration file
|
---|
[313] | 259 | # For project $ENV{'PBPROJ'}
|
---|
[273] | 260 | #
|
---|
| 261 | # \$Id\$
|
---|
| 262 | #
|
---|
| 263 |
|
---|
| 264 | #
|
---|
| 265 | # Which CMS system is used (Subversion, CVS or tar file content extracted)
|
---|
| 266 | #
|
---|
[313] | 267 | #cms $ENV{'PBPROJ'} = svn
|
---|
| 268 | #cms $ENV{'PBPROJ'} = cvs
|
---|
| 269 | #cms $ENV{'PBPROJ'} = flat
|
---|
[273] | 270 |
|
---|
| 271 | #
|
---|
| 272 | # Packager label
|
---|
| 273 | #
|
---|
[313] | 274 | #packager $ENV{'PBPROJ'} = "William Porte <bill\@$ENV{'PBPROJ'}.org>"
|
---|
[273] | 275 | #
|
---|
| 276 |
|
---|
| 277 | # For delivery to a machine by SSH (potentially the FTP server)
|
---|
| 278 | # Needs hostname, account and directory
|
---|
| 279 | #
|
---|
[313] | 280 | #sshhost $ENV{'PBPROJ'} = www.$ENV{'PBPROJ'}.org
|
---|
| 281 | #sshlogin $ENV{'PBPROJ'} = bill
|
---|
| 282 | #sshdir $ENV{'PBPROJ'} = /$ENV{'PBPROJ'}/ftp
|
---|
| 283 | #sshport $ENV{'PBPROJ'} = 22
|
---|
[273] | 284 |
|
---|
| 285 | #
|
---|
| 286 | # For Virtual machines management
|
---|
| 287 | # Naming convention to follow: distribution name (as per ProjectBuilder::Distribution)
|
---|
| 288 | # followed by '_' and by release number
|
---|
| 289 | # a .vmtype extension will be added to the resulting string
|
---|
| 290 | # a QEMU rhel_3 here means that the VM will be named rhel_3.qemu
|
---|
| 291 | #
|
---|
[313] | 292 | #vmlist $ENV{'PBPROJ'} = mandrake_10.1,mandrake_10.2,mandriva_2006.0,mandriva_2007.0,mandriva_2007.1,mandriva_2008.0,redhat_7.3,redhat_9,fedora_4,fedora_5,fedora_6,fedora_7,rhel_3,rhel_4,rhel_5,suse_10.0,suse_10.1,suse_10.2,suse_10.3,sles_9,sles_10,gentoo_nover,debian_3.1,debian_4.0,ubuntu_6.06,ubuntu_7.04,ubuntu_7.10
|
---|
[273] | 293 |
|
---|
| 294 | #
|
---|
| 295 | # Valid values for vmtype are
|
---|
| 296 | # qemu, (vmware, xen, ... TBD)
|
---|
[313] | 297 | #vmtype $ENV{'PBPROJ'} = qemu
|
---|
[273] | 298 |
|
---|
| 299 | # Hash for VM stuff on vmtype
|
---|
| 300 | #vmntp default = pool.ntp.org
|
---|
| 301 |
|
---|
| 302 | # We suppose we can commmunicate with the VM through SSH
|
---|
[313] | 303 | #vmhost $ENV{'PBPROJ'} = localhost
|
---|
| 304 | #vmlogin $ENV{'PBPROJ'} = pb
|
---|
| 305 | #vmport $ENV{'PBPROJ'} = 2222
|
---|
[273] | 306 |
|
---|
| 307 | # Timeout to wait when VM is launched/stopped
|
---|
| 308 | #vmtmout default = 120
|
---|
| 309 |
|
---|
| 310 | # per VMs needed paramaters
|
---|
[313] | 311 | #vmopt $ENV{'PBPROJ'} = -m 384 -daemonize
|
---|
| 312 | #vmpath $ENV{'PBPROJ'} = /home/qemu
|
---|
| 313 | #vmsize $ENV{'PBPROJ'} = 5G
|
---|
[273] | 314 |
|
---|
| 315 | #
|
---|
| 316 | # Global version/tag for the project
|
---|
| 317 | #
|
---|
[313] | 318 | #projver $ENV{'PBPROJ'} = devel
|
---|
| 319 | #projtag $ENV{'PBPROJ'} = 1
|
---|
[273] | 320 |
|
---|
| 321 | # Adapt to your needs:
|
---|
| 322 | # Optional if you need to overwrite the global values above
|
---|
| 323 | #
|
---|
| 324 | #pkgver pkg1 = stable
|
---|
| 325 | #pkgtag pkg1 = 3
|
---|
| 326 | #pkgver nil
|
---|
| 327 | #pkgtag nil
|
---|
| 328 |
|
---|
| 329 | # Hash of default package/package directory
|
---|
| 330 | #defpkgdir pkg1 = pkg1dir
|
---|
| 331 |
|
---|
| 332 | # Hash of additional package/package directory
|
---|
| 333 | #extpkgdir pkg1-doc = pkg1-docdir
|
---|
| 334 |
|
---|
| 335 | # Hash of valid version names
|
---|
| 336 | #version devel
|
---|
| 337 | #version stable
|
---|
| 338 |
|
---|
| 339 | # List of files per pkg on which to apply filters
|
---|
| 340 | # Files are mentioned relatively to pbroot/defpkgdir
|
---|
| 341 | #filteredfiles pkg1 = Makefile.PL
|
---|
| 342 | #filteredfiles pkg1-doc = configure.in
|
---|
[300] | 343 | #supfiles pkg1 = pkg1.init
|
---|
[273] | 344 | EOF
|
---|
| 345 | close(CONF);
|
---|
[314] | 346 | pb_mkdir_p("$ENV{'PBROOT'}/pbfilter") || die "Unable to create $ENV{'PBROOT'}/pbfilter";
|
---|
| 347 | open(CONF,"> $ENV{'PBROOT'}/pbfilter/all.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/all.pbf";
|
---|
[273] | 348 | print CONF << "EOF";
|
---|
| 349 | #
|
---|
| 350 | # \$Id\$
|
---|
| 351 | #
|
---|
| 352 | # Filter for all files
|
---|
| 353 | #
|
---|
| 354 | # PBSRC is replaced by the source package format
|
---|
[313] | 355 | #filter PBSRC = ftp://ftp.$ENV{'PBPROJ'}.org/src/%{name}-%{version}.tar.gz
|
---|
[273] | 356 |
|
---|
| 357 | # PBVER is replaced by the version (\$pbver in code)
|
---|
| 358 | #filter PBVER = \$pbver
|
---|
| 359 |
|
---|
| 360 | # PBDATE is replaced by the date (\$pbdate in code)
|
---|
| 361 | #filter PBDATE = \$pbdate
|
---|
| 362 |
|
---|
| 363 | # PBLOG is replaced by the changelog if value is yes
|
---|
| 364 | #filter PBLOG = yes
|
---|
| 365 |
|
---|
| 366 | # PBTAG is replaced by the tag (\$pbtag in code)
|
---|
| 367 | #filter PBTAG = \$pbtag
|
---|
| 368 |
|
---|
| 369 | # PBREV is replaced by the revision (\$pbrev in code)
|
---|
| 370 | #filter PBREV = \$pbrev
|
---|
| 371 |
|
---|
| 372 | # PBPKG is replaced by the package name (\$pbpkg in code)
|
---|
| 373 | #filter PBPKG = \$pbpkg
|
---|
| 374 |
|
---|
| 375 | # PBPACKAGER is replaced by the packager name (\$pbpackager in code)
|
---|
| 376 | #filter PBPACKAGER = \$pbpackager
|
---|
| 377 |
|
---|
| 378 | # PBDESC contains the description of the package
|
---|
| 379 | #filter PBDESC = "Bla-Bla"
|
---|
| 380 |
|
---|
| 381 | # PBURL contains the URL of the Web site of the project
|
---|
[313] | 382 | #filter PBURL = http://www.$ENV{'PBPROJ'}.org
|
---|
[273] | 383 | EOF
|
---|
| 384 | close(CONF);
|
---|
[314] | 385 | open(CONF,"> $ENV{'PBROOT'}/pbfilter/rpm.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/rpm.pbf";
|
---|
[273] | 386 | print CONF << "EOF";
|
---|
| 387 | #
|
---|
| 388 | # \$Id\$
|
---|
| 389 | #
|
---|
| 390 | # Filter for rpm build
|
---|
| 391 | #
|
---|
| 392 |
|
---|
| 393 | # PBGRP is replaced by the RPM group of apps
|
---|
[288] | 394 | # Cf: http://fedoraproject.org/wiki/RPMGroups
|
---|
[273] | 395 | #filter PBGRP = Applications/Archiving
|
---|
| 396 |
|
---|
| 397 | # PBDEP is replaced by the list of dependencies
|
---|
| 398 | #filter PBDEP =
|
---|
| 399 |
|
---|
| 400 | # PBSUF is replaced by the package name (\$pbpkg in code)
|
---|
| 401 | #filter PBSUF = \$pbsuf
|
---|
| 402 |
|
---|
| 403 | # PBOBS is replaced by the Obsolete line
|
---|
| 404 | #filter PBOBS =
|
---|
| 405 |
|
---|
| 406 | EOF
|
---|
| 407 | close(CONF);
|
---|
[314] | 408 | open(CONF,"> $ENV{'PBROOT'}/pbfilter/deb.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/deb.pbf";
|
---|
[273] | 409 | print CONF << "EOF";
|
---|
| 410 | #
|
---|
| 411 | # \$Id\$
|
---|
| 412 | #
|
---|
| 413 | # Filter for debian build
|
---|
| 414 | #
|
---|
| 415 | # PBGRP is replaced by the group of apps
|
---|
| 416 | #filter PBGRP = utils
|
---|
| 417 |
|
---|
| 418 | # PBVER is replaced by the version (\$pbver in code)
|
---|
| 419 | #filter PBVER = \$pbver
|
---|
| 420 |
|
---|
| 421 | # PBDEP is replaced by the list of dependencies
|
---|
| 422 | #filter PBDEP =
|
---|
| 423 |
|
---|
| 424 | # PBSUG is replaced by the list of suggestions
|
---|
| 425 | #filter PBSUG =
|
---|
| 426 |
|
---|
| 427 | # PBREC is replaced by the list of recommandations
|
---|
| 428 | #filter PBREC =
|
---|
| 429 |
|
---|
| 430 | # PBLOG is replaced by the changelog if value is yes
|
---|
| 431 | #filter PBLOG = yes
|
---|
| 432 |
|
---|
| 433 | # PBPKG is replaced by the package name (\$pbpkg in code)
|
---|
| 434 | #filter PBPKG = \$pbpkg
|
---|
| 435 |
|
---|
| 436 | # PBPACKAGER is replaced by the packager name (\$pbpackager in code)
|
---|
| 437 | #filter PBPACKAGER = \$pbpackager
|
---|
| 438 |
|
---|
| 439 | EOF
|
---|
| 440 | close(CONF);
|
---|
[314] | 441 | open(CONF,"> $ENV{'PBROOT'}/pbfilter/md.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/md.pbf";
|
---|
[273] | 442 | print CONF << "EOF";
|
---|
[313] | 443 | # Specific group for Mandriva for $ENV{'PBPROJ'}
|
---|
[273] | 444 | filter PBGRP = Archiving/Backup
|
---|
| 445 | EOF
|
---|
| 446 | close(CONF);
|
---|
[314] | 447 | open(CONF,"> $ENV{'PBROOT'}/pbfilter/novell.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/novell.pbf";
|
---|
[273] | 448 | print CONF << "EOF";
|
---|
[313] | 449 | # Specific group for SuSE for $ENV{'PBPROJ'}
|
---|
[273] | 450 | filter PBGRP = Productivity/Archiving/Backup
|
---|
| 451 | EOF
|
---|
| 452 | close(CONF);
|
---|
[314] | 453 | pb_mkdir_p("$ENV{'PBROOT'}/pkg1/deb") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb";
|
---|
| 454 | open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/control") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/control";
|
---|
[273] | 455 | print CONF << "EOF";
|
---|
| 456 | Source: PBPKG
|
---|
| 457 | Section: PBGRP
|
---|
| 458 | Priority: optional
|
---|
| 459 | Maintainer: PBPACKAGER
|
---|
| 460 | Build-Depends: debhelper (>= 4.2.20), PBDEP
|
---|
| 461 | Standards-Version: 3.6.1
|
---|
| 462 |
|
---|
| 463 | Package: PBPKG
|
---|
| 464 | Architecture: amd64 i386 ia64
|
---|
| 465 | Section: PBGRP
|
---|
| 466 | Priority: optional
|
---|
| 467 | Depends: \${shlibs:Depends}, \${misc:Depends}, PBDEP
|
---|
| 468 | Recommends: PBREC
|
---|
| 469 | Suggests: PBSUG
|
---|
| 470 | Description:
|
---|
| 471 | PBDESC
|
---|
| 472 | .
|
---|
| 473 | Homepage: PBURL
|
---|
| 474 |
|
---|
| 475 | EOF
|
---|
| 476 | close(CONF);
|
---|
[314] | 477 | open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/copyright") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/copyright";
|
---|
[273] | 478 | print CONF << "EOF";
|
---|
| 479 | This package is debianized by PBPACKAGER
|
---|
| 480 | `date`
|
---|
| 481 |
|
---|
| 482 | The current upstream source was downloaded from
|
---|
[313] | 483 | ftp://ftp.$ENV{'PBPROJ'}.org/src/.
|
---|
[273] | 484 |
|
---|
| 485 | Upstream Authors: Put their name here
|
---|
| 486 |
|
---|
| 487 | Copyright:
|
---|
| 488 |
|
---|
| 489 | This package is free software; you can redistribute it and/or modify
|
---|
| 490 | it under the terms of the GNU General Public License as published by
|
---|
| 491 | the Free Software Foundation; version 2 dated June, 1991.
|
---|
| 492 |
|
---|
| 493 | This package is distributed in the hope that it will be useful,
|
---|
| 494 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 495 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 496 | GNU General Public License for more details.
|
---|
| 497 |
|
---|
| 498 | You should have received a copy of the GNU General Public License
|
---|
| 499 | along with this package; if not, write to the Free Software
|
---|
| 500 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
---|
| 501 | MA 02110-1301, USA.
|
---|
| 502 |
|
---|
| 503 | On Debian systems, the complete text of the GNU General
|
---|
| 504 | Public License can be found in /usr/share/common-licenses/GPL.
|
---|
| 505 |
|
---|
| 506 | EOF
|
---|
| 507 | close(CONF);
|
---|
[314] | 508 | open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/changelog") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/changelog";
|
---|
[273] | 509 | print CONF << "EOF";
|
---|
| 510 | PBLOG
|
---|
| 511 | EOF
|
---|
| 512 | close(CONF);
|
---|
[314] | 513 | open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/compat") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/compat";
|
---|
[273] | 514 | print CONF << "EOF";
|
---|
| 515 | 4
|
---|
| 516 | EOF
|
---|
| 517 | close(CONF);
|
---|
[314] | 518 | open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/pkg1.dirs") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/pkg1.dirs";
|
---|
[273] | 519 | print CONF << "EOF";
|
---|
| 520 | EOF
|
---|
| 521 | close(CONF);
|
---|
[314] | 522 | open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/pkg1.docs") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/pkg1.docs";
|
---|
[273] | 523 | print CONF << "EOF";
|
---|
| 524 | INSTALL
|
---|
| 525 | COPYING
|
---|
| 526 | AUTHORS
|
---|
| 527 | NEWS
|
---|
| 528 | README
|
---|
| 529 | EOF
|
---|
| 530 | close(CONF);
|
---|
[314] | 531 | open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/rules") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/rules";
|
---|
[273] | 532 | print CONF << 'EOF';
|
---|
| 533 | #!/usr/bin/make -f
|
---|
| 534 | # -*- makefile -*-
|
---|
| 535 | # Sample debian/rules that uses debhelper.
|
---|
| 536 | # GNU copyright 1997 to 1999 by Joey Hess.
|
---|
| 537 | #
|
---|
| 538 | # $Id$
|
---|
| 539 | #
|
---|
| 540 |
|
---|
| 541 | # Uncomment this to turn on verbose mode.
|
---|
| 542 | #export DH_VERBOSE=1
|
---|
| 543 |
|
---|
| 544 | # Define package name variable for a one-stop change.
|
---|
| 545 | PACKAGE_NAME = PBPKG
|
---|
| 546 |
|
---|
| 547 | # These are used for cross-compiling and for saving the configure script
|
---|
| 548 | # from having to guess our platform (since we know it already)
|
---|
| 549 | DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
|
---|
| 550 | DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
|
---|
| 551 |
|
---|
| 552 | CFLAGS = -Wall -g
|
---|
| 553 |
|
---|
| 554 | ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
|
---|
| 555 | CFLAGS += -O0
|
---|
| 556 | else
|
---|
| 557 | CFLAGS += -O2
|
---|
| 558 | endif
|
---|
| 559 | ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
|
---|
| 560 | INSTALL_PROGRAM += -s
|
---|
| 561 | endif
|
---|
| 562 | config.status: configure
|
---|
| 563 | dh_testdir
|
---|
| 564 |
|
---|
| 565 | # Configure the package.
|
---|
| 566 | CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr
|
---|
| 567 | --mandir=\$${prefix}/share/man
|
---|
| 568 |
|
---|
| 569 | # Build both architecture dependent and independent
|
---|
| 570 | build: build-arch build-indep
|
---|
| 571 |
|
---|
| 572 | # Build architecture dependent
|
---|
| 573 | build-arch: build-arch-stamp
|
---|
| 574 |
|
---|
| 575 | build-arch-stamp: config.status
|
---|
| 576 | dh_testdir
|
---|
| 577 |
|
---|
| 578 | # Compile the package.
|
---|
| 579 | $(MAKE)
|
---|
| 580 |
|
---|
| 581 | touch build-stamp
|
---|
| 582 |
|
---|
| 583 | # Build architecture independent
|
---|
| 584 | build-indep: build-indep-stamp
|
---|
| 585 |
|
---|
| 586 | build-indep-stamp: config.status
|
---|
| 587 | # Nothing to do, the only indep item is the manual which is available as html in original source
|
---|
| 588 | touch build-indep-stamp
|
---|
| 589 |
|
---|
| 590 | # Clean up
|
---|
| 591 | clean:
|
---|
| 592 | dh_testdir
|
---|
| 593 | dh_testroot
|
---|
| 594 | rm -f build-arch-stamp build-indep-stamp #CONFIGURE-STAMP#
|
---|
| 595 | # Clean temporary document directory
|
---|
| 596 | rm -rf debian/doc-temp
|
---|
| 597 | # Clean up.
|
---|
| 598 | -$(MAKE) distclean
|
---|
| 599 | rm -f config.log
|
---|
| 600 | ifneq "$(wildcard /usr/share/misc/config.sub)" ""
|
---|
| 601 | cp -f /usr/share/misc/config.sub config.sub
|
---|
| 602 | endif
|
---|
| 603 | ifneq "$(wildcard /usr/share/misc/config.guess)" ""
|
---|
| 604 | cp -f /usr/share/misc/config.guess config.guess
|
---|
| 605 | endif
|
---|
| 606 |
|
---|
| 607 | dh_clean
|
---|
| 608 |
|
---|
| 609 | # Install architecture dependent and independent
|
---|
| 610 | install: install-arch install-indep
|
---|
| 611 |
|
---|
| 612 | # Install architecture dependent
|
---|
| 613 | install-arch: build-arch
|
---|
| 614 | dh_testdir
|
---|
| 615 | dh_testroot
|
---|
| 616 | dh_clean -k -s
|
---|
| 617 | dh_installdirs -s
|
---|
| 618 |
|
---|
| 619 | # Install the package files into build directory:
|
---|
| 620 | # - start with upstream make install
|
---|
| 621 | $(MAKE) install prefix=$(CURDIR)/debian/$(PACKAGE_NAME)/usr mandir=$(CURDIR)/debian/$(PACKAGE_NAME)/us
|
---|
| 622 | r/share/man
|
---|
| 623 | # - copy html manual to temporary location for renaming
|
---|
| 624 | mkdir -p debian/doc-temp
|
---|
| 625 | dh_install -s
|
---|
| 626 |
|
---|
| 627 | # Install architecture independent
|
---|
| 628 | install-indep: build-indep
|
---|
| 629 | dh_testdir
|
---|
| 630 | dh_testroot
|
---|
| 631 | dh_clean -k -i
|
---|
| 632 | dh_installdirs -i
|
---|
| 633 | dh_install -i
|
---|
| 634 |
|
---|
| 635 | # Must not depend on anything. This is to be called by
|
---|
| 636 | # binary-arch/binary-indep
|
---|
| 637 | # in another 'make' thread.
|
---|
| 638 | binary-common:
|
---|
| 639 | dh_testdir
|
---|
| 640 | dh_testroot
|
---|
| 641 | dh_installchangelogs ChangeLog
|
---|
| 642 | dh_installdocs
|
---|
| 643 | dh_installman
|
---|
| 644 | dh_link
|
---|
| 645 | dh_strip
|
---|
| 646 | dh_compress
|
---|
| 647 | dh_fixperms
|
---|
| 648 | dh_installdeb
|
---|
| 649 | dh_shlibdeps
|
---|
| 650 | dh_gencontrol
|
---|
| 651 | dh_md5sums
|
---|
| 652 | dh_builddeb
|
---|
| 653 |
|
---|
| 654 | # Build architecture independant packages using the common target.
|
---|
| 655 | binary-indep: build-indep install-indep
|
---|
| 656 | $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
|
---|
| 657 |
|
---|
| 658 | # Build architecture dependant packages using the common target.
|
---|
| 659 | binary-arch: build-arch install-arch
|
---|
| 660 | $(MAKE) -f debian/rules DH_OPTIONS=-a binary-common
|
---|
| 661 |
|
---|
| 662 | # Build architecture depdendent and independent packages
|
---|
| 663 | binary: binary-arch binary-indep
|
---|
| 664 | .PHONY: clean binary
|
---|
| 665 |
|
---|
| 666 | EOF
|
---|
| 667 | close(CONF);
|
---|
[314] | 668 | pb_mkdir_p("$ENV{'PBROOT'}/pkg1/rpm") || die "Unable to create $ENV{'PBROOT'}/pkg1/rpm";
|
---|
| 669 | open(CONF,"> $ENV{'PBROOT'}/pkg1/rpm/pkg1.spec") || die "Unable to create $ENV{'PBROOT'}/pkg1/rpm/pkg1.spec";
|
---|
[273] | 670 | print CONF << 'EOF';
|
---|
| 671 | #
|
---|
| 672 | # $Id$
|
---|
| 673 | #
|
---|
| 674 |
|
---|
| 675 | Summary: bla-bla
|
---|
| 676 | Summary(fr): french bla-bla
|
---|
| 677 |
|
---|
| 678 | Name: PBPKG
|
---|
| 679 | Version: PBVER
|
---|
| 680 | Release: PBTAGPBSUF
|
---|
| 681 | License: GPL
|
---|
| 682 | Group: PBGRP
|
---|
| 683 | Url: PBURL
|
---|
| 684 | Source: PBSRC
|
---|
| 685 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(id -u -n)
|
---|
| 686 | Requires: PBDEP
|
---|
| 687 |
|
---|
| 688 | %description
|
---|
| 689 | PBDESC
|
---|
| 690 |
|
---|
| 691 | %description -l fr
|
---|
| 692 | french desc
|
---|
| 693 |
|
---|
| 694 | %prep
|
---|
| 695 | %setup -q
|
---|
| 696 |
|
---|
| 697 | %build
|
---|
| 698 | %configure
|
---|
[288] | 699 | make %{?_smp_mflags}
|
---|
[273] | 700 |
|
---|
| 701 | %install
|
---|
| 702 | %{__rm} -rf $RPM_BUILD_ROOT
|
---|
| 703 | make DESTDIR=$RPM_BUILD_ROOT install
|
---|
| 704 |
|
---|
| 705 | %clean
|
---|
| 706 | %{__rm} -rf $RPM_BUILD_ROOT
|
---|
| 707 |
|
---|
| 708 | %files
|
---|
| 709 | %defattr(-,root,root)
|
---|
| 710 | %doc ChangeLog
|
---|
| 711 | %doc INSTALL COPYING README AUTHORS NEWS
|
---|
| 712 |
|
---|
| 713 | %changelog
|
---|
| 714 | PBLOG
|
---|
| 715 |
|
---|
| 716 | EOF
|
---|
| 717 | close(CONF);
|
---|
[314] | 718 | pb_mkdir_p("$ENV{'PBROOT'}/pkg1/pbfilter") || die "Unable to create $ENV{'PBROOT'}/pkg1/pbfilter";
|
---|
[273] | 719 |
|
---|
| 720 | print "\nDo not to forget to commit the pbconf directory in your CMS if needed\n";
|
---|
| 721 | print "After having renamed the pkg1 directory to your package's name \n\n";
|
---|
| 722 | } else {
|
---|
[314] | 723 | die "Unable to open $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
|
---|
[273] | 724 | }
|
---|
[98] | 725 | }
|
---|
[8] | 726 | umask 0022;
|
---|
[314] | 727 | return($debug,$LOG, \%filteredfiles, \%supfiles, \%defpkgdir, \%extpkgdir);
|
---|
[2] | 728 | }
|
---|
[9] | 729 |
|
---|
[74] | 730 | # Internal mkdir -p function
|
---|
| 731 | sub pb_mkdir_p {
|
---|
[29] | 732 | my @dir = @_;
|
---|
| 733 | my $ret = mkpath(@dir, 0, 0755);
|
---|
| 734 | return($ret);
|
---|
[9] | 735 | }
|
---|
| 736 |
|
---|
[74] | 737 | # Internal rm -rf function
|
---|
| 738 | sub pb_rm_rf {
|
---|
[29] | 739 | my @dir = @_;
|
---|
| 740 | my $ret = rmtree(@dir, 0, 0);
|
---|
| 741 | return($ret);
|
---|
[9] | 742 | }
|
---|
| 743 |
|
---|
[74] | 744 | # Internal system function
|
---|
| 745 | sub pb_system {
|
---|
[29] | 746 |
|
---|
| 747 | my $cmd=shift;
|
---|
[30] | 748 | my $cmt=shift || $cmd;
|
---|
[29] | 749 |
|
---|
[108] | 750 | print "$cmt... ";
|
---|
[117] | 751 | #system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
|
---|
[293] | 752 | system($cmd);
|
---|
[29] | 753 | if ($? == -1) {
|
---|
[108] | 754 | print "failed to execute ($cmd) : $!\n";
|
---|
[106] | 755 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
[29] | 756 | } elsif ($? & 127) {
|
---|
[108] | 757 | printf "child ($cmd) died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
|
---|
[106] | 758 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
| 759 | } elsif ($? == 0) {
|
---|
[108] | 760 | print "OK\n";
|
---|
[29] | 761 | } else {
|
---|
[106] | 762 | printf "child ($cmd) exited with value %d\n", $? >> 8;
|
---|
| 763 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
[29] | 764 | }
|
---|
[30] | 765 | }
|
---|
[74] | 766 |
|
---|
[106] | 767 | sub pb_display_file {
|
---|
| 768 |
|
---|
| 769 | my $file=shift;
|
---|
| 770 |
|
---|
[117] | 771 | return if (not -f $file);
|
---|
| 772 | open(FILE,"$file");
|
---|
[106] | 773 | while (<FILE>) {
|
---|
[108] | 774 | print $_;
|
---|
[106] | 775 | }
|
---|
| 776 | close(FILE);
|
---|
| 777 | }
|
---|
| 778 |
|
---|
[242] | 779 | # Function which returns a pointer on a table
|
---|
| 780 | # corresponding to a set of values queried in the conf file
|
---|
[88] | 781 | # and test the returned vaue as they need to exist in that case
|
---|
| 782 | sub pb_conf_get {
|
---|
| 783 |
|
---|
| 784 | my @param = @_;
|
---|
[313] | 785 | my @return = pb_conf_get_if(@param);
|
---|
[88] | 786 |
|
---|
[313] | 787 | die "No params found for $ENV{'PBPROJ'}" if (not defined @return);
|
---|
| 788 |
|
---|
| 789 | foreach my $i (0..$#param) {
|
---|
| 790 | die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $return[$i]);
|
---|
| 791 | }
|
---|
| 792 | return(@return);
|
---|
| 793 | }
|
---|
| 794 |
|
---|
| 795 | # Function which returns a pointer on a table
|
---|
| 796 | # corresponding to a set of values queried in the conf file
|
---|
| 797 | # Those value may be undef if they do not exist
|
---|
| 798 | sub pb_conf_get_if {
|
---|
| 799 |
|
---|
| 800 | my @param = @_;
|
---|
| 801 |
|
---|
[242] | 802 | # Everything is returned via ptr1
|
---|
[313] | 803 | my @ptr1 = pb_conf_read_if("$ENV{'PBETC'}", @param);
|
---|
[314] | 804 | my @ptr2 = pb_conf_read_if("$ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb", @param);
|
---|
[89] | 805 |
|
---|
[242] | 806 | my $p1;
|
---|
| 807 | my $p2;
|
---|
| 808 |
|
---|
[262] | 809 | #print "DEBUG: param1: ".Dumper(@ptr1)."\n"; # if ($debug >= 1);
|
---|
| 810 | #print "DEBUG: param2: ".Dumper(@ptr2)."\n"; # if ($debug >= 1);
|
---|
| 811 |
|
---|
[88] | 812 | foreach my $i (0..$#param) {
|
---|
[262] | 813 | $p1 = $ptr1[$i];
|
---|
| 814 | $p2 = $ptr2[$i];
|
---|
[242] | 815 | # Always try to take the param from the home dir conf file in priority
|
---|
| 816 | # in order to mask what could be defined under the CMS to allow for overloading
|
---|
| 817 | if (not defined $p2) {
|
---|
| 818 | # No ref in CMS project conf file so use the home dir one.
|
---|
| 819 | $p1->{$ENV{'PBPROJ'}} = $p1->{'default'} if (not defined $p1->{$ENV{'PBPROJ'}});
|
---|
| 820 | } else {
|
---|
| 821 | # Ref found in CMS project conf file
|
---|
| 822 | if (not defined $p1) {
|
---|
| 823 | # No ref in home dir project conf file so use the CMS one.
|
---|
| 824 | $p2->{$ENV{'PBPROJ'}} = $p2->{'default'} if (not defined $p2->{$ENV{'PBPROJ'}});
|
---|
| 825 | $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
|
---|
| 826 | } else {
|
---|
| 827 | # Both are defined - handling the overloading
|
---|
| 828 | if (not defined $p1->{'default'}) {
|
---|
| 829 | if (defined $p2->{'default'}) {
|
---|
| 830 | $p1->{'default'} = $p2->{'default'};
|
---|
| 831 | }
|
---|
| 832 | }
|
---|
| 833 |
|
---|
| 834 | if (not defined $p1->{$ENV{'PBPROJ'}}) {
|
---|
| 835 | if (defined $p2->{$ENV{'PBPROJ'}}) {
|
---|
| 836 | $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
|
---|
| 837 | } else {
|
---|
| 838 | $p1->{$ENV{'PBPROJ'}} = $p1->{'default'};
|
---|
| 839 | }
|
---|
| 840 | }
|
---|
| 841 | }
|
---|
| 842 | }
|
---|
[262] | 843 | $ptr1[$i] = $p1;
|
---|
| 844 | #print "DEBUG: param ptr1: ".Dumper(@ptr1)."\n"; # if ($debug >= 1);
|
---|
[88] | 845 | }
|
---|
[242] | 846 | return(@ptr1);
|
---|
[88] | 847 | }
|
---|
| 848 |
|
---|
| 849 | # Function which returns a pointer on a hash
|
---|
[74] | 850 | # corresponding to a declaration (arg2) in a conf file (arg1)
|
---|
[313] | 851 | # if that conf file doesn't exist returns undef
|
---|
| 852 | sub pb_conf_read_if {
|
---|
| 853 |
|
---|
| 854 | my $conffile = shift;
|
---|
| 855 | my @param = @_;
|
---|
| 856 |
|
---|
| 857 | open(CONF,$conffile) || return((undef));
|
---|
| 858 | close(CONF);
|
---|
| 859 | return(pb_conf_read($conffile,@param));
|
---|
| 860 | }
|
---|
| 861 |
|
---|
| 862 | # Function which returns a pointer on a hash
|
---|
| 863 | # corresponding to a declaration (arg2) in a conf file (arg1)
|
---|
[74] | 864 | sub pb_conf_read {
|
---|
| 865 |
|
---|
| 866 | my $conffile = shift;
|
---|
| 867 | my @param = @_;
|
---|
| 868 | my $trace;
|
---|
| 869 | my @ptr;
|
---|
[291] | 870 | my %h;
|
---|
[74] | 871 |
|
---|
[108] | 872 | my $debug = 0;
|
---|
| 873 |
|
---|
[291] | 874 | open(CONF,$conffile) || die "Unable to open $conffile";
|
---|
| 875 | while(<CONF>) {
|
---|
| 876 | if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
|
---|
| 877 | print "DEBUG: 1:$1 2:$2 3:$3\n" if ($debug >= 1);
|
---|
| 878 | $h{$1}{$2}=$3;
|
---|
| 879 | }
|
---|
[74] | 880 | }
|
---|
[291] | 881 | close(CONF);
|
---|
[74] | 882 |
|
---|
| 883 | for my $param (@param) {
|
---|
[291] | 884 | push @ptr,$h{$param};
|
---|
[74] | 885 | }
|
---|
[291] | 886 | print "DEBUG: h:".Dumper(%h)." param:".Dumper(@param)." ptr:".Dumper(@ptr)."\n" if ($debug >= 1);
|
---|
[89] | 887 | return(@ptr);
|
---|
[74] | 888 | }
|
---|
| 889 |
|
---|
[313] | 890 | # Analyze a url passed and return protocol, account, password, server, port, path
|
---|
[314] | 891 | sub pb_get_uri {
|
---|
[313] | 892 |
|
---|
[314] | 893 | my $uri = shift || undef;
|
---|
[313] | 894 |
|
---|
[314] | 895 | # A URL has the format protocol://[ac@]host[:port][path[?query][#fragment]].
|
---|
| 896 | # Cf man URI
|
---|
| 897 | my ($scheme, $authority, $path, $query, $fragment) =
|
---|
| 898 | $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
|
---|
| 899 | my ($account,$host,$port) = $authority =~ m|(?:([^\@]+)\@)?([^:]+)(:(?:[0-9]+))?|;
|
---|
| 900 | print "DEBUG: scheme:$scheme ac:$account host:$host port:$port path:$path\n" if ($debug >= 1);
|
---|
| 901 | return($scheme, $account, $host, $port, $path);
|
---|
[313] | 902 | }
|
---|
| 903 |
|
---|
| 904 |
|
---|
| 905 | # Setup environment for CMS system for URL passed
|
---|
[74] | 906 | sub pb_cms_init {
|
---|
| 907 |
|
---|
| 908 | my $proj = shift || undef;
|
---|
| 909 | my $ret;
|
---|
| 910 |
|
---|
[89] | 911 | my ($cms) = pb_conf_get("cms");
|
---|
[74] | 912 |
|
---|
[88] | 913 | if ($cms->{$proj} eq "svn") {
|
---|
[74] | 914 | $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; svnversion .)`;
|
---|
| 915 | chomp($ENV{'PBREVISION'});
|
---|
| 916 | $ENV{'PBCMSLOGFILE'}="svn.log";
|
---|
[226] | 917 | } elsif ($cms->{$proj} eq "flat") {
|
---|
| 918 | $ENV{'PBREVISION'}="flat";
|
---|
[227] | 919 | $ENV{'PBCMSLOGFILE'}="flat.log";
|
---|
[88] | 920 | } elsif ($cms->{$proj} eq "cvs") {
|
---|
[106] | 921 | # Way too slow
|
---|
| 922 | #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
|
---|
| 923 | #chomp($ENV{'PBREVISION'});
|
---|
| 924 | $ENV{'PBREVISION'}="CVS";
|
---|
[74] | 925 | $ENV{'PBCMSLOGFILE'}="cvs.log";
|
---|
[87] | 926 | #
|
---|
| 927 | # Export content if needed
|
---|
| 928 | #
|
---|
[313] | 929 | my ($cvsrsh) = pb_conf_get_if("cvsrsh");
|
---|
[299] | 930 | $ENV{'CVS_RSH'} = $cvsrsh->{$proj} if (defined $cvsrsh->{$proj});
|
---|
[74] | 931 | } else {
|
---|
[88] | 932 | die "cms $cms->{$proj} unknown";
|
---|
[74] | 933 | }
|
---|
[106] | 934 | return($cms);
|
---|
[74] | 935 | }
|
---|
| 936 |
|
---|
[106] | 937 | sub pb_cms_export {
|
---|
| 938 | my $cms = shift;
|
---|
| 939 | my $pbdate = shift || undef;
|
---|
[108] | 940 | my $source = shift;
|
---|
[106] | 941 | my $destdir = shift;
|
---|
[108] | 942 | my $tmp;
|
---|
[115] | 943 | my $tmp1;
|
---|
[106] | 944 |
|
---|
| 945 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
[108] | 946 | if (-d $source) {
|
---|
| 947 | $tmp = $destdir;
|
---|
| 948 | } else {
|
---|
| 949 | $tmp = $destdir."/".basename($source);
|
---|
| 950 | }
|
---|
[116] | 951 | pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp");
|
---|
[226] | 952 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
| 953 | if (-d $source) {
|
---|
| 954 | $tmp = $destdir;
|
---|
| 955 | } else {
|
---|
| 956 | $tmp = $destdir."/".basename($source);
|
---|
| 957 | }
|
---|
| 958 | pb_system("cp -a $source $tmp","Exporting $source from DIR to $tmp");
|
---|
[106] | 959 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
| 960 | my $dir=dirname($destdir);
|
---|
| 961 | my $base=basename($destdir);
|
---|
[115] | 962 | if (-d $source) {
|
---|
| 963 | $tmp1 = $source;
|
---|
| 964 | $tmp1 =~ s|$ENV{'PBROOT'}/||;
|
---|
| 965 | } else {
|
---|
| 966 | $tmp1 = dirname($source);
|
---|
| 967 | $tmp1 =~ s|$ENV{'PBROOT'}/||;
|
---|
| 968 | $tmp1 = $tmp1."/".basename($source);
|
---|
| 969 | }
|
---|
[106] | 970 | # CVS needs a relative path !
|
---|
[310] | 971 | my ($cvsroot) = pb_conf_get("cvsroot");
|
---|
| 972 | pb_system("cd $dir ; cvs -d $cvsroot->{$ENV{'PBPROJ'}} export -D \"$pbdate\" -d $base $tmp1","Exporting $source from CVS to $destdir");
|
---|
[106] | 973 | } else {
|
---|
| 974 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
| 975 | }
|
---|
| 976 | }
|
---|
| 977 |
|
---|
[285] | 978 |
|
---|
| 979 | sub pb_create_authors {
|
---|
| 980 |
|
---|
| 981 | my $authors=shift;
|
---|
| 982 | my $dest=shift;
|
---|
| 983 | my $cms=shift;
|
---|
| 984 |
|
---|
[286] | 985 | return if ($authors eq "/dev/null");
|
---|
| 986 | open(SAUTH,$authors) || die "Unable to open $authors";
|
---|
[285] | 987 | open(DAUTH,"> $dest/AUTHORS") || die "Unable to create $dest/AUTHORS";
|
---|
| 988 | print DAUTH "Authors of the project are:\n";
|
---|
| 989 | print DAUTH "===========================\n";
|
---|
[286] | 990 | while (<SAUTH>) {
|
---|
[285] | 991 | my ($nick,$gcos) = split(/:/);
|
---|
[286] | 992 | chomp($gcos);
|
---|
[285] | 993 | print DAUTH "$gcos";
|
---|
[286] | 994 | if (defined $cms) {
|
---|
| 995 | print DAUTH " ($nick under $cms)\n";
|
---|
| 996 | } else {
|
---|
| 997 | print DAUTH "\n";
|
---|
| 998 | }
|
---|
[285] | 999 | }
|
---|
| 1000 | close(DAUTH);
|
---|
[286] | 1001 | close(SAUTH);
|
---|
[285] | 1002 | }
|
---|
| 1003 |
|
---|
[106] | 1004 | sub pb_cms_log {
|
---|
| 1005 | my $cms = shift;
|
---|
| 1006 | my $pkgdir = shift;
|
---|
[285] | 1007 | my $dest = shift;
|
---|
[286] | 1008 | my $chglog = shift;
|
---|
[285] | 1009 | my $authors = shift;
|
---|
[106] | 1010 |
|
---|
[285] | 1011 | pb_create_authors($authors,$dest,$cms->{$ENV{'PBPROJ'}});
|
---|
| 1012 |
|
---|
[106] | 1013 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
[286] | 1014 | if (! -f "$dest/ChangeLog") {
|
---|
| 1015 | if (-x "/usr/bin/svn2cl") {
|
---|
| 1016 | pb_system("/usr/bin/svn2cl --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN");
|
---|
| 1017 | } else {
|
---|
| 1018 | # To be written from pbcl
|
---|
| 1019 | pb_system("svn log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
|
---|
| 1020 | }
|
---|
[285] | 1021 | }
|
---|
[226] | 1022 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
[288] | 1023 | if (! -f "$dest/ChangeLog") {
|
---|
| 1024 | pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
|
---|
| 1025 | }
|
---|
[106] | 1026 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
| 1027 | my $tmp=basename($pkgdir);
|
---|
| 1028 | # CVS needs a relative path !
|
---|
[286] | 1029 | if (! -f "$dest/ChangeLog") {
|
---|
| 1030 | if (-x "/usr/bin/cvs2cl") {
|
---|
[288] | 1031 | pb_system("/usr/bin/cvs2cl --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from CVS");
|
---|
[286] | 1032 | } else {
|
---|
| 1033 | # To be written from pbcl
|
---|
| 1034 | pb_system("cvs log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
|
---|
| 1035 | }
|
---|
[285] | 1036 | }
|
---|
[106] | 1037 | } else {
|
---|
| 1038 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
| 1039 | }
|
---|
| 1040 | }
|
---|
| 1041 |
|
---|
[204] | 1042 | sub pb_cms_getinfo {
|
---|
| 1043 | my $cms = shift;
|
---|
[314] | 1044 | my $dir = shift;
|
---|
[204] | 1045 | my $url = "";
|
---|
| 1046 | my $void = "";
|
---|
[106] | 1047 |
|
---|
[314] | 1048 | if ($cms->{$ENV{'PBPROJ'}} =~ /^svn/) {
|
---|
| 1049 | open(PIPE,"LANGUAGE=C svn info $dir |") || return("");
|
---|
[204] | 1050 | while (<PIPE>) {
|
---|
[206] | 1051 | ($void,$url) = split(/^URL:/) if (/^URL:/);
|
---|
[204] | 1052 | }
|
---|
| 1053 | close(PIPE);
|
---|
[205] | 1054 | chomp($url);
|
---|
[226] | 1055 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
[204] | 1056 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
| 1057 | } else {
|
---|
| 1058 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
| 1059 | }
|
---|
| 1060 | return($url);
|
---|
| 1061 | }
|
---|
| 1062 |
|
---|
| 1063 | sub pb_cms_copy {
|
---|
| 1064 | my $cms = shift;
|
---|
| 1065 | my $oldurl = shift;
|
---|
| 1066 | my $newurl = shift;
|
---|
| 1067 |
|
---|
| 1068 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
[212] | 1069 | pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
|
---|
[226] | 1070 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
[204] | 1071 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
| 1072 | } else {
|
---|
| 1073 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
| 1074 | }
|
---|
| 1075 | }
|
---|
| 1076 |
|
---|
| 1077 | sub pb_cms_checkout {
|
---|
| 1078 | my $cms = shift;
|
---|
| 1079 | my $url = shift;
|
---|
| 1080 | my $destination = shift;
|
---|
| 1081 |
|
---|
| 1082 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
| 1083 | pb_system("svn co $url $destination","Checking $url to $destination ");
|
---|
[226] | 1084 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
[204] | 1085 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
| 1086 | } else {
|
---|
| 1087 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
| 1088 | }
|
---|
| 1089 | }
|
---|
| 1090 |
|
---|
[208] | 1091 | sub pb_cms_checkin {
|
---|
| 1092 | my $cms = shift;
|
---|
| 1093 | my $dir = shift;
|
---|
| 1094 |
|
---|
[212] | 1095 | my $ver = basename($dir);
|
---|
[208] | 1096 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
[212] | 1097 | pb_system("svn ci -m \"Updated to $ver\" $dir","Checking in $dir");
|
---|
[208] | 1098 | pb_system("svn up $dir","Updating $dir");
|
---|
[226] | 1099 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
[208] | 1100 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
| 1101 | } else {
|
---|
| 1102 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
| 1103 | }
|
---|
| 1104 | }
|
---|
| 1105 |
|
---|
[204] | 1106 | sub pb_cms_isdiff {
|
---|
| 1107 | my $cms = shift;
|
---|
| 1108 |
|
---|
| 1109 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
| 1110 | open(PIPE,"svn diff $ENV{'PBROOT'} |") || die "Unable to get svn diff from $ENV{'PBROOT'}";
|
---|
| 1111 | my $l = 0;
|
---|
| 1112 | while (<PIPE>) {
|
---|
| 1113 | $l++;
|
---|
| 1114 | }
|
---|
| 1115 | return($l);
|
---|
[226] | 1116 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
[204] | 1117 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
| 1118 | } else {
|
---|
| 1119 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
| 1120 | }
|
---|
| 1121 | }
|
---|
| 1122 |
|
---|
[77] | 1123 | # Get all filters to apply
|
---|
| 1124 | # They're cumulative from less specific to most specific
|
---|
| 1125 | # suffix is .pbf
|
---|
| 1126 |
|
---|
| 1127 | sub pb_get_filters {
|
---|
| 1128 |
|
---|
[108] | 1129 | # For the moment not dynamic
|
---|
| 1130 | my $debug = 0; # Debug level
|
---|
| 1131 | my $LOG = *STDOUT; # Where to log
|
---|
| 1132 |
|
---|
[77] | 1133 | my @ffiles;
|
---|
[235] | 1134 | my ($ffile00, $ffile0, $ffile1, $ffile2, $ffile3);
|
---|
| 1135 | my ($mfile00, $mfile0, $mfile1, $mfile2, $mfile3);
|
---|
[77] | 1136 | my $pbpkg = shift || die "No package specified";
|
---|
[236] | 1137 | my $dtype = shift || "";
|
---|
| 1138 | my $dfam = shift || "";
|
---|
| 1139 | my $ddir = shift || "";
|
---|
| 1140 | my $dver = shift || "";
|
---|
[77] | 1141 | my $ptr; # returned value pointer on the hash of filters
|
---|
[79] | 1142 | my %ptr;
|
---|
[291] | 1143 | my %h;
|
---|
[77] | 1144 |
|
---|
[169] | 1145 | # Global filter files first, then package specificities
|
---|
[314] | 1146 | if (-d "$ENV{'PBROOT'}/pbfilter") {
|
---|
| 1147 | $mfile00 = "$ENV{'PBROOT'}/pbfilter/all.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/all.pbf");
|
---|
| 1148 | $mfile0 = "$ENV{'PBROOT'}/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$dtype.pbf");
|
---|
| 1149 | $mfile1 = "$ENV{'PBROOT'}/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$dfam.pbf");
|
---|
| 1150 | $mfile2 = "$ENV{'PBROOT'}/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$ddir.pbf");
|
---|
| 1151 | $mfile3 = "$ENV{'PBROOT'}/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$ddir-$dver.pbf");
|
---|
[169] | 1152 |
|
---|
[231] | 1153 | push @ffiles,$mfile00 if (defined $mfile00);
|
---|
[169] | 1154 | push @ffiles,$mfile0 if (defined $mfile0);
|
---|
| 1155 | push @ffiles,$mfile1 if (defined $mfile1);
|
---|
| 1156 | push @ffiles,$mfile2 if (defined $mfile2);
|
---|
| 1157 | push @ffiles,$mfile3 if (defined $mfile3);
|
---|
| 1158 | }
|
---|
| 1159 |
|
---|
[314] | 1160 | if (-d "$ENV{'PBROOT'}/$pbpkg/pbfilter") {
|
---|
| 1161 | $ffile00 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/all.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/all.pbf");
|
---|
| 1162 | $ffile0 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dtype.pbf");
|
---|
| 1163 | $ffile1 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dfam.pbf");
|
---|
| 1164 | $ffile2 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir.pbf");
|
---|
| 1165 | $ffile3 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
|
---|
[77] | 1166 |
|
---|
[231] | 1167 | push @ffiles,$ffile00 if (defined $ffile00);
|
---|
[77] | 1168 | push @ffiles,$ffile0 if (defined $ffile0);
|
---|
| 1169 | push @ffiles,$ffile1 if (defined $ffile1);
|
---|
| 1170 | push @ffiles,$ffile2 if (defined $ffile2);
|
---|
| 1171 | push @ffiles,$ffile3 if (defined $ffile3);
|
---|
| 1172 | }
|
---|
| 1173 | if (@ffiles) {
|
---|
| 1174 | print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
|
---|
[79] | 1175 |
|
---|
[291] | 1176 | foreach my $f (@ffiles) {
|
---|
| 1177 | open(CONF,$f) || next;
|
---|
| 1178 | while(<CONF>) {
|
---|
| 1179 | if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
|
---|
| 1180 | $h{$1}{$2}=$3;
|
---|
| 1181 | }
|
---|
[79] | 1182 | }
|
---|
[291] | 1183 | close(CONF);
|
---|
[79] | 1184 |
|
---|
[291] | 1185 | $ptr = $h{"filter"};
|
---|
| 1186 | print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
|
---|
| 1187 | }
|
---|
[77] | 1188 | } else {
|
---|
| 1189 | $ptr = { };
|
---|
| 1190 | }
|
---|
[79] | 1191 | %ptr = %$ptr;
|
---|
| 1192 | return(\%ptr);
|
---|
[77] | 1193 | }
|
---|
| 1194 |
|
---|
[236] | 1195 | # Function which applies filter on pb build files
|
---|
[77] | 1196 | sub pb_filter_file_pb {
|
---|
| 1197 |
|
---|
| 1198 | my $f=shift;
|
---|
| 1199 | my $ptr=shift;
|
---|
| 1200 | my %filter=%$ptr;
|
---|
| 1201 | my $destfile=shift;
|
---|
| 1202 | my $dtype=shift;
|
---|
[99] | 1203 | my $pbsuf=shift;
|
---|
[297] | 1204 | my $pbproj=shift;
|
---|
[80] | 1205 | my $pbpkg=shift;
|
---|
| 1206 | my $pbver=shift;
|
---|
| 1207 | my $pbtag=shift;
|
---|
| 1208 | my $pbrev=shift;
|
---|
| 1209 | my $pbdate=shift;
|
---|
[108] | 1210 | my $defpkgdir = shift;
|
---|
| 1211 | my $extpkgdir = shift;
|
---|
[174] | 1212 | my $pbpackager = shift;
|
---|
[285] | 1213 | my $chglog = shift || undef;
|
---|
[77] | 1214 |
|
---|
[108] | 1215 | # For the moment not dynamic
|
---|
| 1216 | my $debug = 0; # Debug level
|
---|
| 1217 | my $LOG = *STDOUT; # Where to log
|
---|
| 1218 |
|
---|
[77] | 1219 | print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
|
---|
| 1220 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
| 1221 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
| 1222 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
| 1223 | while (<FILE>) {
|
---|
| 1224 | my $line = $_;
|
---|
| 1225 | foreach my $s (keys %filter) {
|
---|
| 1226 | # Process single variables
|
---|
[79] | 1227 | print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug >= 1);
|
---|
[77] | 1228 | my $tmp = $filter{$s};
|
---|
| 1229 | next if (not defined $tmp);
|
---|
| 1230 | # Expand variables if any single one found
|
---|
[79] | 1231 | print $LOG "DEBUG tmp: $tmp\n" if ($debug >= 1);
|
---|
[77] | 1232 | if ($tmp =~ /\$/) {
|
---|
| 1233 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
| 1234 | # special case for ChangeLog only for pb
|
---|
[259] | 1235 | } elsif (($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
|
---|
[108] | 1236 | my $p = $defpkgdir->{$pbpkg};
|
---|
| 1237 | $p = $extpkgdir->{$pbpkg} if (not defined $p);
|
---|
[285] | 1238 | pb_changelog($dtype, $pbpkg, $pbver, $pbtag, $pbsuf, $p, \*DEST, $tmp, $chglog);
|
---|
[254] | 1239 | $tmp = "";
|
---|
[77] | 1240 | }
|
---|
| 1241 | $line =~ s|$s|$tmp|;
|
---|
| 1242 | }
|
---|
| 1243 | print DEST $line;
|
---|
| 1244 | }
|
---|
| 1245 | close(FILE);
|
---|
| 1246 | close(DEST);
|
---|
| 1247 | }
|
---|
| 1248 |
|
---|
| 1249 | # Function which applies filter on files (external call)
|
---|
| 1250 | sub pb_filter_file {
|
---|
| 1251 |
|
---|
| 1252 | my $f=shift;
|
---|
| 1253 | my $ptr=shift;
|
---|
| 1254 | my %filter=%$ptr;
|
---|
| 1255 | my $destfile=shift;
|
---|
[298] | 1256 | my $pbproj=shift;
|
---|
[80] | 1257 | my $pbpkg=shift;
|
---|
| 1258 | my $pbver=shift;
|
---|
| 1259 | my $pbtag=shift;
|
---|
| 1260 | my $pbrev=shift;
|
---|
| 1261 | my $pbdate=shift;
|
---|
[174] | 1262 | my $pbpackager=shift;
|
---|
[77] | 1263 |
|
---|
[108] | 1264 | # For the moment not dynamic
|
---|
| 1265 | my $debug = 0; # Debug level
|
---|
| 1266 | my $LOG = *STDOUT; # Where to log
|
---|
| 1267 |
|
---|
[77] | 1268 | print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
|
---|
| 1269 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
| 1270 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
| 1271 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
| 1272 | while (<FILE>) {
|
---|
| 1273 | my $line = $_;
|
---|
| 1274 | foreach my $s (keys %filter) {
|
---|
| 1275 | # Process single variables
|
---|
| 1276 | print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
|
---|
| 1277 | my $tmp = $filter{$s};
|
---|
| 1278 | next if (not defined $tmp);
|
---|
| 1279 | # Expand variables if any single one found
|
---|
| 1280 | if ($tmp =~ /\$/) {
|
---|
| 1281 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
| 1282 | }
|
---|
| 1283 | $line =~ s|$s|$tmp|;
|
---|
| 1284 | }
|
---|
| 1285 | print DEST $line;
|
---|
| 1286 | }
|
---|
| 1287 | close(FILE);
|
---|
| 1288 | close(DEST);
|
---|
| 1289 | }
|
---|
| 1290 |
|
---|
| 1291 |
|
---|
[2] | 1292 | 1;
|
---|