Changeset 313 in ProjectBuilder for devel/pb/lib/ProjectBuilder/Base.pm


Ignore:
Timestamp:
Feb 9, 2008, 2:48:12 AM (16 years ago)
Author:
Bruno Cornec
Message:

WARNING: Modifications in progress. DOES NOT WORK
Addition of a different origin for pbconf WIP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/lib/ProjectBuilder/Base.pm

    r310 r313  
    4040
    4141#
    42 # We get the pbrc file for that project
     42# We get the pbconf file for that project
    4343# and use its content
    4444#
    45 my ($pbrc) = pb_conf_read("$ENV{'PBETC'}","pbrc");
    46 print "DEBUG pbrc: ".Dumper($pbrc)."\n" if ($debug >= 1);
    47 
    48 my %pbrc = %$pbrc;
     45my ($pbconf) = pb_conf_read("$ENV{'PBETC'}","pbconf");
     46print "DEBUG pbconf: ".Dumper($pbconf)."\n" if ($debug >= 1);
     47
     48my %pbconf = %$pbconf;
    4949if (not defined $proj) {
    5050    # Take the first as the default project
    51     $proj = (keys %pbrc)[0];
    52     print $LOG "Using $proj as default project as none has been specified\n" if (($debug >= 0) and (defined $proj));
    53 }
    54 die "No project defined - use env var PBPROJ or -p proj" if (not (defined $proj));
     51    $proj = (keys %pbconf)[0];
     52    if (($debug >= 0) and (defined $proj)) {
     53        print $LOG "WARNING: using $proj as default project as none has been specified\n"
     54        print $LOG "Please create a pbconf reference for project $proj in $ENV{'PBETC'}\nif you want to use another project\n";
     55    }
     56}
     57die "No project defined - use env var PBPROJ or -p proj or a pbconf entry in $ENV{'PBETC'}" if (not (defined $proj));
     58
     59# That's always the environment variable that will be used
     60$ENV{'PBPROJ'} = $proj;
     61
     62if (not defined ($pbconf{$ENV{'PBPROJ'}})) {
     63    die "Please create a pbconf reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n";
     64}
     65
     66#
     67# Detect the root dir for hosting all the content generated with pb
     68#
     69my ($pbroot) = pb_conf_get_if("pbroot");
     70my %pbroot = %$pbroot;
     71
     72if (not defined $ENV{'PBROOT'}) {
     73    if (not defined ($pbroot{$ENV{'PBPROJ'}})) {
     74        print $LOG "WARNING: no pbroot defined, using /var/cache\n";
     75        print $LOG "Please create a pbroot reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\nif you want to use another directory\n";
     76    }
     77    # That's always the environment variable that will be used
     78    $ENV{'PBROOT'} = $pbroot{$ENV{'PBPROJ'}};
     79}
     80# Expand potential env variable in it
     81eval { $ENV{'PBROOT'} =~ s/(\$ENV.+\})/$1/eeg };
    5582
    5683#
    5784# Set delivery directory
    5885#
    59 if (not defined ($pbrc{$proj})) {
    60     die "Please create a pbrc reference for project $proj in $ENV{'PBETC'}\n";
    61 }
    62 
    63 my $topdir=dirname($pbrc{$proj});
    64 # Expand potential env variable in it
    65 eval { $topdir =~ s/(\$ENV.+\})/$1/eeg };
    66 chdir $topdir || die "Unable to change directory to $topdir";
    67 $pbrc{$proj} = $topdir."/pbrc";
    68 $ENV{'PBDESTDIR'}=$topdir."/delivery";
    69 
    70 #
    71 # Use project configuration file if needed
    72 #
    73 if (not defined $ENV{'PBROOT'}) {
    74     if (-f $pbrc{$proj}) {
    75         my ($pbroot) = pb_conf_read($pbrc{$proj},"pbroot");
    76         my %pbroot = %$pbroot;
    77         # All lines should point to the same pbroot so take the first
    78         $ENV{'PBROOT'} = (values %$pbroot)[0] if (defined $pbroot);
    79         print $LOG "Using $ENV{'PBROOT'} as default pbroot from $pbrc{$proj}\n" if (($debug >= 0) and (defined $ENV{'PBROOT'}));
    80     }
    81     die "No pbroot defined - use env var PBROOT or -r pbroot " if (not defined $ENV{'PBROOT'});
    82 }
    83 
    84 #
    85 # Check pb conf compliance
    86 #
    87 $ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
     86$ENV{'PBDESTDIR'}="$ENV{'PBROOT'}/$ENV{'PBPROJ'}/delivery";
     87
     88#
     89# Removes all directory existing below the delivery dir
     90# as they are temp dir only
     91# Files stay and have to be cleaned up manually if needed
     92# those files serves as communication channels between pb phases
     93# Removing them prevents a following phase to detect what has been done before
     94#
     95if (-d $ENV{'PBDESTDIR'}) {
     96    opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
     97    foreach my $d (readdir(DIR)) {
     98        next if ($d =~ /^\./);
     99        next if (-f "$ENV{'PBDESTDIR'}/$d");
     100        pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
     101    }
     102    closedir(DIR);
     103}
     104if (! -d "$ENV{'PBDESTDIR'}") {
     105    pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
     106}
     107
     108#
     109# Set build directory
     110#
     111$ENV{'PBBUILDDIR'}="$ENV{'PBROOT'}/$ENV{'PBPROJ'}/build";
     112if (! -d "$ENV{'PBBUILDDIR'}") {
     113    pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
     114}
     115
     116#
     117# Set temp directory
     118#
     119if (not defined $ENV{'TMPDIR'}) {
     120    $ENV{'TMPDIR'}="/tmp";
     121}
     122$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
     123
     124# Not sure it'll still be needed
     125#$pbrc{$ENV{'PBPROJ'}} = $topdir."/pbrc";
     126
     127#
     128# Check pbconf compliance
     129#
     130$ENV{'PBCONF'} = "$ENV{'PBROOT'}/$ENV{'PBPROJ'}/pbconf";
     131if (not -d "$ENV{'PBCONF'}") {
     132    pb_mkdir_p("$ENV{'PBCONF'}");
     133    }
     134
     135
    88136if (defined $pbinit) {
    89137    print $LOG "Creating $ENV{'PBCONF'} directory\n";
    90138    pb_mkdir_p("$ENV{'PBCONF'}");
    91139    }
    92 die "Project $proj not Project-Builder compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
     140die "Project $ENV{'PBPROJ'} not Project-Builder compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
    93141
    94142my %version = ();
     
    98146my %supfiles = ();
    99147
    100 if ((-f "$ENV{'PBCONF'}/$proj.pb") and (not defined $pbinit)) {
     148if ((-f "$ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb") and (not defined $pbinit)) {
    101149    # List of pkg to build by default (mandatory)
     150    my ($defpkgdir) = pb_conf_get("defpkgdir");
    102151    # List of additional pkg to build when all is called (optional)
    103152    # Valid version names (optional)
    104153    # List of files to filter (optional)
    105     my ($defpkgdir, $extpkgdir, $version, $filteredfiles, $supfiles, $pkgv, $pkgt) = pb_conf_read("$ENV{'PBCONF'}/$proj.pb","defpkgdir","extpkgdir","version","filteredfiles","supfiles","projver","projtag");
     154    # Project version and tag (optional)
     155    my ($extpkgdir, $version, $filteredfiles, $supfiles, $pkgv, $pkgt) = pb_conf_get_if("extpkgdir","version","filteredfiles","supfiles","projver","projtag");
    106156    print "DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n" if ($debug >= 1);
    107157    print "DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n" if ($debug >= 1);
     
    109159    print "DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n" if ($debug >= 1);
    110160    print "DEBUG: supfiles: ".Dumper($supfiles)."\n" if ($debug >= 1);
    111     die "Unable to find defpkgdir in $ENV{'PBCONF'}/$proj.pb" if (not defined $defpkgdir);
     161    die "Unable to find defpkgdir in $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb" if (not defined $defpkgdir);
    112162    # Global
    113163    %defpkgdir = %$defpkgdir;
    114     # Global
    115164    %extpkgdir = %$extpkgdir if (defined $extpkgdir);
    116165    %version = %$version if (defined $version);
    117     # Global
    118166    %filteredfiles = %$filteredfiles if (defined $filteredfiles);
    119167    %supfiles = %$supfiles if (defined $supfiles);
     
    123171
    124172    if (not defined $ENV{'PBVER'}) {
    125         if ((defined $pkgv) && (defined $pkgv->{$proj})) {
    126             $ENV{'PBVER'}=$pkgv->{$proj};
     173        if ((defined $pkgv) && (defined $pkgv->{$ENV{'PBPROJ'}})) {
     174            $ENV{'PBVER'}=$pkgv->{$ENV{'PBPROJ'}};
    127175        } else {
    128             die "No projver found in $ENV{'PBCONF'}/$proj.pb";
     176            die "No projver found in $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb";
    129177        }
    130178    }
    131     die "Invalid version name $ENV{'PBVER'} in $ENV{'PBCONF'}/$proj.pb" if (($ENV{'PBVER'} !~ /[0-9.]+/) && (not defined $version) && ($ENV{'PBVER'} =~ /$version{$proj}/));
     179    die "Invalid version name $ENV{'PBVER'} in $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb" if (($ENV{'PBVER'} !~ /[0-9.]+/) && (not defined $version) && ($ENV{'PBVER'} =~ /$version{$ENV{'PBPROJ'}}/));
    132180   
    133181    if (not defined $ENV{'PBTAG'}) {
    134         if ((defined $pkgt) && (defined $pkgt->{$proj})) {
    135             $ENV{'PBTAG'}=$pkgt->{$proj};
     182        if ((defined $pkgt) && (defined $pkgt->{$ENV{'PBPROJ'}})) {
     183            $ENV{'PBTAG'}=$pkgt->{$ENV{'PBPROJ'}};
    136184        } else {
    137             die "No projtag found in $ENV{'PBCONF'}/$proj.pb";
     185            die "No projtag found in $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb";
    138186        }
    139187    }
    140     die "Invalid tag name $ENV{'PBTAG'} in $ENV{'PBCONF'}/$proj.pb" if ($ENV{'PBTAG'} !~ /[0-9.]+/);
     188    die "Invalid tag name $ENV{'PBTAG'} in $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb" if ($ENV{'PBTAG'} !~ /[0-9.]+/);
    141189} else {
    142190    if (defined $pbinit) {
    143         open(CONF,"> $ENV{'PBCONF'}/$proj.pb") || die "Unable to create $ENV{'PBCONF'}/$proj.pb";
     191        open(CONF,"> $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb") || die "Unable to create $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb";
    144192        print CONF << "EOF";
    145193#
    146194# Project Builder configuration file
    147 # For project $proj
     195# For project $ENV{'PBPROJ'}
    148196#
    149197# \$Id\$
     
    153201# Which CMS system is used (Subversion, CVS or tar file content extracted)
    154202#
    155 #cms $proj = svn
    156 #cms $proj = cvs
    157 #cms $proj = flat
     203#cms $ENV{'PBPROJ'} = svn
     204#cms $ENV{'PBPROJ'} = cvs
     205#cms $ENV{'PBPROJ'} = flat
    158206
    159207#
    160208# Packager label
    161209#
    162 #packager $proj = "William Porte <bill\@$proj.org>"
     210#packager $ENV{'PBPROJ'} = "William Porte <bill\@$ENV{'PBPROJ'}.org>"
    163211#
    164212
     
    166214# Needs hostname, account and directory
    167215#
    168 #sshhost $proj = www.$proj.org
    169 #sshlogin $proj = bill
    170 #sshdir $proj = /$proj/ftp
    171 #sshport $proj = 22
     216#sshhost $ENV{'PBPROJ'} = www.$ENV{'PBPROJ'}.org
     217#sshlogin $ENV{'PBPROJ'} = bill
     218#sshdir $ENV{'PBPROJ'} = /$ENV{'PBPROJ'}/ftp
     219#sshport $ENV{'PBPROJ'} = 22
    172220
    173221#
     
    178226# a QEMU rhel_3 here means that the VM will be named rhel_3.qemu
    179227#
    180 #vmlist $proj = 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
     228#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
    181229
    182230#
    183231# Valid values for vmtype are
    184232# qemu, (vmware, xen, ... TBD)
    185 #vmtype $proj = qemu
     233#vmtype $ENV{'PBPROJ'} = qemu
    186234
    187235# Hash for VM stuff on vmtype
     
    189237
    190238# We suppose we can commmunicate with the VM through SSH
    191 #vmhost $proj = localhost
    192 #vmlogin $proj = pb
    193 #vmport $proj = 2222
     239#vmhost $ENV{'PBPROJ'} = localhost
     240#vmlogin $ENV{'PBPROJ'} = pb
     241#vmport $ENV{'PBPROJ'} = 2222
    194242
    195243# Timeout to wait when VM is launched/stopped
     
    197245
    198246# per VMs needed paramaters
    199 #vmopt $proj = -m 384 -daemonize
    200 #vmpath $proj = /home/qemu
    201 #vmsize $proj = 5G
     247#vmopt $ENV{'PBPROJ'} = -m 384 -daemonize
     248#vmpath $ENV{'PBPROJ'} = /home/qemu
     249#vmsize $ENV{'PBPROJ'} = 5G
    202250
    203251#
    204252# Global version/tag for the project
    205253#
    206 #projver $proj = devel
    207 #projtag $proj = 1
     254#projver $ENV{'PBPROJ'} = devel
     255#projtag $ENV{'PBPROJ'} = 1
    208256
    209257# Adapt to your needs:
     
    241289#
    242290# PBSRC is replaced by the source package format
    243 #filter PBSRC = ftp://ftp.$proj.org/src/%{name}-%{version}.tar.gz
     291#filter PBSRC = ftp://ftp.$ENV{'PBPROJ'}.org/src/%{name}-%{version}.tar.gz
    244292
    245293# PBVER is replaced by the version (\$pbver in code)
     
    268316
    269317# PBURL contains the URL of the Web site of the project
    270 #filter PBURL = http://www.$proj.org
     318#filter PBURL = http://www.$ENV{'PBPROJ'}.org
    271319EOF
    272320        close(CONF);
     
    329377        open(CONF,"> $ENV{'PBCONF'}/pbfilter/md.pbf") || die "Unable to create $ENV{'PBCONF'}/pbfilter/md.pbf";
    330378        print CONF << "EOF";
    331 # Specific group for Mandriva for $proj
     379# Specific group for Mandriva for $ENV{'PBPROJ'}
    332380filter PBGRP = Archiving/Backup
    333381EOF
     
    335383        open(CONF,"> $ENV{'PBCONF'}/pbfilter/novell.pbf") || die "Unable to create $ENV{'PBCONF'}/pbfilter/novell.pbf";
    336384        print CONF << "EOF";
    337 # Specific group for SuSE for $proj
     385# Specific group for SuSE for $ENV{'PBPROJ'}
    338386filter PBGRP = Productivity/Archiving/Backup
    339387EOF
     
    369417
    370418The current upstream source was downloaded from
    371 ftp://ftp.$proj.org/src/.
     419ftp://ftp.$ENV{'PBPROJ'}.org/src/.
    372420
    373421Upstream Authors: Put their name here
     
    609657        print "After having renamed the pkg1 directory to your package's name      \n\n";
    610658    } else {
    611         die "Unable to open $ENV{'PBCONF'}/$proj.pb";
    612     }
    613 }
    614 
    615 #
    616 # Set temp directory
    617 #
    618 if (not defined $ENV{'TMPDIR'}) {
    619     $ENV{'TMPDIR'}="/tmp";
    620 }
    621 $ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
    622 
    623 #
    624 # Removes all directory existing below the delivery dir
    625 # as they are temp dir only
    626 # Files stay and have to be cleaned up manually
    627 #
    628 if (-d $ENV{'PBDESTDIR'}) {
    629     opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
    630     foreach my $d (readdir(DIR)) {
    631         next if ($d =~ /^\./);
    632         next if (-f "$ENV{'PBDESTDIR'}/$d");
    633         pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
    634     }
    635     closedir(DIR);
    636 }
    637 if (! -d "$ENV{'PBDESTDIR'}") {
    638     pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
    639 }
    640 
    641 #
    642 # Set build directory
    643 #
    644 $ENV{'PBBUILDDIR'}=$topdir."/build";
    645 if (! -d "$ENV{'PBBUILDDIR'}") {
    646     pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
    647 }
    648 
     659        die "Unable to open $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb";
     660    }
     661}
    649662umask 0022;
    650 return($proj,$debug,$LOG,\%pbrc, \%filteredfiles, \%supfiles, \%defpkgdir, \%extpkgdir);
     663return($debug,$LOG,\%pbconf, \%filteredfiles, \%supfiles, \%defpkgdir, \%extpkgdir);
    651664}
    652665
     
    706719
    707720my @param = @_;
     721my @return = pb_conf_get_if(@param);
     722
     723die "No params found for $ENV{'PBPROJ'}" if (not defined @return);
     724
     725foreach my $i (0..$#param) {
     726    die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $return[$i]);
     727}
     728return(@return);
     729}
     730
     731# Function which returns a pointer on a table
     732# corresponding to a set of values queried in the conf file
     733# Those value may be undef if they do not exist
     734sub pb_conf_get_if {
     735
     736my @param = @_;
    708737
    709738# Everything is returned via ptr1
    710 my @ptr1 = pb_conf_read("$ENV{'PBETC'}", @param);
    711 my @ptr2 = pb_conf_read("$ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb", @param);
     739my @ptr1 = pb_conf_read_if("$ENV{'PBETC'}", @param);
     740my @ptr2 = pb_conf_read_if("$ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb", @param);
    712741
    713742my $p1;
     
    720749    $p1 = $ptr1[$i];
    721750    $p2 = $ptr2[$i];
    722     die "No $param[$i] defined for $ENV{'PBPROJ'}" if ((not @ptr1) && (not @ptr2));
    723     die "No $param[$i] defined for $ENV{'PBPROJ'}" if ((not defined $p1) && (not defined $p2));
    724751    # Always try to take the param from the home dir conf file in priority
    725752    # in order to mask what could be defined under the CMS to allow for overloading
     
    750777        }
    751778    }
    752     die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $p1->{$ENV{'PBPROJ'}});
    753779    $ptr1[$i] = $p1;
    754780    #print "DEBUG: param ptr1: ".Dumper(@ptr1)."\n"; # if ($debug >= 1);
    755781}
    756782return(@ptr1);
     783}
     784
     785# Function which returns a pointer on a hash
     786# corresponding to a declaration (arg2) in a conf file (arg1)
     787# if that conf file doesn't exist returns undef
     788sub pb_conf_read_if {
     789
     790my $conffile = shift;
     791my @param = @_;
     792
     793open(CONF,$conffile) || return((undef));
     794close(CONF);
     795return(pb_conf_read($conffile,@param));
    757796}
    758797
     
    785824}
    786825
    787 # Setup environment for CMS system
     826# Analyze a url passed and return protocol, account, password, server, port, path
     827sub pb_get_url {
     828
     829my $url = shift || undef;
     830
     831# A URL has the format protocol://ac@host[:port][path[?query][#fragment]].
     832my $url_regex = "([a-z]+?)://([-\w]+.[-\w.]*)(\d+)?(/.*)?";
     833
     834my ($proto,$account,$passwd,$server,$port,$path) = ;
     835}
     836
     837
     838# Setup environment for CMS system for URL passed
    788839sub pb_cms_init {
    789840
     
    809860    # Export content if needed
    810861    #
    811     my ($cvsrsh) = pb_conf_get("cvsrsh");
     862    my ($cvsrsh) = pb_conf_get_if("cvsrsh");
    812863    $ENV{'CVS_RSH'} = $cvsrsh->{$proj} if (defined $cvsrsh->{$proj});
    813864} else {
Note: See TracChangeset for help on using the changeset viewer.