| 1 | #!/usr/bin/perl -w
|
|---|
| 2 | #
|
|---|
| 3 | # Project Builder main application
|
|---|
| 4 | #
|
|---|
| 5 | # $Id$
|
|---|
| 6 | #
|
|---|
| 7 | # Copyright B. Cornec 2007
|
|---|
| 8 | # Provided under the GPL v2
|
|---|
| 9 |
|
|---|
| 10 | # Syntax: pb [-p project] <action> [<params>...]
|
|---|
| 11 |
|
|---|
| 12 | use strict;
|
|---|
| 13 | use Switch;
|
|---|
| 14 | use Getopt::Std;
|
|---|
| 15 | use Data::Dumper;
|
|---|
| 16 | use English;
|
|---|
| 17 | use Time::localtime qw(localtime);
|
|---|
| 18 | use POSIX qw(strftime);
|
|---|
| 19 |
|
|---|
| 20 | use lib qw (lib etc);
|
|---|
| 21 | use vars qw (%defpkgdir %extpkgdir %version);
|
|---|
| 22 | use common qw (env_init);
|
|---|
| 23 | use pb qw (defpkgdir extpkgdir version pb_init);
|
|---|
| 24 | use distro qw (distro_init);
|
|---|
| 25 | use cms;
|
|---|
| 26 |
|
|---|
| 27 | my %opts; # CLI Options
|
|---|
| 28 | my $action; # action to realize
|
|---|
| 29 | my $test = "FALSE";
|
|---|
| 30 | my $option = "";
|
|---|
| 31 | my @pkgs;
|
|---|
| 32 |
|
|---|
| 33 | getopts('p:t',\%opts);
|
|---|
| 34 |
|
|---|
| 35 | # Handles project name if any
|
|---|
| 36 | if (defined $opts{'p'}) {
|
|---|
| 37 | $ENV{'PBPROJ'} = env_init($opts{'p'});
|
|---|
| 38 | } else {
|
|---|
| 39 | $ENV{'PBPROJ'} = env_init();
|
|---|
| 40 | }
|
|---|
| 41 | # Handles test option
|
|---|
| 42 | if (defined $opts{'t'}) {
|
|---|
| 43 | $test = "TRUE";
|
|---|
| 44 | # Works only for SVN
|
|---|
| 45 | $option = "-r BASE";
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | # Get Action
|
|---|
| 49 | $action = shift @ARGV;
|
|---|
| 50 | die "Syntax: pb [-p project] <action> [<params>...]" if (not defined $action);
|
|---|
| 51 |
|
|---|
| 52 | print "Project $ENV{'PBPROJ'}\n";
|
|---|
| 53 | #print "Action: $action - ARGV:".Dumper(\@ARGV);
|
|---|
| 54 |
|
|---|
| 55 | # Act depending on action
|
|---|
| 56 | if ($action =~ /^cms2build$/) {
|
|---|
| 57 | print "Action: cms2build\n";
|
|---|
| 58 | # Get packages list
|
|---|
| 59 | if (not defined $ARGV[0]) {
|
|---|
| 60 | @pkgs = keys %defpkgdir;
|
|---|
| 61 | } elsif ($ARGV[0] =~ /^all$/) {
|
|---|
| 62 | @pkgs = keys %defpkgdir;
|
|---|
| 63 | push(@pkgs, keys %extpkgdir);
|
|---|
| 64 | } else {
|
|---|
| 65 | @pkgs = @ARGV;
|
|---|
| 66 | }
|
|---|
| 67 | print "Packages:\n";
|
|---|
| 68 | print Dumper(@pkgs);
|
|---|
| 69 | cms_init();
|
|---|
| 70 |
|
|---|
| 71 | foreach my $p (@pkgs) {
|
|---|
| 72 |
|
|---|
| 73 | my $v;
|
|---|
| 74 |
|
|---|
| 75 | if (-f "$ENV{'PBROOT'}/$p/VERSION") {
|
|---|
| 76 | open(V,"$ENV{'PBROOT'}/$p/VERSION") || die "Unable to open $ENV{'PBROOT'}/$p/VERSION";
|
|---|
| 77 | $v = <V>;
|
|---|
| 78 | chomp($v);
|
|---|
| 79 | close(V);
|
|---|
| 80 | } else {
|
|---|
| 81 | $v = $ENV{'PBVER'};
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | my $tag;
|
|---|
| 85 |
|
|---|
| 86 | if (-f "$ENV{'PBROOT'}/$p/TAG") {
|
|---|
| 87 | open(T,"$ENV{'PBROOT'}/$p/TAG") || die "Unable to open $ENV{'PBROOT'}/$p/TAG";
|
|---|
| 88 | $tag = <T>;
|
|---|
| 89 | chomp($tag);
|
|---|
| 90 | close(T);
|
|---|
| 91 | } else {
|
|---|
| 92 | $tag = $ENV{'PBTAG'};
|
|---|
| 93 | }
|
|---|
| 94 | print "Management of $p $v-$tag (rev $ENV{'PBREVISION'})\n";
|
|---|
| 95 | die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
|
|---|
| 96 | # Clean up dest if necessary
|
|---|
| 97 | my $dest = "$ENV{'PBDESTDIR'}/$p-$v";
|
|---|
| 98 | pbrm_rf($dest) if (-d $dest);
|
|---|
| 99 |
|
|---|
| 100 | # Export CMS tree for the concerned package to dest
|
|---|
| 101 | # And generate some additional files
|
|---|
| 102 | $OUTPUT_AUTOFLUSH=1;
|
|---|
| 103 | print "$ENV{'PBCMSEXP'} of $p...";
|
|---|
| 104 | # computes in which dir we have to work
|
|---|
| 105 | my $dir = $defpkgdir{$p};
|
|---|
| 106 | $dir = $extpkgdir{$p} if (not defined $dir);
|
|---|
| 107 | system("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null");
|
|---|
| 108 | if ($? == -1) {
|
|---|
| 109 | print "failed to execute: $!\n";
|
|---|
| 110 | } elsif ($? & 127) {
|
|---|
| 111 | printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
|
|---|
| 112 | } else {
|
|---|
| 113 | print " Done under $dest\n";
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | # Creates a REVISION file
|
|---|
| 117 | open(R,"> $dest/REVISION") || die "Unable to create $dest/REVISION";
|
|---|
| 118 | print R "$ENV{'PBREVISION'}\n";
|
|---|
| 119 | close(R);
|
|---|
| 120 |
|
|---|
| 121 | # Extract cms log history and store it
|
|---|
| 122 | system("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}");
|
|---|
| 123 | print "$ENV{'PBCMSLOG'} of $p...";
|
|---|
| 124 | if ($? == -1) {
|
|---|
| 125 | print "failed to execute: $!\n";
|
|---|
| 126 | } elsif ($? & 127) {
|
|---|
| 127 | printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
|
|---|
| 128 | } else {
|
|---|
| 129 | print " OK\n";
|
|---|
| 130 | }
|
|---|
| 131 | my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
|
|---|
| 132 | my $pbdate = strftime("%Y-%m-%d", @date);
|
|---|
| 133 |
|
|---|
| 134 | open(D,"$ENV{'PBCONF'}/DISTROS") || die "Unable to find $ENV{'PBCONF'}/DISTROS\n";
|
|---|
| 135 | while (<D>) {
|
|---|
| 136 | my $d = $_;
|
|---|
| 137 | my ($dir,$ver) = split(/_/,$d);
|
|---|
| 138 | chomp($ver);
|
|---|
| 139 | print "Generating build files for $dir ($ver)\n";
|
|---|
| 140 | my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init($dir,$ver);
|
|---|
| 141 | #print Dumper($ddir, $dver, $dfam, $dtype, $dsuf);
|
|---|
| 142 | #print "Filtering DDD => $pbdate, TTT => $tag, RRR => $tag$dsuf, VVV => $v\n";
|
|---|
| 143 |
|
|---|
| 144 | # Filter build files from the most precise up to the less
|
|---|
| 145 | # Filter all files found, keeping the name, and generating in dest
|
|---|
| 146 | my @bfiles;
|
|---|
| 147 | #print "dir: $ENV{'PBCONF'}/$p\n";
|
|---|
| 148 | if (-d "$ENV{'PBCONF'}/$p/$ddir-$dver") {
|
|---|
| 149 | opendir(BDIR,"$ENV{'PBCONF'}/$p/$ddir-$dver" || die "Unable to open dir $ENV{'PBCONF'}/$p/$ddir-$dver: $!");
|
|---|
| 150 | @bfiles = grep { ! /^\./ && -f "$ENV{'PBCONF'}/$p/$ddir-$dver/$_" } readdir(BDIR);
|
|---|
| 151 | closedir(BDIR);
|
|---|
| 152 | } elsif (-d "$ENV{'PBCONF'}/$p/$ddir") {
|
|---|
| 153 | opendir(BDIR,"$ENV{'PBCONF'}/$p/$ddir" || die "Unable to open dir $ENV{'PBCONF'}/$p/$ddir: $!");
|
|---|
| 154 | @bfiles = grep { ! /^\./ && -f "$ENV{'PBCONF'}/$p/$ddir/$_" } readdir(BDIR);
|
|---|
| 155 | closedir(BDIR);
|
|---|
| 156 | } elsif (-d "$ENV{'PBCONF'}/$p/$dfam") {
|
|---|
| 157 | opendir(BDIR,"$ENV{'PBCONF'}/$p/$dfam" || die "Unable to open dir $ENV{'PBCONF'}/$p/$dfam: $!");
|
|---|
| 158 | @bfiles = grep { ! /^\./ && -f "$ENV{'PBCONF'}/$p/$dfam/$_" } readdir(BDIR);
|
|---|
| 159 | closedir(BDIR);
|
|---|
| 160 | } elsif (-d "$ENV{'PBCONF'}/$p/$dtype") {
|
|---|
| 161 | opendir(BDIR,"$ENV{'PBCONF'}/$p/$dtype" || die "Unable to open dir $ENV{'PBCONF'}/$p/$dtype: $!");
|
|---|
| 162 | @bfiles = grep { ! /^\./ && -f "$ENV{'PBCONF'}/$p/$dtype/$_" } readdir(BDIR);
|
|---|
| 163 | closedir(BDIR);
|
|---|
| 164 | } else {
|
|---|
| 165 | print "No Build Files found for $ddir-$dver\n";
|
|---|
| 166 | next;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | }
|
|---|
| 170 | close(D);
|
|---|
| 171 |
|
|---|
| 172 | }
|
|---|
| 173 | } else {
|
|---|
| 174 | print "'$action' is not available\n";
|
|---|
| 175 | print "Available actions are:\n";
|
|---|
| 176 | print " cms2build\n";
|
|---|
| 177 | }
|
|---|