Changeset 74 in ProjectBuilder


Ignore:
Timestamp:
Sep 1, 2007, 1:56:48 AM (17 years ago)
Author:
Bruno Cornec
Message:

Big renaming to be more perlish
Single module Base contains all routines except when detaching makes sense

Location:
devel
Files:
2 deleted
3 edited
3 moved

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r73 r74  
    2121
    2222# Global variables
    23 use vars qw (%defpkgdir %extpkgdir %version %confparam %filteredfiles %pbrc $debug $LOG $projectbuilderver $projectbuilderrev);
     23use vars qw (%defpkgdir %extpkgdir %filteredfiles %pbrc $debug $LOG);
    2424
    2525$debug = 0;                 # Debug level
    2626$LOG = *STDOUT;             # Where to log
    2727use lib qw (lib);
    28 use ProjectBuilder::common qw (env_init);
    29 use ProjectBuilder::distro qw (distro_init);
    30 use ProjectBuilder::cms;
    31 use ProjectBuilder::changelog qw (changelog);
    32 use ProjectBuilder::Version qw (version_init);
    33 use ProjectBuilder::pb qw (pb_init);
     28use ProjectBuilder::Distribution qw (pb_distro_init);
     29use ProjectBuilder::Changelog qw (pb_changelog);
     30use ProjectBuilder::Version qw (pb_version_init);
     31use ProjectBuilder::Base qw (pb_conf_read pb_cms_init pb_mkdir_p pb_system pb_rm_rf);
    3432
    3533my %opts;                   # CLI Options
     
    4644getopts('hl:p:qr:tv',\%opts);
    4745
    48 version_init();
     46my ($projectbuilderver,$projectbuilderrev) = ("0.5","1"); #pb_version_init();
    4947if (defined $opts{'h'}) {
    50     syntax();
     48    pb_syntax();
    5149    exit(0);
    5250}
     
    7169# Get Action
    7270$action = shift @ARGV;
    73 die syntax() if (not defined $action);
     71die pb_syntax() if (not defined $action);
    7472
    7573# Handle root of the project if defined
     
    7977# Handles project name if any
    8078if (defined $opts{'p'}) {
    81     $ENV{'PBPROJ'} = env_init($opts{'p'});
     79    $ENV{'PBPROJ'} = pb_env_init($opts{'p'});
    8280} else {
    83     $ENV{'PBPROJ'} = env_init();
     81    $ENV{'PBPROJ'} = pb_env_init();
    8482}
    8583
     
    9189    my $ptr = get_pkg();
    9290    @pkgs = @$ptr;
    93     cms_init();
     91    pb_cms_init($ENV{'PBPROJ'});
    9492
    9593    foreach my $pbpkg (@pkgs) {
     
    117115        # Clean up dest if necessary. The export will recreate it
    118116        my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
    119         pbrm_rf($dest) if (-d $dest);
     117        pb_rm_rf($dest) if (-d $dest);
    120118
    121119        # Export CMS tree for the concerned package to dest
     
    126124        my $dir = $defpkgdir{$pbpkg};
    127125        $dir = $extpkgdir{$pbpkg} if (not defined $dir);
    128         pbsystem("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null", "Exporting $ENV{'PBROOT'}/$dir");
     126        pb_system("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null", "Exporting $ENV{'PBROOT'}/$dir");
    129127
    130128        # Creates a REVISION file
     
    134132
    135133        # Extract cms log history and store it
    136         pbsystem("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}", "Extracting log info");
     134        pb_system("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}", "Extracting log info");
    137135
    138136        my %build;
     
    142140            my ($ndir,$ver) = split(/_/,$d);
    143141            chomp($ver);
    144             my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init($ndir,$ver);
     142            my ($ddir, $dver, $dfam, $dtype, $dsuf) = pb_distro_init($ndir,$ver);
    145143            print $LOG "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $dsuf)."\n" if ($debug >= 1);
    146144            print $LOG "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1);
     
    251249        # Prepare the dest directory for archive
    252250        if (-x "$ENV{'PBCONF'}/$pbpkg/pbinit") {
    253             pbsystem("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit","Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit");
     251            pb_system("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit","Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit");
    254252        }
    255253
     
    257255        chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
    258256        # Possibility to look at PBSRC to guess more the filename
    259         pbsystem("tar cfpz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed");
     257        pb_system("tar cfpz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed");
    260258        print $LOG "Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n" if ($debug >= 0);
    261259        # Keep track of what is generated for default
     
    269267    if (not defined $vertag) {
    270268        if (-f $pbrc{$ENV{'PBPROJ'}}) {
    271             my $pbroot = pb_init($pbrc{$ENV{'PBPROJ'}},"pbroot");
     269            my $pbroot = pb_conf_read($pbrc{$ENV{'PBPROJ'}},"pbroot");
    272270            # There is only one line normaly
    273             $vertag = (keys %$pbroot)[0]
    274             $ENV{'PBROOT'} = (values %$pbroot)[0]
     271            $vertag = (keys %$pbroot)[0];
     272            $ENV{'PBROOT'} = (values %$pbroot)[0];
    275273        } else {
    276274            die "Unable to open $pbrc{$ENV{'PBPROJ'}}\nYou may want to precise as parameter version-tag";
     
    284282
    285283    # Get the running distro to build on
    286     my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init();
     284    my ($ddir, $dver, $dfam, $dtype, $dsuf) = pb_distro_init();
    287285    print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $dsuf))."\n" if ($debug >= 1);
    288286
     
    300298            foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
    301299                if (! -d "$ENV{'PBBUILDDIR'}/$d") {
    302                 pbmkdir_p("$ENV{'PBBUILDDIR'}/$d") || die "Please ensure that you can write into $ENV{'PBBUILDDIR'} to create $d\nSolution: setup _topdir in your ~/.rpmmacros or\nchown the $ENV{'PBBUILDDIR'} directory to your uid";
     300                pb_mkdir_p("$ENV{'PBBUILDDIR'}/$d") || die "Please ensure that you can write into $ENV{'PBBUILDDIR'} to create $d\nSolution: setup _topdir in your ~/.rpmmacros or\nchown the $ENV{'PBBUILDDIR'} directory to your uid";
    303301                }
    304302            }
     
    315313            foreach my $f (@specfile) {
    316314                if ($f =~ /\.spec$/) {
    317                     pbsystem("rpmbuild -ba $f","Building package with $f");
     315                    pb_system("rpmbuild -ba $f","Building package with $f");
    318316                    last;
    319317                }
    320318            }
    321319        } elsif ($dtype eq "tgz") {
    322             pbmkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install");
     320            pb_mkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install");
    323321        } elsif ($dtype eq "ebuild") {
    324             pbmkdir_p("$ENV{'PBBUILDDIR'}/portage") if (! -d "$ENV{'PBBUILDDIR'}/portage");
     322            pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage") if (! -d "$ENV{'PBBUILDDIR'}/portage");
    325323        } else {
    326324        }
     
    328326} else {
    329327    print $LOG "'$action' is not available\n";
    330     syntax();
     328    pb_syntax();
    331329}
    332330
     
    343341
    344342print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
    345 pbmkdir_p(dirname($destfile)) if (! -d dirname($destfile));
     343pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
    346344open(DEST,"> $destfile") || die "Unable to create $destfile";
    347345open(FILE,"$f") || die "Unable to open $f: $!";
     
    360358            my $p = $defpkgdir{$pbpkg};
    361359            $p = $extpkgdir{$pbpkg} if (not defined $p);
    362             changelog($dtype, $pbpkg, $pbtag, $dsuf, $p, \*DEST);
     360            pb_changelog($dtype, $pbpkg, $pbtag, $dsuf, $p, \*DEST);
    363361            $tmp = "";
    364362        }
     
    400398my @files;
    401399
    402 pbsystem("tar xfpz $src $dir >/dev/null","Extracting build files");
     400pb_system("tar xfpz $src $dir >/dev/null","Extracting build files");
    403401opendir(DIR,"$dir") || die "Unable to open directory $dir";
    404402foreach my $f (readdir(DIR)) {
     
    410408closedir(DIR);
    411409# Not enough but still a first cleanup
    412 pbrm_rf("$dir");
     410pb_rm_rf("$dir");
    413411return(@files);
    414412}
    415413
    416 sub syntax {
     414sub pb_syntax {
    417415
    418416    print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n";
  • devel/pb/lib/ProjectBuilder/Base.pm

    r73 r74  
    11#!/usr/bin/perl -w
    22#
    3 # Creates common environment
     3# Base subroutines for the Project-Builder project
    44#
    55# $Id$
     
    88use strict;
    99use lib qw (lib);
    10 use ProjectBuilder::pb qw (pb_init);
    1110use File::Basename;
    1211use File::Path;
    1312use File::Temp qw /tempdir/;
     13use AppConfig qw(ARGCOUNT_HASH);
    1414use Data::Dumper;
    15 use vars qw (%pbrc);
    1615
    1716$ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
    1817
    19 sub env_init {
     18sub pb_env_init {
    2019
    2120my $proj=shift;
     
    3837# and use its content
    3938#
    40 my $pbrc = pb_init("$ENV{'PBETC'}","pbrc");
     39my $pbrc = pb_conf_read("$ENV{'PBETC'}","pbrc");
     40print "DEBUG pbrc: ".Dumper($pbrc)."\n" if ($debug >= 1);
    4141
    4242%pbrc = %$pbrc;
     
    6060if (not defined $ENV{'PBROOT'}) {
    6161    if (-f $pbrc{$proj}) {
    62         my $pbroot = pb_init($pbrc{$proj},"pbroot");
     62        my $pbroot = pb_conf_read($pbrc{$proj},"pbroot");
    6363        my %pbroot = %$pbroot;
    6464        # There is normaly only one line in it
     
    7575die "Project $proj not Project-Builder compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
    7676
     77my %version = ();
     78my %confparam = ();
     79
    7780if (-f "$ENV{'PBCONF'}/$proj.pb") {
    78     pb_conf_init("$ENV{'PBCONF'}/$proj.pb");
     81    # main parameter confparam (mandatory)
     82    # List of pkg to build by default (mandatory)
     83    # List of additional pkg to build when all is called (optional)
     84    # Valid version names (optional)
     85    # List of files to filter (optional)
     86    my $ptr = pb_conf_read("$ENV{'PBCONF'}/$proj.pb","confparam","defpkgdir","extpkgdir","version","filteredfiles");
     87    my ($confparam, $defpkgdir, $extpkgdir, $version, $filteredfiles) = @$ptr;
     88    print "DEBUG: confparam: ".Dumper($confparam)."\n" if ($debug >= 1);
     89    print "DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n" if ($debug >= 1);
     90    print "DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n" if ($debug >= 1);
     91    print "DEBUG: version: ".Dumper($version)."\n" if ($debug >= 1);
     92    print "DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n" if ($debug >= 1);
     93    die "Unable to find confparam in $ENV{'PBCONF'}/$proj.pb" if (not defined $confparam);
     94    die "Unable to find defpkgdir in $ENV{'PBCONF'}/$proj.pb" if (not defined $defpkgdir);
     95    %confparam = %$confparam;
     96    # Global
     97    %defpkgdir = %$defpkgdir;
     98    # Global
     99    %extpkgdir = ();
     100    %extpkgdir = %$defpkgdir if (defined $defpkgdir);
     101    %version = ();
     102    %version = %$version if (defined $version);
     103    # Global
     104    %filteredfiles = ();
     105    %filteredfiles = %$filteredfiles if (defined $filteredfiles);
    79106} else {
    80107    die "Unable to open $ENV{'PBCONF'}/$proj.pb";
     
    82109
    83110#
    84 # Check content
     111# Export content if needed
    85112#
    86113if (defined $confparam{"cvsroot"}) {
    87114    $ENV{'CVSROOT'} = $confparam{"cvsroot"};
    88115}
    89 
    90 die "defpkgdir doesn't exist in $ENV{'PBETC'}/$proj.pb" if (not (defined %defpkgdir));
    91116
    92117#
     
    110135
    111136#
    112 #Get global TAG
     137# Get global TAG
    113138#
    114139open(TAG, "$ENV{'PBCONF'}/TAG") || die "Unable to open $ENV{'PBCONF'}/TAG: $?";
     
    129154        next if ($d =~ /^\./);
    130155        next if (-f "$ENV{'PBDESTDIR'}/$d");
    131         pbrm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
     156        pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
    132157    }
    133158    closedir(DIR);
    134159}
    135160if (! -d "$ENV{'PBDESTDIR'}") {
    136     pbmkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
     161    pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
    137162}
    138163
     
    141166#
    142167$ENV{'PBBUILDDIR'}=$topdir."/build";
    143 pbrm_rf($ENV{'PBBUILDDIR'}) if (-d "$ENV{'PBBUILDDIR'}");
    144 pbmkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
     168pb_rm_rf($ENV{'PBBUILDDIR'}) if (-d "$ENV{'PBBUILDDIR'}");
     169pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
    145170
    146171umask 0022;
     
    148173}
    149174
    150 sub pbmkdir_p {
     175# Internal mkdir -p function
     176sub pb_mkdir_p {
    151177my @dir = @_;
    152178my $ret = mkpath(@dir, 0, 0755);
     
    154180}
    155181
    156 sub pbrm_rf {
     182# Internal rm -rf function
     183sub pb_rm_rf {
    157184my @dir = @_;
    158185my $ret = rmtree(@dir, 0, 0);
     
    160187}
    161188
    162 sub pbsystem {
     189# Internal system function
     190sub pb_system {
    163191
    164192my $cmd=shift;
     
    175203}
    176204}
     205
     206# Function which returns a pointer on a hash
     207# corresponding to a declaration (arg2) in a conf file (arg1)
     208sub pb_conf_read {
     209
     210my $conffile = shift;
     211my @param = @_;
     212my $trace;
     213my @ptr;
     214
     215if ($debug > 0) {
     216    $trace = 1;
     217} else {
     218    $trace = 0;
     219}
     220
     221
     222my $config = AppConfig->new({
     223                            # Auto Create variables mentioned in Conf file
     224                            CREATE => 1,
     225                            DEBUG => $trace,
     226                            GLOBAL => {
     227                                # Each conf item is a hash
     228                                ARGCOUNT => ARGCOUNT_HASH,
     229                            },
     230                        });
     231$config->file($conffile);
     232for my $param (@param) {
     233    push @ptr,$config->get($param);
     234}
     235if ($#param == 0) {
     236    print "DEBUG: param: ".Dumper($ptr[0])."\n" if ($debug >= 1);
     237    return($ptr[0]);
     238} else {
     239    my $ptr = \@ptr;
     240    print "DEBUG: params: ".Dumper($ptr)."\n" if ($debug >= 1);
     241    return($ptr);
     242}
     243}
     244
     245sub pb_conf_init {
     246
     247my $conffile = shift;
     248my $ptr;
     249my $trace;
     250
     251if ($debug > 0) {
     252    $trace = 1;
     253} else {
     254    $trace = 0;
     255}
     256
     257my $config = AppConfig->new({
     258                            # Auto Create variables mentioned in Conf file
     259                            DEBUG => $trace,
     260                            CREATE => '1',
     261                            GLOBAL => {
     262                                # Each conf item is a hash
     263                                ARGCOUNT => ARGCOUNT_HASH,
     264                            },
     265                        });
     266$config->file($conffile);
     267
     268# Root of the project to build
     269# needs at least 2 levels of dir as in the upper
     270# other dirs will be created and used
     271
     272}
     273
     274# Setup environment for CMS system
     275sub pb_cms_init {
     276
     277my $proj = shift || undef;
     278my $ret;
     279
     280my $cms = pb_conf_read("$ENV{'PBETC'}","cms");
     281die "No CMS defined for $proj" if (not defined $cms);
     282my %cms = %$cms;
     283die "No CMS defined for $proj" if (not defined $cms{$proj});
     284
     285if ($cms{$proj} eq "svn") {
     286    $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; svnversion .)`;
     287    chomp($ENV{'PBREVISION'});
     288    $ENV{'PBCMSLOG'}="svn log";
     289    $ENV{'PBCMSLOGFILE'}="svn.log";
     290    $ENV{'PBCMSEXP'}="svn export";
     291} elsif ($cms{$proj} eq "cvs") {
     292    $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate  -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
     293    chomp($ENV{'PBREVISION'});
     294    $ENV{'PBCMSLOG'}="cvs log";
     295    $ENV{'PBCMSLOGFILE'}="cvs.log";
     296    $ENV{'PBCMSEXP'}="cvs export"
     297} else {
     298    die "CMS $cms{$proj} unknown";
     299}
     300}
     301
    1773021;
  • devel/pb/lib/ProjectBuilder/Changelog.pm

    r73 r74  
    1010use File::Basename;
    1111use English;
     12use ProjectBuilder::Base qw (pb_conf_read);
    1213
    13 sub changelog {
     14sub pb_changelog {
    1415
    1516my $dtype = shift;
     
    6566    my $n2date = &UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
    6667    #print "**$ndate**\n";
     68    my $confparam = pb_conf_read("$ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb", "confparam");
     69    my %confparam = %$confparam;
    6770    if (($dtype eq "rpm") || ($dtype eq "fc")) {
    6871        if ($ver !~ /-/) {
  • devel/pb/lib/ProjectBuilder/Distribution.pm

    r73 r74  
    88use strict;
    99
    10 sub distro_init {
     10sub pb_distro_init {
    1111
    1212my $ddir = shift || undef;
     
    1717
    1818# If we don't know which distribution we're on, then guess it
    19 ($ddir,$dver) = get_distro() if ((not defined $ddir) || (not defined $dver));
     19($ddir,$dver) = pb_get_distro() if ((not defined $ddir) || (not defined $dver));
    2020
    2121# There shold be unicity of names between ddir dfam and dtype
     
    8282}
    8383
    84 sub get_distro {
     84sub pb_get_distro {
    8585
    8686# Cf: http://linuxmafia.com/faq/Admin/release-files.html
     
    173173while (($d,$r) = each %single_rel_files) {
    174174    if (-f "$base/$r" && !-l "$base/$r") {
    175         my $tmp=get_content("$base/$r");
     175        my $tmp=pb_get_content("$base/$r");
    176176        # Found the only possibility.
    177177        # Try to get version and return
     
    191191        # Found one possibility.
    192192        # Get all distros concerned by that file
    193         my $tmp=get_content("$base/$r");
     193        my $tmp=pb_get_content("$base/$r");
    194194        my $found = 0;
    195195        my $ptr = $distro_similar{$d};
     
    221221}
    222222
    223 sub get_content {
     223# get content of a file in a variable
     224sub pb_get_content {
    224225
    225226my $file=shift;
  • devel/pb/lib/ProjectBuilder/Version.pm

    r53 r74  
    55# and have been isolated here to avoid unrelated effects
    66#
     7use strict;
    78
    8 sub version_init {
    9 $projectbuilderver = "PBVER";
    10 $projectbuilderrev = "PBREV";
    11 };
    12 1
     9sub pb_version_init {
     10
     11my $projectbuilderver = "PBVER";
     12my $projectbuilderrev = "PBREV";
     13
     14return($projectbuilderver,$projectbuilderrev);
     15}
     161;
  • devel/pbconf/project-builder/rpm/pb.spec

    r53 r74  
    1616BuildArch:  noarch
    1717Requires:   perl >= 5.8.4, PBDEP
    18 Provides:   perl(ProjectBuilder::changelog), perl(ProjectBuilder::cms), perl(ProjectBuilder::common), perl(ProjectBuilder::distro), perl(ProjectBuilder::pb), perl(ProjectBuilder::Version)
     18Provides:   perl(ProjectBuilder::Changelog), perl(ProjectBuilder::Base), perl(ProjectBuilder::Distribution), perl(ProjectBuilder::Version)
    1919
    2020%description
Note: See TracChangeset for help on using the changeset viewer.