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

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

Begin to deal with filters

  • Property svn:executable set to *
File size: 5.6 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;
17use Time::localtime qw(localtime);
18use POSIX qw(strftime);
19
20use lib qw (lib etc);
21use vars qw (%defpkgdir %extpkgdir %version @filteredfiles);
22use common qw (env_init);
23use pb qw (defpkgdir extpkgdir version filteredfiles pb_init);
24use distro qw (distro_init);
25use cms;
26
27my %opts; # CLI Options
28my $action; # action to realize
29my $test = "FALSE";
30my $option = "";
31my @pkgs;
32
33getopts('p:t',\%opts);
34
35# Handles project name if any
36if (defined $opts{'p'}) {
37 $ENV{'PBPROJ'} = env_init($opts{'p'});
38} else {
39 $ENV{'PBPROJ'} = env_init();
40}
41# Handles test option
42if (defined $opts{'t'}) {
43 $test = "TRUE";
44 # Works only for SVN
45 $option = "-r BASE";
46}
47
48# Get Action
49$action = shift @ARGV;
50die "Syntax: pb [-p project] <action> [<params>...]" if (not defined $action);
51
52print "Project $ENV{'PBPROJ'}\n";
53#print "Action: $action - ARGV:".Dumper(\@ARGV);
54
55# Act depending on action
56if ($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 # Get all filters to apply
170 # They're cumulative from less specific to most specific
171 # suffix is .pbf
172 if (-d "$ENV{'PBCONF'}/$p/pbfilter") {
173 opendir(BDIR,"$ENV{'PBCONF'}/$p/pbfilter" || die "Unable to open dir $ENV{'PBCONF'}/$p/pbfilter: $!");
174 foreach my $f (readdir(BDIR)) {
175 if (-f "$ENV{'PBCONF'}/$p/pbfilter/$dtype.pbf") {
176
177 @bfiles = grep { ! /^\./ && -f "$ENV{'PBCONF'}/$p/$dtype/$_" } readdir(BDIR);
178 closedir(BDIR);
179 }
180
181 }
182 close(D);
183
184 }
185} else {
186 print "'$action' is not available\n";
187 print "Available actions are:\n";
188 print " cms2build\n";
189}
Note: See TracBrowser for help on using the repository browser.