[5] | 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 |
|
---|
[9] | 10 | # Syntax: pb [-p project] <action> [<params>...]
|
---|
| 11 |
|
---|
[5] | 12 | use strict;
|
---|
| 13 | use Switch;
|
---|
| 14 | use Getopt::Std;
|
---|
[9] | 15 | use Data::Dumper;
|
---|
| 16 | use English;
|
---|
[5] | 17 |
|
---|
[6] | 18 | use lib qw (lib etc);
|
---|
[8] | 19 | use vars qw (%defpkgdir %extpkgdir %version);
|
---|
[9] | 20 | use common qw (env_init);
|
---|
[5] | 21 | use pb qw (defpkgdir extpkgdir version pb_init);
|
---|
| 22 | use cms;
|
---|
| 23 |
|
---|
| 24 | my %opts; # CLI Options
|
---|
[9] | 25 | my $action; # action to realize
|
---|
| 26 | my $test = "FALSE";
|
---|
| 27 | my $option = "";
|
---|
| 28 | my @pkgs;
|
---|
[5] | 29 |
|
---|
[9] | 30 | getopts('p:t',\%opts);
|
---|
[5] | 31 |
|
---|
| 32 | # Handles project name if any
|
---|
| 33 | if (defined $opts{'p'}) {
|
---|
[9] | 34 | $ENV{'PBPROJ'} = env_init($opts{'p'});
|
---|
[5] | 35 | } else {
|
---|
[9] | 36 | $ENV{'PBPROJ'} = env_init();
|
---|
[5] | 37 | }
|
---|
[9] | 38 | # Handles test option
|
---|
| 39 | if (defined $opts{'t'}) {
|
---|
| 40 | $test = "TRUE";
|
---|
| 41 | # Works only for SVN
|
---|
| 42 | $option = "-r BASE";
|
---|
| 43 | }
|
---|
[5] | 44 |
|
---|
[9] | 45 | # Get Action
|
---|
| 46 | $action = shift @ARGV;
|
---|
| 47 | die "Syntax: pb [-p project] <action> [<params>...]" if (not defined $action);
|
---|
[6] | 48 |
|
---|
[9] | 49 | print "Project $ENV{'PBPROJ'}\n";
|
---|
| 50 | #print "Action: $action - ARGV:".Dumper(\@ARGV);
|
---|
| 51 |
|
---|
| 52 | # Act depending on action
|
---|
| 53 | if ($action =~ /^cms2build$/) {
|
---|
| 54 | print "Action: cms2build\n";
|
---|
| 55 | # Get packages list
|
---|
| 56 | if (not defined $ARGV[0]) {
|
---|
| 57 | @pkgs = keys %defpkgdir;
|
---|
| 58 | } elsif ($ARGV[0] =~ /^all$/) {
|
---|
| 59 | @pkgs = keys %defpkgdir;
|
---|
| 60 | push(@pkgs, keys %extpkgdir);
|
---|
| 61 | } else {
|
---|
| 62 | @pkgs = @ARGV;
|
---|
| 63 | }
|
---|
| 64 | print "Packages:\n";
|
---|
| 65 | print Dumper(@pkgs);
|
---|
| 66 | cms_init();
|
---|
| 67 |
|
---|
| 68 | foreach my $p (@pkgs) {
|
---|
| 69 |
|
---|
| 70 | my $v;
|
---|
| 71 |
|
---|
| 72 | if (-f "$ENV{'PBROOT'}/$p/VERSION") {
|
---|
| 73 | open(V,"$ENV{'PBROOT'}/$p/VERSION") || die "Unable to open $ENV{'PBROOT'}/$p/VERSION";
|
---|
| 74 | $v = <V>;
|
---|
| 75 | chomp($v);
|
---|
| 76 | close(V);
|
---|
| 77 | } else {
|
---|
| 78 | $v = $ENV{'PBVER'};
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | my $tag;
|
---|
| 82 |
|
---|
| 83 | if (-f "$ENV{'PBROOT'}/$p/TAG") {
|
---|
| 84 | open(T,"$ENV{'PBROOT'}/$p/TAG") || die "Unable to open $ENV{'PBROOT'}/$p/TAG";
|
---|
| 85 | $tag = <T>;
|
---|
| 86 | chomp($tag);
|
---|
| 87 | close(T);
|
---|
| 88 | } else {
|
---|
| 89 | $tag = $ENV{'PBTAG'};
|
---|
| 90 | }
|
---|
| 91 | print "Management of $p $v-$tag (rev $ENV{'PBREVISION'})\n";
|
---|
| 92 | die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
|
---|
| 93 | # Clean up dest if necessary
|
---|
| 94 | my $dest = "$ENV{'PBDESTDIR'}/$p-$v";
|
---|
| 95 | pbrm_rf($dest) if (-d $dest);
|
---|
| 96 |
|
---|
| 97 | # Export CMS tree for the concerned package to dest
|
---|
| 98 | # And generate some additional files
|
---|
| 99 | $OUTPUT_AUTOFLUSH=1;
|
---|
| 100 | print "$ENV{'PBCMSEXP'} of $p...";
|
---|
| 101 | # computes in which dir we have to work
|
---|
| 102 | my $dir = $defpkgdir{$p};
|
---|
| 103 | $dir = $extpkgdir{$p} if (not defined $dir);
|
---|
| 104 | system("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null");
|
---|
| 105 | if ($? == -1) {
|
---|
| 106 | print "failed to execute: $!\n";
|
---|
| 107 | } elsif ($? & 127) {
|
---|
| 108 | printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
|
---|
| 109 | } else {
|
---|
| 110 | print " Done under $dest\n";
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | # Creates a REVISION file
|
---|
| 114 | open(R,"> $dest/REVISION") || die "Unable to create $dest/REVISION";
|
---|
| 115 | print R "$ENV{'PBREVISION'}\n";
|
---|
| 116 | close(R);
|
---|
| 117 |
|
---|
| 118 | # Extract cms log history and store it
|
---|
| 119 | system("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}");
|
---|
| 120 | print "$ENV{'PBCMSLOG'} of $p...";
|
---|
| 121 | if ($? == -1) {
|
---|
| 122 | print "failed to execute: $!\n";
|
---|
| 123 | } elsif ($? & 127) {
|
---|
| 124 | printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
|
---|
| 125 | } else {
|
---|
| 126 | print " OK\n";
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 | } else {
|
---|
| 130 | print "'$action' is not available\n";
|
---|
| 131 | print "Available actions are:\n";
|
---|
| 132 | print " cms2build\n";
|
---|
| 133 | }
|
---|