source: ProjectBuilder/devel/pb/bin/pb.pl@ 9

Last change on this file since 9 was 9, checked in by Bruno Cornec, 17 years ago

cms2build begins to export

  • Property svn:executable set to *
File size: 3.2 KB
Line 
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
12use strict;
13use Switch;
14use Getopt::Std;
15use Data::Dumper;
16use English;
17
18use lib qw (lib etc);
19use vars qw (%defpkgdir %extpkgdir %version);
20use common qw (env_init);
21use pb qw (defpkgdir extpkgdir version pb_init);
22use cms;
23
24my %opts; # CLI Options
25my $action; # action to realize
26my $test = "FALSE";
27my $option = "";
28my @pkgs;
29
30getopts('p:t',\%opts);
31
32# Handles project name if any
33if (defined $opts{'p'}) {
34 $ENV{'PBPROJ'} = env_init($opts{'p'});
35} else {
36 $ENV{'PBPROJ'} = env_init();
37}
38# Handles test option
39if (defined $opts{'t'}) {
40 $test = "TRUE";
41 # Works only for SVN
42 $option = "-r BASE";
43}
44
45# Get Action
46$action = shift @ARGV;
47die "Syntax: pb [-p project] <action> [<params>...]" if (not defined $action);
48
49print "Project $ENV{'PBPROJ'}\n";
50#print "Action: $action - ARGV:".Dumper(\@ARGV);
51
52# Act depending on action
53if ($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}
Note: See TracBrowser for help on using the repository browser.