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