[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;
|
---|
[315] | 12 | use File::Copy;
|
---|
[2] | 13 | use File::Temp qw /tempdir/;
|
---|
[8] | 14 | use Data::Dumper;
|
---|
[315] | 15 | use POSIX qw(strftime);
|
---|
[2] | 16 |
|
---|
[199] | 17 | use ProjectBuilder::Changelog qw (pb_changelog);
|
---|
| 18 |
|
---|
[49] | 19 | $ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
|
---|
[5] | 20 |
|
---|
[315] | 21 | my $debug = 0;
|
---|
| 22 | my $LOG = \*STDOUT;
|
---|
| 23 |
|
---|
[74] | 24 | sub pb_env_init {
|
---|
[2] | 25 |
|
---|
[273] | 26 | my $proj=shift || undef;
|
---|
| 27 | my $pbinit=shift || undef;
|
---|
[5] | 28 | my $ver;
|
---|
| 29 | my $tag;
|
---|
[2] | 30 |
|
---|
[8] | 31 | #
|
---|
[5] | 32 | # Check project name
|
---|
[49] | 33 | # Could be with env var PBPROJ
|
---|
| 34 | # or option -p
|
---|
| 35 | # if not define take the first in conf file
|
---|
[8] | 36 | #
|
---|
[5] | 37 | if ((defined $ENV{'PBPROJ'}) &&
|
---|
| 38 | (not (defined $proj))) {
|
---|
| 39 | $proj = $ENV{'PBPROJ'};
|
---|
| 40 | }
|
---|
[69] | 41 |
|
---|
[49] | 42 | #
|
---|
[313] | 43 | # We get the pbconf file for that project
|
---|
[69] | 44 | # and use its content
|
---|
| 45 | #
|
---|
[313] | 46 | my ($pbconf) = pb_conf_read("$ENV{'PBETC'}","pbconf");
|
---|
[315] | 47 | pb_log(2,"DEBUG pbconf: ".Dumper($pbconf)."\n");
|
---|
[69] | 48 |
|
---|
[313] | 49 | my %pbconf = %$pbconf;
|
---|
[69] | 50 | if (not defined $proj) {
|
---|
| 51 | # Take the first as the default project
|
---|
[313] | 52 | $proj = (keys %pbconf)[0];
|
---|
[315] | 53 | if (defined $proj) {
|
---|
| 54 | pb_log(2,"WARNING: using $proj as default project as none has been specified\n");
|
---|
| 55 | pb_log(2,"Please create a pbconf reference for project $proj in $ENV{'PBETC'}\nif you want to use another project\n");
|
---|
[313] | 56 | }
|
---|
[69] | 57 | }
|
---|
[313] | 58 | die "No project defined - use env var PBPROJ or -p proj or a pbconf entry in $ENV{'PBETC'}" if (not (defined $proj));
|
---|
[69] | 59 |
|
---|
[313] | 60 | # That's always the environment variable that will be used
|
---|
| 61 | $ENV{'PBPROJ'} = $proj;
|
---|
| 62 |
|
---|
| 63 | if (not defined ($pbconf{$ENV{'PBPROJ'}})) {
|
---|
| 64 | die "Please create a pbconf reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n";
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[69] | 67 | #
|
---|
[313] | 68 | # Detect the root dir for hosting all the content generated with pb
|
---|
[69] | 69 | #
|
---|
[314] | 70 | # Tree will look like this:
|
---|
| 71 | #
|
---|
[315] | 72 | # maint pbdir PBDIR dev dir (optional) PBDEVDIR
|
---|
| 73 | # | |
|
---|
| 74 | # ------------------------ --------------------
|
---|
| 75 | # | | | |
|
---|
| 76 | # pbproj1 pbproj2 PBPROJ pbproj1 pbproj2 PBDEVPROJ
|
---|
| 77 | # | |
|
---|
| 78 | # --------------------------------------------- ----------
|
---|
| 79 | # * * | | | | * *
|
---|
| 80 | # 1.0 dev pbconf ... build delivery PBCONF 1.0 dev PBDEVROOT
|
---|
| 81 | # | | PBDESTDIR
|
---|
| 82 | # ------ pbrc PBBUILDDIR
|
---|
[314] | 83 | # | |
|
---|
[315] | 84 | # 1.0 dev PBROOT
|
---|
[314] | 85 | # |
|
---|
| 86 | # ----------------------------------
|
---|
| 87 | # | | | |
|
---|
| 88 | # pkg1 pbproj1.pb pbfilter pbcl
|
---|
| 89 | # |
|
---|
| 90 | # -----------------
|
---|
| 91 | # | | |
|
---|
| 92 | # rpm deb pbfilter
|
---|
| 93 | #
|
---|
| 94 | #
|
---|
| 95 | # (*) By default, if no relocation in .pbrc, dev dir is taken in the maint pbdir (when appropriate)
|
---|
| 96 | # Names under a pbproj and the corresponding pbconf should be similar
|
---|
| 97 | #
|
---|
[313] | 98 |
|
---|
[314] | 99 | my ($pbdir) = pb_conf_get_if("pbdir");
|
---|
| 100 | my %pbdir = %$pbdir;
|
---|
| 101 |
|
---|
| 102 | if (not defined $ENV{'PBDIR'}) {
|
---|
| 103 | if (not defined ($pbdir{$ENV{'PBPROJ'}})) {
|
---|
[315] | 104 | pb_log(2,"WARNING: no pbdir defined, using /var/cache\n");
|
---|
| 105 | pb_log(2,"Please create a pbdir reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\nif you want to use another directory\n");
|
---|
[313] | 106 | }
|
---|
| 107 | # That's always the environment variable that will be used
|
---|
[314] | 108 | $ENV{'PBDIR'} = $pbdir{$ENV{'PBPROJ'}};
|
---|
[273] | 109 | }
|
---|
[108] | 110 | # Expand potential env variable in it
|
---|
[314] | 111 | eval { $ENV{'PBDIR'} =~ s/(\$ENV.+\})/$1/eeg };
|
---|
[69] | 112 |
|
---|
| 113 | #
|
---|
[313] | 114 | # Set delivery directory
|
---|
[49] | 115 | #
|
---|
[314] | 116 | $ENV{'PBDESTDIR'}="$ENV{'PBDIR'}/$ENV{'PBPROJ'}/delivery";
|
---|
[313] | 117 |
|
---|
| 118 | #
|
---|
| 119 | # Removes all directory existing below the delivery dir
|
---|
| 120 | # as they are temp dir only
|
---|
| 121 | # Files stay and have to be cleaned up manually if needed
|
---|
| 122 | # those files serves as communication channels between pb phases
|
---|
| 123 | # Removing them prevents a following phase to detect what has been done before
|
---|
| 124 | #
|
---|
| 125 | if (-d $ENV{'PBDESTDIR'}) {
|
---|
| 126 | opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
|
---|
| 127 | foreach my $d (readdir(DIR)) {
|
---|
| 128 | next if ($d =~ /^\./);
|
---|
| 129 | next if (-f "$ENV{'PBDESTDIR'}/$d");
|
---|
| 130 | pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
|
---|
[67] | 131 | }
|
---|
[313] | 132 | closedir(DIR);
|
---|
[49] | 133 | }
|
---|
[313] | 134 | if (! -d "$ENV{'PBDESTDIR'}") {
|
---|
| 135 | pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
|
---|
| 136 | }
|
---|
[2] | 137 |
|
---|
[8] | 138 | #
|
---|
[313] | 139 | # Set build directory
|
---|
[8] | 140 | #
|
---|
[314] | 141 | $ENV{'PBBUILDDIR'}="$ENV{'PBDIR'}/$ENV{'PBPROJ'}/build";
|
---|
[313] | 142 | if (! -d "$ENV{'PBBUILDDIR'}") {
|
---|
| 143 | pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | #
|
---|
| 147 | # Set temp directory
|
---|
| 148 | #
|
---|
| 149 | if (not defined $ENV{'TMPDIR'}) {
|
---|
| 150 | $ENV{'TMPDIR'}="/tmp";
|
---|
| 151 | }
|
---|
| 152 | $ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
|
---|
| 153 |
|
---|
| 154 | #
|
---|
| 155 | # Check pbconf compliance
|
---|
| 156 | #
|
---|
[314] | 157 | $ENV{'PBCONF'} = "$ENV{'PBDIR'}/$ENV{'PBPROJ'}/pbconf";
|
---|
[313] | 158 |
|
---|
[314] | 159 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($pbconf{$ENV{'PBPROJ'}});
|
---|
[313] | 160 |
|
---|
[314] | 161 | if ((not -d "$ENV{'PBCONF'}") || (defined $pbinit)) {
|
---|
[315] | 162 | pb_cms_checkout($scheme,$pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONF'});
|
---|
[314] | 163 | } else {
|
---|
[315] | 164 | my $cmsurl = pb_cms_getinfo($scheme,$ENV{'PBCONF'},"URL:");
|
---|
[314] | 165 | if ($cmsurl !~ /^$scheme/) {
|
---|
| 166 | pb_rm_rf("$ENV{'PBCONF'}");
|
---|
[315] | 167 | pb_cms_checkout($scheme,$pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONF'});
|
---|
[314] | 168 | } elsif ($cmsurl ne $pbconf{$ENV{'PBPROJ'}}) {
|
---|
| 169 | # The local content doesn't correpond to the repository
|
---|
[315] | 170 | pb_log(2,"ERROR: Inconsistency detected:\n");
|
---|
| 171 | pb_log(2,"* $ENV{'PBCONF'} refers to $cmsurl but\n");
|
---|
| 172 | pb_log(2,"* $ENV{'PBETC'} refers to $pbconf{$ENV{'PBPROJ'}}\n");
|
---|
[314] | 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'}: $!";
|
---|
[315] | 183 | my $maxmtime = 0;
|
---|
[314] | 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);
|
---|
[315] | 196 | pb_log(2,"WARNING: no pbroot defined, using $ENV{'PBROOT'}\n");
|
---|
| 197 | pb_log(2,"Please -r release if you want to use another release\n");
|
---|
[314] | 198 | } else {
|
---|
| 199 | my ($pbroot) = pb_conf_read_if("$ENV{'PBDESTDIR'}/pbrc","pbroot");
|
---|
| 200 | # That's always the environment variable that will be used
|
---|
[315] | 201 | $ENV{'PBROOT'} = $pbroot->{$ENV{'PBPROJ'}};
|
---|
[314] | 202 | }
|
---|
| 203 | } else {
|
---|
| 204 | # transform in full path if relative
|
---|
[315] | 205 | $ENV{'PBROOT'} = "$ENV{'PBCONF'}/$ENV{'PBROOT'}" if ($ENV{'PBROOT'} !~ /\//);
|
---|
[314] | 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");
|
---|
[315] | 222 | pb_log(2,"DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n");
|
---|
| 223 | pb_log(2,"DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n");
|
---|
| 224 | pb_log(2,"DEBUG: version: ".Dumper($version)."\n");
|
---|
| 225 | pb_log(2,"DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n");
|
---|
| 226 | pb_log(2,"DEBUG: supfiles: ".Dumper($supfiles)."\n");
|
---|
[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 |
|
---|
[315] | 720 | pb_log(2,"\nDo not to forget to commit the pbconf directory in your CMS if needed\n");
|
---|
| 721 | pb_log(2,"After having renamed the pkg1 directory to your package's name \n\n");
|
---|
[273] | 722 | } else {
|
---|
[314] | 723 | die "Unable to open $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
|
---|
[273] | 724 | }
|
---|
[98] | 725 | }
|
---|
[8] | 726 | umask 0022;
|
---|
[315] | 727 | return(\%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 |
|
---|
[315] | 750 | pb_log(2,"$cmt... ");
|
---|
[117] | 751 | #system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
|
---|
[293] | 752 | system($cmd);
|
---|
[29] | 753 | if ($? == -1) {
|
---|
[315] | 754 | pb_log(2,"failed to execute ($cmd) : $!\n");
|
---|
[106] | 755 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
[29] | 756 | } elsif ($? & 127) {
|
---|
[315] | 757 | pb_log(2, "child ($cmd) died with signal ".($? & 127).", ".($? & 128) ? 'with' : 'without'." coredump\n");
|
---|
[106] | 758 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
| 759 | } elsif ($? == 0) {
|
---|
[315] | 760 | pb_log(2,"OK\n");
|
---|
[29] | 761 | } else {
|
---|
[315] | 762 | pb_log(2, "child ($cmd) exited with value ".($? >> 8)."\n");
|
---|
[106] | 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 |
|
---|
[315] | 787 | die "No params found for $ENV{'PBPROJ'}" if (not @return);
|
---|
[313] | 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 |
|
---|
[315] | 809 | pb_log(2,"DEBUG: param1: ".Dumper(@ptr1)."\n");
|
---|
| 810 | pb_log(2,"DEBUG: param2: ".Dumper(@ptr2)."\n");
|
---|
[262] | 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;
|
---|
[315] | 844 | pb_log(2,"DEBUG: param ptr1: ".Dumper(@ptr1)."\n");
|
---|
[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 |
|
---|
[291] | 872 | open(CONF,$conffile) || die "Unable to open $conffile";
|
---|
| 873 | while(<CONF>) {
|
---|
| 874 | if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
|
---|
[315] | 875 | pb_log(2,"DEBUG: 1:$1 2:$2 3:$3\n");
|
---|
[291] | 876 | $h{$1}{$2}=$3;
|
---|
| 877 | }
|
---|
[74] | 878 | }
|
---|
[291] | 879 | close(CONF);
|
---|
[74] | 880 |
|
---|
| 881 | for my $param (@param) {
|
---|
[291] | 882 | push @ptr,$h{$param};
|
---|
[74] | 883 | }
|
---|
[315] | 884 | pb_log(2,"DEBUG: h:".Dumper(%h)." param:".Dumper(@param)." ptr:".Dumper(@ptr)."\n");
|
---|
[89] | 885 | return(@ptr);
|
---|
[74] | 886 | }
|
---|
| 887 |
|
---|
[313] | 888 | # Analyze a url passed and return protocol, account, password, server, port, path
|
---|
[314] | 889 | sub pb_get_uri {
|
---|
[313] | 890 |
|
---|
[314] | 891 | my $uri = shift || undef;
|
---|
[313] | 892 |
|
---|
[314] | 893 | # A URL has the format protocol://[ac@]host[:port][path[?query][#fragment]].
|
---|
| 894 | # Cf man URI
|
---|
| 895 | my ($scheme, $authority, $path, $query, $fragment) =
|
---|
| 896 | $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
|
---|
| 897 | my ($account,$host,$port) = $authority =~ m|(?:([^\@]+)\@)?([^:]+)(:(?:[0-9]+))?|;
|
---|
[315] | 898 | pb_log(2,"DEBUG: scheme:$scheme ac:$account host:$host port:$port path:$path\n");
|
---|
[314] | 899 | return($scheme, $account, $host, $port, $path);
|
---|
[313] | 900 | }
|
---|
| 901 |
|
---|
| 902 |
|
---|
| 903 | # Setup environment for CMS system for URL passed
|
---|
[74] | 904 | sub pb_cms_init {
|
---|
| 905 |
|
---|
| 906 | my $proj = shift || undef;
|
---|
| 907 |
|
---|
[315] | 908 | # Use the project URI
|
---|
| 909 | my ($uri) = pb_conf_get("pburl");
|
---|
[74] | 910 |
|
---|
[315] | 911 | # Extract values from that URI
|
---|
| 912 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri->{$ENV{'PBPROJ'}});
|
---|
| 913 |
|
---|
| 914 | if ($scheme =~ /^svn/) {
|
---|
| 915 | $ENV{'PBREVISION'}= pb_cms_getinfo($scheme,$uri->{$ENV{'PBPROJ'}},"Revision:");
|
---|
| 916 | #$ENV{'PBREVISION'}=`(cd "$ENV{'PBDEVDIR'}" ; svnversion .)`;
|
---|
[74] | 917 | $ENV{'PBCMSLOGFILE'}="svn.log";
|
---|
[315] | 918 | } elsif (($scheme eq "file") || ($scheme eq "ftp") || ($scheme eq "http")) {
|
---|
[226] | 919 | $ENV{'PBREVISION'}="flat";
|
---|
[227] | 920 | $ENV{'PBCMSLOGFILE'}="flat.log";
|
---|
[315] | 921 | } elsif ($scheme eq "cvs") {
|
---|
[106] | 922 | # Way too slow
|
---|
| 923 | #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
|
---|
| 924 | #chomp($ENV{'PBREVISION'});
|
---|
| 925 | $ENV{'PBREVISION'}="CVS";
|
---|
[74] | 926 | $ENV{'PBCMSLOGFILE'}="cvs.log";
|
---|
[87] | 927 | #
|
---|
| 928 | # Export content if needed
|
---|
| 929 | #
|
---|
[313] | 930 | my ($cvsrsh) = pb_conf_get_if("cvsrsh");
|
---|
[299] | 931 | $ENV{'CVS_RSH'} = $cvsrsh->{$proj} if (defined $cvsrsh->{$proj});
|
---|
[74] | 932 | } else {
|
---|
[315] | 933 | die "cms $scheme unknown";
|
---|
[74] | 934 | }
|
---|
[315] | 935 |
|
---|
| 936 | #
|
---|
| 937 | #if (not defined $scheme) {
|
---|
| 938 | # We're an upstream guy
|
---|
| 939 | # Try to make it easy for us
|
---|
| 940 | #pb_log(2,"WARNING: Assuming a local project under $ENV{'PBDIR'}/$ENV{'PBPROJ'}:\n");
|
---|
| 941 | #pb_log(2,"If not, pleaase setup a pbproj entry in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb\n");
|
---|
| 942 | #return("");
|
---|
| 943 | #}
|
---|
| 944 |
|
---|
| 945 | return($scheme,$uri->{$ENV{'PBPROJ'}});
|
---|
[74] | 946 | }
|
---|
| 947 |
|
---|
[315] | 948 | sub pb_get_date {
|
---|
| 949 |
|
---|
| 950 | return(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
|
---|
| 951 | }
|
---|
| 952 |
|
---|
[106] | 953 | sub pb_cms_export {
|
---|
[315] | 954 |
|
---|
| 955 | my $scheme = shift;
|
---|
[108] | 956 | my $source = shift;
|
---|
[106] | 957 | my $destdir = shift;
|
---|
[108] | 958 | my $tmp;
|
---|
[115] | 959 | my $tmp1;
|
---|
[106] | 960 |
|
---|
[315] | 961 | my @date = pb_get_date();
|
---|
| 962 |
|
---|
| 963 | if ($scheme eq "svn") {
|
---|
[108] | 964 | if (-d $source) {
|
---|
| 965 | $tmp = $destdir;
|
---|
| 966 | } else {
|
---|
| 967 | $tmp = $destdir."/".basename($source);
|
---|
| 968 | }
|
---|
[116] | 969 | pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp");
|
---|
[315] | 970 | } elsif ($scheme eq "flat") {
|
---|
[226] | 971 | if (-d $source) {
|
---|
| 972 | $tmp = $destdir;
|
---|
| 973 | } else {
|
---|
| 974 | $tmp = $destdir."/".basename($source);
|
---|
| 975 | }
|
---|
| 976 | pb_system("cp -a $source $tmp","Exporting $source from DIR to $tmp");
|
---|
[315] | 977 | } elsif ($scheme eq "cvs") {
|
---|
[106] | 978 | my $dir=dirname($destdir);
|
---|
| 979 | my $base=basename($destdir);
|
---|
[115] | 980 | if (-d $source) {
|
---|
| 981 | $tmp1 = $source;
|
---|
| 982 | $tmp1 =~ s|$ENV{'PBROOT'}/||;
|
---|
| 983 | } else {
|
---|
| 984 | $tmp1 = dirname($source);
|
---|
| 985 | $tmp1 =~ s|$ENV{'PBROOT'}/||;
|
---|
| 986 | $tmp1 = $tmp1."/".basename($source);
|
---|
| 987 | }
|
---|
[106] | 988 | # CVS needs a relative path !
|
---|
[310] | 989 | my ($cvsroot) = pb_conf_get("cvsroot");
|
---|
[315] | 990 | my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
|
---|
[310] | 991 | pb_system("cd $dir ; cvs -d $cvsroot->{$ENV{'PBPROJ'}} export -D \"$pbdate\" -d $base $tmp1","Exporting $source from CVS to $destdir");
|
---|
[106] | 992 | } else {
|
---|
[315] | 993 | die "cms $scheme unknown";
|
---|
[106] | 994 | }
|
---|
| 995 | }
|
---|
| 996 |
|
---|
[285] | 997 |
|
---|
| 998 | sub pb_create_authors {
|
---|
| 999 |
|
---|
| 1000 | my $authors=shift;
|
---|
| 1001 | my $dest=shift;
|
---|
[315] | 1002 | my $scheme=shift;
|
---|
[285] | 1003 |
|
---|
[286] | 1004 | return if ($authors eq "/dev/null");
|
---|
| 1005 | open(SAUTH,$authors) || die "Unable to open $authors";
|
---|
[285] | 1006 | open(DAUTH,"> $dest/AUTHORS") || die "Unable to create $dest/AUTHORS";
|
---|
| 1007 | print DAUTH "Authors of the project are:\n";
|
---|
| 1008 | print DAUTH "===========================\n";
|
---|
[286] | 1009 | while (<SAUTH>) {
|
---|
[285] | 1010 | my ($nick,$gcos) = split(/:/);
|
---|
[286] | 1011 | chomp($gcos);
|
---|
[285] | 1012 | print DAUTH "$gcos";
|
---|
[315] | 1013 | if (defined $scheme) {
|
---|
| 1014 | print DAUTH " ($nick under $scheme)\n";
|
---|
[286] | 1015 | } else {
|
---|
| 1016 | print DAUTH "\n";
|
---|
| 1017 | }
|
---|
[285] | 1018 | }
|
---|
| 1019 | close(DAUTH);
|
---|
[286] | 1020 | close(SAUTH);
|
---|
[285] | 1021 | }
|
---|
| 1022 |
|
---|
[106] | 1023 | sub pb_cms_log {
|
---|
[315] | 1024 | my $scheme = shift;
|
---|
[106] | 1025 | my $pkgdir = shift;
|
---|
[285] | 1026 | my $dest = shift;
|
---|
[286] | 1027 | my $chglog = shift;
|
---|
[285] | 1028 | my $authors = shift;
|
---|
[106] | 1029 |
|
---|
[315] | 1030 | pb_create_authors($authors,$dest,$scheme);
|
---|
[285] | 1031 |
|
---|
[315] | 1032 | if ($scheme eq "svn") {
|
---|
[286] | 1033 | if (! -f "$dest/ChangeLog") {
|
---|
| 1034 | if (-x "/usr/bin/svn2cl") {
|
---|
[315] | 1035 | pb_system("/usr/bin/svn2cl --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN with svn2cl");
|
---|
[286] | 1036 | } else {
|
---|
| 1037 | # To be written from pbcl
|
---|
| 1038 | pb_system("svn log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
|
---|
| 1039 | }
|
---|
[285] | 1040 | }
|
---|
[315] | 1041 | } elsif ($scheme eq "flat") {
|
---|
[288] | 1042 | if (! -f "$dest/ChangeLog") {
|
---|
| 1043 | pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
|
---|
| 1044 | }
|
---|
[315] | 1045 | } elsif ($scheme eq "cvs") {
|
---|
[106] | 1046 | my $tmp=basename($pkgdir);
|
---|
| 1047 | # CVS needs a relative path !
|
---|
[286] | 1048 | if (! -f "$dest/ChangeLog") {
|
---|
| 1049 | if (-x "/usr/bin/cvs2cl") {
|
---|
[315] | 1050 | pb_system("/usr/bin/cvs2cl --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from CVS with cvs2cl");
|
---|
[286] | 1051 | } else {
|
---|
| 1052 | # To be written from pbcl
|
---|
| 1053 | pb_system("cvs log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
|
---|
| 1054 | }
|
---|
[285] | 1055 | }
|
---|
[106] | 1056 | } else {
|
---|
[315] | 1057 | die "cms $scheme unknown";
|
---|
[106] | 1058 | }
|
---|
| 1059 | }
|
---|
| 1060 |
|
---|
[204] | 1061 | sub pb_cms_getinfo {
|
---|
[315] | 1062 | my $scheme = shift;
|
---|
[314] | 1063 | my $dir = shift;
|
---|
[315] | 1064 | my $info = shift || "URL:";
|
---|
| 1065 |
|
---|
| 1066 | my $res = "";
|
---|
[204] | 1067 | my $void = "";
|
---|
[106] | 1068 |
|
---|
[315] | 1069 | if ($scheme =~ /^svn/) {
|
---|
[314] | 1070 | open(PIPE,"LANGUAGE=C svn info $dir |") || return("");
|
---|
[204] | 1071 | while (<PIPE>) {
|
---|
[315] | 1072 | ($void,$res) = split(/^$info/) if (/^$info/);
|
---|
[204] | 1073 | }
|
---|
| 1074 | close(PIPE);
|
---|
[315] | 1075 | chomp($res);
|
---|
| 1076 | } elsif ($scheme eq "flat") {
|
---|
| 1077 | } elsif ($scheme eq "cvs") {
|
---|
[204] | 1078 | } else {
|
---|
[315] | 1079 | die "cms $scheme unknown";
|
---|
[204] | 1080 | }
|
---|
[315] | 1081 | return($res);
|
---|
[204] | 1082 | }
|
---|
| 1083 |
|
---|
| 1084 | sub pb_cms_copy {
|
---|
[315] | 1085 | my $scheme = shift;
|
---|
[204] | 1086 | my $oldurl = shift;
|
---|
| 1087 | my $newurl = shift;
|
---|
| 1088 |
|
---|
[315] | 1089 | if ($scheme eq "svn") {
|
---|
[212] | 1090 | pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
|
---|
[315] | 1091 | } elsif ($scheme eq "flat") {
|
---|
| 1092 | } elsif ($scheme eq "cvs") {
|
---|
[204] | 1093 | } else {
|
---|
[315] | 1094 | die "cms $scheme unknown";
|
---|
[204] | 1095 | }
|
---|
| 1096 | }
|
---|
| 1097 |
|
---|
| 1098 | sub pb_cms_checkout {
|
---|
[315] | 1099 | my $scheme = shift;
|
---|
[204] | 1100 | my $url = shift;
|
---|
| 1101 | my $destination = shift;
|
---|
| 1102 |
|
---|
[315] | 1103 | if ($scheme =~ /^svn/) {
|
---|
[204] | 1104 | pb_system("svn co $url $destination","Checking $url to $destination ");
|
---|
[315] | 1105 | } elsif ($scheme eq "flat") {
|
---|
| 1106 | } elsif ($scheme eq "cvs") {
|
---|
[204] | 1107 | } else {
|
---|
[315] | 1108 | die "cms $scheme unknown";
|
---|
[204] | 1109 | }
|
---|
| 1110 | }
|
---|
| 1111 |
|
---|
[208] | 1112 | sub pb_cms_checkin {
|
---|
[315] | 1113 | my $scheme = shift;
|
---|
[208] | 1114 | my $dir = shift;
|
---|
| 1115 |
|
---|
[212] | 1116 | my $ver = basename($dir);
|
---|
[315] | 1117 | if ($scheme eq "svn") {
|
---|
[212] | 1118 | pb_system("svn ci -m \"Updated to $ver\" $dir","Checking in $dir");
|
---|
[208] | 1119 | pb_system("svn up $dir","Updating $dir");
|
---|
[315] | 1120 | } elsif ($scheme eq "flat") {
|
---|
| 1121 | } elsif ($scheme eq "cvs") {
|
---|
[208] | 1122 | } else {
|
---|
[315] | 1123 | die "cms $scheme unknown";
|
---|
[208] | 1124 | }
|
---|
| 1125 | }
|
---|
| 1126 |
|
---|
[204] | 1127 | sub pb_cms_isdiff {
|
---|
[315] | 1128 | my $scheme = shift;
|
---|
[204] | 1129 |
|
---|
[315] | 1130 | if ($scheme eq "svn") {
|
---|
[204] | 1131 | open(PIPE,"svn diff $ENV{'PBROOT'} |") || die "Unable to get svn diff from $ENV{'PBROOT'}";
|
---|
| 1132 | my $l = 0;
|
---|
| 1133 | while (<PIPE>) {
|
---|
| 1134 | $l++;
|
---|
| 1135 | }
|
---|
| 1136 | return($l);
|
---|
[315] | 1137 | } elsif ($scheme eq "flat") {
|
---|
| 1138 | } elsif ($scheme eq "cvs") {
|
---|
[204] | 1139 | } else {
|
---|
[315] | 1140 | die "cms $scheme unknown";
|
---|
[204] | 1141 | }
|
---|
| 1142 | }
|
---|
| 1143 |
|
---|
[77] | 1144 | # Get all filters to apply
|
---|
| 1145 | # They're cumulative from less specific to most specific
|
---|
| 1146 | # suffix is .pbf
|
---|
| 1147 |
|
---|
| 1148 | sub pb_get_filters {
|
---|
| 1149 |
|
---|
| 1150 | my @ffiles;
|
---|
[235] | 1151 | my ($ffile00, $ffile0, $ffile1, $ffile2, $ffile3);
|
---|
| 1152 | my ($mfile00, $mfile0, $mfile1, $mfile2, $mfile3);
|
---|
[77] | 1153 | my $pbpkg = shift || die "No package specified";
|
---|
[236] | 1154 | my $dtype = shift || "";
|
---|
| 1155 | my $dfam = shift || "";
|
---|
| 1156 | my $ddir = shift || "";
|
---|
| 1157 | my $dver = shift || "";
|
---|
[77] | 1158 | my $ptr; # returned value pointer on the hash of filters
|
---|
[79] | 1159 | my %ptr;
|
---|
[291] | 1160 | my %h;
|
---|
[77] | 1161 |
|
---|
[169] | 1162 | # Global filter files first, then package specificities
|
---|
[314] | 1163 | if (-d "$ENV{'PBROOT'}/pbfilter") {
|
---|
| 1164 | $mfile00 = "$ENV{'PBROOT'}/pbfilter/all.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/all.pbf");
|
---|
| 1165 | $mfile0 = "$ENV{'PBROOT'}/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$dtype.pbf");
|
---|
| 1166 | $mfile1 = "$ENV{'PBROOT'}/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$dfam.pbf");
|
---|
| 1167 | $mfile2 = "$ENV{'PBROOT'}/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$ddir.pbf");
|
---|
| 1168 | $mfile3 = "$ENV{'PBROOT'}/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$ddir-$dver.pbf");
|
---|
[169] | 1169 |
|
---|
[231] | 1170 | push @ffiles,$mfile00 if (defined $mfile00);
|
---|
[169] | 1171 | push @ffiles,$mfile0 if (defined $mfile0);
|
---|
| 1172 | push @ffiles,$mfile1 if (defined $mfile1);
|
---|
| 1173 | push @ffiles,$mfile2 if (defined $mfile2);
|
---|
| 1174 | push @ffiles,$mfile3 if (defined $mfile3);
|
---|
| 1175 | }
|
---|
| 1176 |
|
---|
[314] | 1177 | if (-d "$ENV{'PBROOT'}/$pbpkg/pbfilter") {
|
---|
| 1178 | $ffile00 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/all.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/all.pbf");
|
---|
| 1179 | $ffile0 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dtype.pbf");
|
---|
| 1180 | $ffile1 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dfam.pbf");
|
---|
| 1181 | $ffile2 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir.pbf");
|
---|
| 1182 | $ffile3 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
|
---|
[77] | 1183 |
|
---|
[231] | 1184 | push @ffiles,$ffile00 if (defined $ffile00);
|
---|
[77] | 1185 | push @ffiles,$ffile0 if (defined $ffile0);
|
---|
| 1186 | push @ffiles,$ffile1 if (defined $ffile1);
|
---|
| 1187 | push @ffiles,$ffile2 if (defined $ffile2);
|
---|
| 1188 | push @ffiles,$ffile3 if (defined $ffile3);
|
---|
| 1189 | }
|
---|
| 1190 | if (@ffiles) {
|
---|
[315] | 1191 | pb_log(2,"DEBUG ffiles: ".Dumper(\@ffiles)."\n");
|
---|
[79] | 1192 |
|
---|
[291] | 1193 | foreach my $f (@ffiles) {
|
---|
| 1194 | open(CONF,$f) || next;
|
---|
| 1195 | while(<CONF>) {
|
---|
| 1196 | if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
|
---|
| 1197 | $h{$1}{$2}=$3;
|
---|
| 1198 | }
|
---|
[79] | 1199 | }
|
---|
[291] | 1200 | close(CONF);
|
---|
[79] | 1201 |
|
---|
[291] | 1202 | $ptr = $h{"filter"};
|
---|
[315] | 1203 | pb_log(2,"DEBUG f:".Dumper($ptr)."\n");
|
---|
[291] | 1204 | }
|
---|
[77] | 1205 | } else {
|
---|
| 1206 | $ptr = { };
|
---|
| 1207 | }
|
---|
[79] | 1208 | %ptr = %$ptr;
|
---|
| 1209 | return(\%ptr);
|
---|
[77] | 1210 | }
|
---|
| 1211 |
|
---|
[236] | 1212 | # Function which applies filter on pb build files
|
---|
[77] | 1213 | sub pb_filter_file_pb {
|
---|
| 1214 |
|
---|
| 1215 | my $f=shift;
|
---|
| 1216 | my $ptr=shift;
|
---|
| 1217 | my %filter=%$ptr;
|
---|
| 1218 | my $destfile=shift;
|
---|
| 1219 | my $dtype=shift;
|
---|
[99] | 1220 | my $pbsuf=shift;
|
---|
[297] | 1221 | my $pbproj=shift;
|
---|
[80] | 1222 | my $pbpkg=shift;
|
---|
| 1223 | my $pbver=shift;
|
---|
| 1224 | my $pbtag=shift;
|
---|
| 1225 | my $pbrev=shift;
|
---|
| 1226 | my $pbdate=shift;
|
---|
[108] | 1227 | my $defpkgdir = shift;
|
---|
| 1228 | my $extpkgdir = shift;
|
---|
[174] | 1229 | my $pbpackager = shift;
|
---|
[285] | 1230 | my $chglog = shift || undef;
|
---|
[77] | 1231 |
|
---|
[315] | 1232 | pb_log(2,"DEBUG: From $f to $destfile\n");
|
---|
[77] | 1233 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
| 1234 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
| 1235 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
| 1236 | while (<FILE>) {
|
---|
| 1237 | my $line = $_;
|
---|
| 1238 | foreach my $s (keys %filter) {
|
---|
| 1239 | # Process single variables
|
---|
[315] | 1240 | pb_log(2,"DEBUG filter{$s}: $filter{$s}\n");
|
---|
[77] | 1241 | my $tmp = $filter{$s};
|
---|
| 1242 | next if (not defined $tmp);
|
---|
| 1243 | # Expand variables if any single one found
|
---|
[315] | 1244 | pb_log(2,"DEBUG tmp: $tmp\n");
|
---|
[77] | 1245 | if ($tmp =~ /\$/) {
|
---|
| 1246 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
| 1247 | # special case for ChangeLog only for pb
|
---|
[259] | 1248 | } elsif (($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
|
---|
[108] | 1249 | my $p = $defpkgdir->{$pbpkg};
|
---|
| 1250 | $p = $extpkgdir->{$pbpkg} if (not defined $p);
|
---|
[285] | 1251 | pb_changelog($dtype, $pbpkg, $pbver, $pbtag, $pbsuf, $p, \*DEST, $tmp, $chglog);
|
---|
[254] | 1252 | $tmp = "";
|
---|
[77] | 1253 | }
|
---|
| 1254 | $line =~ s|$s|$tmp|;
|
---|
| 1255 | }
|
---|
| 1256 | print DEST $line;
|
---|
| 1257 | }
|
---|
| 1258 | close(FILE);
|
---|
| 1259 | close(DEST);
|
---|
| 1260 | }
|
---|
| 1261 |
|
---|
| 1262 | # Function which applies filter on files (external call)
|
---|
[315] | 1263 | sub pb_filter_file_inplace {
|
---|
| 1264 |
|
---|
| 1265 | my $ptr=shift;
|
---|
| 1266 | my %filter=%$ptr;
|
---|
| 1267 | my $destfile=shift;
|
---|
| 1268 | my $pbproj=shift;
|
---|
| 1269 | my $pbpkg=shift;
|
---|
| 1270 | my $pbver=shift;
|
---|
| 1271 | my $pbtag=shift;
|
---|
| 1272 | my $pbrev=shift;
|
---|
| 1273 | my $pbdate=shift;
|
---|
| 1274 | my $pbpackager=shift;
|
---|
| 1275 |
|
---|
| 1276 | my $cp = "$ENV{'PBTMP'}/".basename($destfile);
|
---|
| 1277 | copy($destfile,$cp) || die "Unable to create $cp";
|
---|
| 1278 |
|
---|
| 1279 | pb_filter_file($cp,$ptr,$destfile,$pbproj,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
|
---|
| 1280 | unlink $cp;
|
---|
| 1281 | }
|
---|
| 1282 |
|
---|
| 1283 | # Function which applies filter on files (external call)
|
---|
[77] | 1284 | sub pb_filter_file {
|
---|
| 1285 |
|
---|
| 1286 | my $f=shift;
|
---|
| 1287 | my $ptr=shift;
|
---|
| 1288 | my %filter=%$ptr;
|
---|
| 1289 | my $destfile=shift;
|
---|
[298] | 1290 | my $pbproj=shift;
|
---|
[80] | 1291 | my $pbpkg=shift;
|
---|
| 1292 | my $pbver=shift;
|
---|
| 1293 | my $pbtag=shift;
|
---|
| 1294 | my $pbrev=shift;
|
---|
| 1295 | my $pbdate=shift;
|
---|
[174] | 1296 | my $pbpackager=shift;
|
---|
[77] | 1297 |
|
---|
[315] | 1298 | pb_log(2,"DEBUG: From $f to $destfile\n");
|
---|
[77] | 1299 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
| 1300 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
| 1301 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
| 1302 | while (<FILE>) {
|
---|
| 1303 | my $line = $_;
|
---|
| 1304 | foreach my $s (keys %filter) {
|
---|
| 1305 | # Process single variables
|
---|
[315] | 1306 | pb_log(2,"DEBUG filter{$s}: $filter{$s}\n");
|
---|
[77] | 1307 | my $tmp = $filter{$s};
|
---|
| 1308 | next if (not defined $tmp);
|
---|
| 1309 | # Expand variables if any single one found
|
---|
| 1310 | if ($tmp =~ /\$/) {
|
---|
| 1311 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
| 1312 | }
|
---|
| 1313 | $line =~ s|$s|$tmp|;
|
---|
| 1314 | }
|
---|
| 1315 | print DEST $line;
|
---|
| 1316 | }
|
---|
| 1317 | close(FILE);
|
---|
| 1318 | close(DEST);
|
---|
| 1319 | }
|
---|
| 1320 |
|
---|
[315] | 1321 | sub pb_log_init {
|
---|
[77] | 1322 |
|
---|
[315] | 1323 | $debug = shift || 0;
|
---|
| 1324 | $LOG = shift || \*STDOUT;
|
---|
| 1325 |
|
---|
| 1326 | }
|
---|
| 1327 |
|
---|
| 1328 | sub pb_log {
|
---|
| 1329 |
|
---|
| 1330 | my $dlevel = shift;
|
---|
| 1331 | my $msg = shift;
|
---|
| 1332 |
|
---|
| 1333 | print $LOG "$msg\n" if ($dlevel >= $debug);
|
---|
| 1334 | }
|
---|
| 1335 |
|
---|
[2] | 1336 | 1;
|
---|