source: devel/pb/lib/ProjectBuilder/Base.pm @ 318

Last change on this file since 318 was 318, checked in by bruno, 12 years ago

First success with collectl

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