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

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

Addition of distro management

  • Property svn:executable set to *
File size: 3.5 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 distro qw (distro_init);
23use cms;
24
25my %opts; # CLI Options
26my $action; # action to realize
27my $test = "FALSE";
28my $option = "";
29my @pkgs;
30
31getopts('p:t',\%opts);
32
33# Handles project name if any
34if (defined $opts{'p'}) {
35 $ENV{'PBPROJ'} = env_init($opts{'p'});
36} else {
37 $ENV{'PBPROJ'} = env_init();
38}
39# Handles test option
40if (defined $opts{'t'}) {
41 $test = "TRUE";
42 # Works only for SVN
43 $option = "-r BASE";
44}
45
46# Get Action
47$action = shift @ARGV;
48die "Syntax: pb [-p project] <action> [<params>...]" if (not defined $action);
49
50print "Project $ENV{'PBPROJ'}\n";
51#print "Action: $action - ARGV:".Dumper(\@ARGV);
52
53# Act depending on action
54if ($action =~ /^cms2build$/) {
55 print "Action: cms2build\n";
56 # Get packages list
57 if (not defined $ARGV[0]) {
58 @pkgs = keys %defpkgdir;
59 } elsif ($ARGV[0] =~ /^all$/) {
60 @pkgs = keys %defpkgdir;
61 push(@pkgs, keys %extpkgdir);
62 } else {
63 @pkgs = @ARGV;
64 }
65 print "Packages:\n";
66 print Dumper(@pkgs);
67 cms_init();
68
69 foreach my $p (@pkgs) {
70
71 my $v;
72
73 if (-f "$ENV{'PBROOT'}/$p/VERSION") {
74 open(V,"$ENV{'PBROOT'}/$p/VERSION") || die "Unable to open $ENV{'PBROOT'}/$p/VERSION";
75 $v = <V>;
76 chomp($v);
77 close(V);
78 } else {
79 $v = $ENV{'PBVER'};
80 }
81
82 my $tag;
83
84 if (-f "$ENV{'PBROOT'}/$p/TAG") {
85 open(T,"$ENV{'PBROOT'}/$p/TAG") || die "Unable to open $ENV{'PBROOT'}/$p/TAG";
86 $tag = <T>;
87 chomp($tag);
88 close(T);
89 } else {
90 $tag = $ENV{'PBTAG'};
91 }
92 print "Management of $p $v-$tag (rev $ENV{'PBREVISION'})\n";
93 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
94 # Clean up dest if necessary
95 my $dest = "$ENV{'PBDESTDIR'}/$p-$v";
96 pbrm_rf($dest) if (-d $dest);
97
98 # Export CMS tree for the concerned package to dest
99 # And generate some additional files
100 $OUTPUT_AUTOFLUSH=1;
101 print "$ENV{'PBCMSEXP'} of $p...";
102 # computes in which dir we have to work
103 my $dir = $defpkgdir{$p};
104 $dir = $extpkgdir{$p} if (not defined $dir);
105 system("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null");
106 if ($? == -1) {
107 print "failed to execute: $!\n";
108 } elsif ($? & 127) {
109 printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
110 } else {
111 print " Done under $dest\n";
112 }
113
114 # Creates a REVISION file
115 open(R,"> $dest/REVISION") || die "Unable to create $dest/REVISION";
116 print R "$ENV{'PBREVISION'}\n";
117 close(R);
118
119 # Extract cms log history and store it
120 system("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}");
121 print "$ENV{'PBCMSLOG'} of $p...";
122 if ($? == -1) {
123 print "failed to execute: $!\n";
124 } elsif ($? & 127) {
125 printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
126 } else {
127 print " OK\n";
128 }
129 open(D,"$ENV{'PBCONF'}/DISTROS") || die "Unable to find $ENV{'PBCONF'}/DISTROS\n";
130 while (<D>) {
131 my $d = $_;
132 my ($dir,$ver) = split(/_/,$d);
133 chomp($ver);
134 print "Generating build files for $dir ($ver)\n";
135 my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init($dir,$ver);
136 #print Dumper($ddir, $dver, $dfam, $dtype, $dsuf);
137 }
138 close(D);
139 }
140} else {
141 print "'$action' is not available\n";
142 print "Available actions are:\n";
143 print " cms2build\n";
144}
Note: See TracBrowser for help on using the repository browser.