1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # Base subroutines for the Project-Builder project
|
---|
4 | #
|
---|
5 | # $Id$
|
---|
6 | #
|
---|
7 |
|
---|
8 | use strict;
|
---|
9 | use lib qw (lib);
|
---|
10 | use File::Basename;
|
---|
11 | use File::Path;
|
---|
12 | use File::Temp qw /tempdir/;
|
---|
13 | use AppConfig qw(ARGCOUNT_HASH);
|
---|
14 | use Data::Dumper;
|
---|
15 |
|
---|
16 | use ProjectBuilder::Changelog qw (pb_changelog);
|
---|
17 |
|
---|
18 | $ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
|
---|
19 |
|
---|
20 | sub pb_env_init {
|
---|
21 |
|
---|
22 | my $proj=shift;
|
---|
23 | my $ver;
|
---|
24 | my $tag;
|
---|
25 |
|
---|
26 | # For the moment not dynamic
|
---|
27 | my $debug = 0; # Debug level
|
---|
28 | my $LOG = *STDOUT; # Where to log
|
---|
29 |
|
---|
30 | #
|
---|
31 | # Check project name
|
---|
32 | # Could be with env var PBPROJ
|
---|
33 | # or option -p
|
---|
34 | # if not define take the first in conf file
|
---|
35 | #
|
---|
36 | if ((defined $ENV{'PBPROJ'}) &&
|
---|
37 | (not (defined $proj))) {
|
---|
38 | $proj = $ENV{'PBPROJ'};
|
---|
39 | }
|
---|
40 |
|
---|
41 | #
|
---|
42 | # We get the pbrc file for that project
|
---|
43 | # and use its content
|
---|
44 | #
|
---|
45 | my ($pbrc) = pb_conf_read("$ENV{'PBETC'}","pbrc");
|
---|
46 | print "DEBUG pbrc: ".Dumper($pbrc)."\n" if ($debug >= 1);
|
---|
47 |
|
---|
48 | my %pbrc = %$pbrc;
|
---|
49 | if (not defined $proj) {
|
---|
50 | # Take the first as the default project
|
---|
51 | $proj = (keys %pbrc)[0];
|
---|
52 | print $LOG "Using $proj as default project as none has been specified\n" if (($debug >= 0) and (defined $proj));
|
---|
53 | }
|
---|
54 | die "No project defined - use env var PBPROJ or -p proj" if (not (defined $proj));
|
---|
55 |
|
---|
56 | #
|
---|
57 | # Set delivery directory
|
---|
58 | #
|
---|
59 | my $topdir=dirname($pbrc{$proj});
|
---|
60 | # Expand potential env variable in it
|
---|
61 | eval { $topdir =~ s/(\$ENV.+\})/$1/eeg };
|
---|
62 | chdir $topdir || die "Unable to change directory to $topdir";
|
---|
63 | $pbrc{$proj} = $topdir."/pbrc";
|
---|
64 | $ENV{'PBDESTDIR'}=$topdir."/delivery";
|
---|
65 |
|
---|
66 | #
|
---|
67 | # Use project configuration file if needed
|
---|
68 | #
|
---|
69 | if (not defined $ENV{'PBROOT'}) {
|
---|
70 | if (-f $pbrc{$proj}) {
|
---|
71 | my ($pbroot) = pb_conf_read($pbrc{$proj},"pbroot");
|
---|
72 | my %pbroot = %$pbroot;
|
---|
73 | # All lines should point to the same pbroot so take the first
|
---|
74 | $ENV{'PBROOT'} = (values %$pbroot)[0] if (defined $pbroot);
|
---|
75 | print $LOG "Using $ENV{'PBROOT'} as default pbroot from $pbrc{$proj}\n" if (($debug >= 0) and (defined $ENV{'PBROOT'}));
|
---|
76 | }
|
---|
77 | die "No pbroot defined - use env var PBROOT or -r pbroot " if (not defined $ENV{'PBROOT'});
|
---|
78 | }
|
---|
79 |
|
---|
80 | #
|
---|
81 | # Check pb conf compliance
|
---|
82 | #
|
---|
83 | $ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
|
---|
84 | die "Project $proj not Project-Builder compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
|
---|
85 |
|
---|
86 | my %version = ();
|
---|
87 | my %defpkgdir = ();
|
---|
88 | my %extpkgdir = ();
|
---|
89 | my %filteredfiles = ();
|
---|
90 |
|
---|
91 | if (-f "$ENV{'PBCONF'}/$proj.pb") {
|
---|
92 | # List of pkg to build by default (mandatory)
|
---|
93 | # List of additional pkg to build when all is called (optional)
|
---|
94 | # Valid version names (optional)
|
---|
95 | # List of files to filter (optional)
|
---|
96 | my ($defpkgdir, $extpkgdir, $version, $filteredfiles, $pkgv, $pkgt) = pb_conf_read("$ENV{'PBCONF'}/$proj.pb","defpkgdir","extpkgdir","version","filteredfiles","projver","projtag");
|
---|
97 | print "DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n" if ($debug >= 1);
|
---|
98 | print "DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n" if ($debug >= 1);
|
---|
99 | print "DEBUG: version: ".Dumper($version)."\n" if ($debug >= 1);
|
---|
100 | print "DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n" if ($debug >= 1);
|
---|
101 | die "Unable to find defpkgdir in $ENV{'PBCONF'}/$proj.pb" if (not defined $defpkgdir);
|
---|
102 | # Global
|
---|
103 | %defpkgdir = %$defpkgdir;
|
---|
104 | # Global
|
---|
105 | %extpkgdir = %$extpkgdir if (defined $extpkgdir);
|
---|
106 | %version = %$version if (defined $version);
|
---|
107 | # Global
|
---|
108 | %filteredfiles = %$filteredfiles if (defined $filteredfiles);
|
---|
109 | #
|
---|
110 | # Get global Version/Tag
|
---|
111 | #
|
---|
112 |
|
---|
113 | if (not defined $ENV{'PBVER'}) {
|
---|
114 | if ((defined $pkgv) && (defined $pkgv->{$proj})) {
|
---|
115 | $ENV{'PBVER'}=$pkgv->{$proj};
|
---|
116 | } else {
|
---|
117 | die "No projver found in $ENV{'PBCONF'}/$proj.pb";
|
---|
118 | }
|
---|
119 | }
|
---|
120 | die "Invalid version name $ENV{'PBVER'} in $ENV{'PBCONF'}/$proj.pb" if (($ENV{'PBVER'} !~ /[0-9.]+/) && (not exists $version{$ENV{'PBVER'}}));
|
---|
121 |
|
---|
122 | if (not defined $ENV{'PBTAG'}) {
|
---|
123 | if ((defined $pkgt) && (defined $pkgt->{$proj})) {
|
---|
124 | $ENV{'PBTAG'}=$pkgt->{$proj};
|
---|
125 | } else {
|
---|
126 | die "No projtag found in $ENV{'PBCONF'}/$proj.pb";
|
---|
127 | }
|
---|
128 | }
|
---|
129 | die "Invalid tag name $ENV{'PBTAG'} in $ENV{'PBCONF'}/$proj.pb" if ($ENV{'PBTAG'} !~ /[0-9.]+/);
|
---|
130 | } else {
|
---|
131 | die "Unable to open $ENV{'PBCONF'}/$proj.pb";
|
---|
132 | }
|
---|
133 |
|
---|
134 | #
|
---|
135 | # Set temp directory
|
---|
136 | #
|
---|
137 | if (not defined $ENV{'TMPDIR'}) {
|
---|
138 | $ENV{'TMPDIR'}="/tmp";
|
---|
139 | }
|
---|
140 | $ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
|
---|
141 |
|
---|
142 | #
|
---|
143 | # Removes all directory existing below the delivery dir
|
---|
144 | # as they are temp dir only
|
---|
145 | # Files stay and have to be cleaned up manually
|
---|
146 | #
|
---|
147 | if (-d $ENV{'PBDESTDIR'}) {
|
---|
148 | opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
|
---|
149 | foreach my $d (readdir(DIR)) {
|
---|
150 | next if ($d =~ /^\./);
|
---|
151 | next if (-f "$ENV{'PBDESTDIR'}/$d");
|
---|
152 | pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
|
---|
153 | }
|
---|
154 | closedir(DIR);
|
---|
155 | }
|
---|
156 | if (! -d "$ENV{'PBDESTDIR'}") {
|
---|
157 | pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
|
---|
158 | }
|
---|
159 |
|
---|
160 | #
|
---|
161 | # Set build directory
|
---|
162 | #
|
---|
163 | $ENV{'PBBUILDDIR'}=$topdir."/build";
|
---|
164 | if (! -d "$ENV{'PBBUILDDIR'}") {
|
---|
165 | pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
|
---|
166 | }
|
---|
167 |
|
---|
168 | umask 0022;
|
---|
169 | return($proj,$debug,$LOG,\%pbrc, \%filteredfiles, \%defpkgdir, \%extpkgdir);
|
---|
170 | }
|
---|
171 |
|
---|
172 | # Internal mkdir -p function
|
---|
173 | sub pb_mkdir_p {
|
---|
174 | my @dir = @_;
|
---|
175 | my $ret = mkpath(@dir, 0, 0755);
|
---|
176 | return($ret);
|
---|
177 | }
|
---|
178 |
|
---|
179 | # Internal rm -rf function
|
---|
180 | sub pb_rm_rf {
|
---|
181 | my @dir = @_;
|
---|
182 | my $ret = rmtree(@dir, 0, 0);
|
---|
183 | return($ret);
|
---|
184 | }
|
---|
185 |
|
---|
186 | # Internal system function
|
---|
187 | sub pb_system {
|
---|
188 |
|
---|
189 | my $cmd=shift;
|
---|
190 | my $cmt=shift || $cmd;
|
---|
191 |
|
---|
192 | print "$cmt... ";
|
---|
193 | #system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
|
---|
194 | system("$cmd");
|
---|
195 | if ($? == -1) {
|
---|
196 | print "failed to execute ($cmd) : $!\n";
|
---|
197 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
198 | } elsif ($? & 127) {
|
---|
199 | printf "child ($cmd) died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
|
---|
200 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
201 | } elsif ($? == 0) {
|
---|
202 | print "OK\n";
|
---|
203 | } else {
|
---|
204 | printf "child ($cmd) exited with value %d\n", $? >> 8;
|
---|
205 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | sub pb_display_file {
|
---|
210 |
|
---|
211 | my $file=shift;
|
---|
212 |
|
---|
213 | return if (not -f $file);
|
---|
214 | open(FILE,"$file");
|
---|
215 | while (<FILE>) {
|
---|
216 | print $_;
|
---|
217 | }
|
---|
218 | close(FILE);
|
---|
219 | }
|
---|
220 |
|
---|
221 | # Function which returns a pointer on a table
|
---|
222 | # corresponding to a set of values queried in the conf file
|
---|
223 | # and test the returned vaue as they need to exist in that case
|
---|
224 | sub pb_conf_get {
|
---|
225 |
|
---|
226 | my @param = @_;
|
---|
227 |
|
---|
228 | # Everything is returned via ptr1
|
---|
229 | my @ptr1 = pb_conf_read("$ENV{'PBETC'}", @param);
|
---|
230 | my @ptr2 = pb_conf_read("$ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb", @param);
|
---|
231 |
|
---|
232 | my $p1;
|
---|
233 | my $p2;
|
---|
234 |
|
---|
235 | foreach my $i (0..$#param) {
|
---|
236 | die "No $param[$i] defined for $ENV{'PBPROJ'}" if ((not defined $ptr1[$i]) && (not defined $ptr2[$i]));
|
---|
237 | # Always try to take the param from the home dir conf file in priority
|
---|
238 | # in order to mask what could be defined under the CMS to allow for overloading
|
---|
239 | $p1 = $ptr1[$i];
|
---|
240 | $p2 = $ptr2[$i];
|
---|
241 | if (not defined $p2) {
|
---|
242 | # No ref in CMS project conf file so use the home dir one.
|
---|
243 | $p1->{$ENV{'PBPROJ'}} = $p1->{'default'} if (not defined $p1->{$ENV{'PBPROJ'}});
|
---|
244 | } else {
|
---|
245 | # Ref found in CMS project conf file
|
---|
246 | if (not defined $p1) {
|
---|
247 | # No ref in home dir project conf file so use the CMS one.
|
---|
248 | $p2->{$ENV{'PBPROJ'}} = $p2->{'default'} if (not defined $p2->{$ENV{'PBPROJ'}});
|
---|
249 | $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
|
---|
250 | } else {
|
---|
251 | # Both are defined - handling the overloading
|
---|
252 | if (not defined $p1->{'default'}) {
|
---|
253 | if (defined $p2->{'default'}) {
|
---|
254 | $p1->{'default'} = $p2->{'default'};
|
---|
255 | }
|
---|
256 | }
|
---|
257 |
|
---|
258 | if (not defined $p1->{$ENV{'PBPROJ'}}) {
|
---|
259 | if (defined $p2->{$ENV{'PBPROJ'}}) {
|
---|
260 | $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
|
---|
261 | } else {
|
---|
262 | $p1->{$ENV{'PBPROJ'}} = $p1->{'default'};
|
---|
263 | }
|
---|
264 | }
|
---|
265 | }
|
---|
266 | }
|
---|
267 | die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $p1->{$ENV{'PBPROJ'}});
|
---|
268 | }
|
---|
269 | #print "DEBUG: param: ".Dumper(@ptr)."\n" if ($debug >= 1);
|
---|
270 | return(@ptr1);
|
---|
271 | }
|
---|
272 |
|
---|
273 | sub pb_no_err {
|
---|
274 | }
|
---|
275 |
|
---|
276 | # Function which returns a pointer on a hash
|
---|
277 | # corresponding to a declaration (arg2) in a conf file (arg1)
|
---|
278 | sub pb_conf_read {
|
---|
279 |
|
---|
280 | my $conffile = shift;
|
---|
281 | my @param = @_;
|
---|
282 | my $trace;
|
---|
283 | my @ptr;
|
---|
284 |
|
---|
285 | my $debug = 0;
|
---|
286 |
|
---|
287 | if ($debug > 0) {
|
---|
288 | $trace = 1;
|
---|
289 | } else {
|
---|
290 | $trace = 0;
|
---|
291 | }
|
---|
292 |
|
---|
293 |
|
---|
294 | my $config = AppConfig->new({
|
---|
295 | # Auto Create variables mentioned in Conf file
|
---|
296 | CREATE => 1,
|
---|
297 | DEBUG => $trace,
|
---|
298 | ERROR => \&pb_no_err,
|
---|
299 | GLOBAL => {
|
---|
300 | # Each conf item is a hash
|
---|
301 | ARGCOUNT => ARGCOUNT_HASH,
|
---|
302 | },
|
---|
303 | });
|
---|
304 | $config->file($conffile);
|
---|
305 | for my $param (@param) {
|
---|
306 | push @ptr,$config->get($param);
|
---|
307 | }
|
---|
308 | print "DEBUG: params: ".Dumper(@param)." ".Dumper(@ptr)."\n" if ($debug >= 1);
|
---|
309 | return(@ptr);
|
---|
310 | }
|
---|
311 |
|
---|
312 | # Setup environment for CMS system
|
---|
313 | sub pb_cms_init {
|
---|
314 |
|
---|
315 | my $proj = shift || undef;
|
---|
316 | my $ret;
|
---|
317 |
|
---|
318 | my ($cms) = pb_conf_get("cms");
|
---|
319 |
|
---|
320 | if ($cms->{$proj} eq "svn") {
|
---|
321 | $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; svnversion .)`;
|
---|
322 | chomp($ENV{'PBREVISION'});
|
---|
323 | $ENV{'PBCMSLOG'}="svn log";
|
---|
324 | $ENV{'PBCMSLOGFILE'}="svn.log";
|
---|
325 | } elsif ($cms->{$proj} eq "flat") {
|
---|
326 | $ENV{'PBREVISION'}="flat";
|
---|
327 | $ENV{'PBCMSLOG'}="/bin/true";
|
---|
328 | $ENV{'PBCMSLOGFILE'}="flat.log";
|
---|
329 | } elsif ($cms->{$proj} eq "cvs") {
|
---|
330 | # Way too slow
|
---|
331 | #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
|
---|
332 | #chomp($ENV{'PBREVISION'});
|
---|
333 | $ENV{'PBREVISION'}="CVS";
|
---|
334 | $ENV{'PBCMSLOG'}="cvs log";
|
---|
335 | $ENV{'PBCMSLOGFILE'}="cvs.log";
|
---|
336 | #
|
---|
337 | # Export content if needed
|
---|
338 | #
|
---|
339 | my ($cvsroot,$cvsrsh) = pb_conf_get("cvsroot","cvsrsh");
|
---|
340 | $ENV{'CVSROOT'} = $cvsroot->{$proj} if (defined $cvsroot->{$proj});
|
---|
341 | $ENV{'CVSRSH'} = $cvsrsh->{$proj} if (defined $cvsrsh->{$proj});
|
---|
342 | } else {
|
---|
343 | die "cms $cms->{$proj} unknown";
|
---|
344 | }
|
---|
345 | return($cms);
|
---|
346 | }
|
---|
347 |
|
---|
348 | sub pb_cms_export {
|
---|
349 | my $cms = shift;
|
---|
350 | my $pbdate = shift || undef;
|
---|
351 | my $source = shift;
|
---|
352 | my $destdir = shift;
|
---|
353 | my $tmp;
|
---|
354 | my $tmp1;
|
---|
355 |
|
---|
356 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
357 | if (-d $source) {
|
---|
358 | $tmp = $destdir;
|
---|
359 | } else {
|
---|
360 | $tmp = $destdir."/".basename($source);
|
---|
361 | }
|
---|
362 | pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp");
|
---|
363 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
364 | if (-d $source) {
|
---|
365 | $tmp = $destdir;
|
---|
366 | } else {
|
---|
367 | $tmp = $destdir."/".basename($source);
|
---|
368 | }
|
---|
369 | pb_system("cp -a $source $tmp","Exporting $source from DIR to $tmp");
|
---|
370 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
371 | my $dir=dirname($destdir);
|
---|
372 | my $base=basename($destdir);
|
---|
373 | if (-d $source) {
|
---|
374 | $tmp1 = $source;
|
---|
375 | $tmp1 =~ s|$ENV{'PBROOT'}/||;
|
---|
376 | } else {
|
---|
377 | $tmp1 = dirname($source);
|
---|
378 | $tmp1 =~ s|$ENV{'PBROOT'}/||;
|
---|
379 | $tmp1 = $tmp1."/".basename($source);
|
---|
380 | }
|
---|
381 | # CVS needs a relative path !
|
---|
382 | pb_system("cd $dir ; cvs export -D \"$pbdate\" -d $base $tmp1","Exporting $source from CVS to $destdir");
|
---|
383 | } else {
|
---|
384 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
385 | }
|
---|
386 | }
|
---|
387 |
|
---|
388 | sub pb_cms_log {
|
---|
389 | my $cms = shift;
|
---|
390 | my $pkgdir = shift;
|
---|
391 | my $destfile = shift;
|
---|
392 |
|
---|
393 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
394 | pb_system("svn log -v $pkgdir > $destfile","Extracting log info from SVN");
|
---|
395 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
396 | # Nothing to do
|
---|
397 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
398 | my $tmp=basename($pkgdir);
|
---|
399 | # CVS needs a relative path !
|
---|
400 | pb_system("cvs log $tmp > $destfile","Extracting log info from CVS");
|
---|
401 | } else {
|
---|
402 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
403 | }
|
---|
404 | }
|
---|
405 |
|
---|
406 | sub pb_cms_getinfo {
|
---|
407 | my $cms = shift;
|
---|
408 | my $url = "";
|
---|
409 | my $void = "";
|
---|
410 |
|
---|
411 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
412 | open(PIPE,"LANGUAGE=C svn info $ENV{'PBROOT'} |") || die "Unable to get svn info from $ENV{'PBROOT'}";
|
---|
413 | while (<PIPE>) {
|
---|
414 | ($void,$url) = split(/^URL:/) if (/^URL:/);
|
---|
415 | }
|
---|
416 | close(PIPE);
|
---|
417 | chomp($url);
|
---|
418 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
419 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
420 | } else {
|
---|
421 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
422 | }
|
---|
423 | return($url);
|
---|
424 | }
|
---|
425 |
|
---|
426 | sub pb_cms_copy {
|
---|
427 | my $cms = shift;
|
---|
428 | my $oldurl = shift;
|
---|
429 | my $newurl = shift;
|
---|
430 |
|
---|
431 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
432 | pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
|
---|
433 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
434 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
435 | } else {
|
---|
436 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
437 | }
|
---|
438 | }
|
---|
439 |
|
---|
440 | sub pb_cms_checkout {
|
---|
441 | my $cms = shift;
|
---|
442 | my $url = shift;
|
---|
443 | my $destination = shift;
|
---|
444 |
|
---|
445 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
446 | pb_system("svn co $url $destination","Checking $url to $destination ");
|
---|
447 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
448 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
449 | } else {
|
---|
450 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
451 | }
|
---|
452 | }
|
---|
453 |
|
---|
454 | sub pb_cms_checkin {
|
---|
455 | my $cms = shift;
|
---|
456 | my $dir = shift;
|
---|
457 |
|
---|
458 | my $ver = basename($dir);
|
---|
459 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
460 | pb_system("svn ci -m \"Updated to $ver\" $dir","Checking in $dir");
|
---|
461 | pb_system("svn up $dir","Updating $dir");
|
---|
462 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
463 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
464 | } else {
|
---|
465 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
466 | }
|
---|
467 | }
|
---|
468 |
|
---|
469 | sub pb_cms_isdiff {
|
---|
470 | my $cms = shift;
|
---|
471 |
|
---|
472 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
473 | open(PIPE,"svn diff $ENV{'PBROOT'} |") || die "Unable to get svn diff from $ENV{'PBROOT'}";
|
---|
474 | my $l = 0;
|
---|
475 | while (<PIPE>) {
|
---|
476 | $l++;
|
---|
477 | }
|
---|
478 | return($l);
|
---|
479 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
|
---|
480 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
481 | } else {
|
---|
482 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
483 | }
|
---|
484 | }
|
---|
485 |
|
---|
486 | # Get all filters to apply
|
---|
487 | # They're cumulative from less specific to most specific
|
---|
488 | # suffix is .pbf
|
---|
489 |
|
---|
490 | sub pb_get_filters {
|
---|
491 |
|
---|
492 | # For the moment not dynamic
|
---|
493 | my $debug = 0; # Debug level
|
---|
494 | my $LOG = *STDOUT; # Where to log
|
---|
495 |
|
---|
496 | my @ffiles;
|
---|
497 | my ($ffile00, $ffile0, $ffile1, $ffile2, $ffile3);
|
---|
498 | my ($mfile00, $mfile0, $mfile1, $mfile2, $mfile3);
|
---|
499 | my $pbpkg = shift || die "No package specified";
|
---|
500 | my $dtype = shift || "";
|
---|
501 | my $dfam = shift || "";
|
---|
502 | my $ddir = shift || "";
|
---|
503 | my $dver = shift || "";
|
---|
504 | my $ptr; # returned value pointer on the hash of filters
|
---|
505 | my %ptr;
|
---|
506 |
|
---|
507 | # Global filter files first, then package specificities
|
---|
508 | if (-d "$ENV{'PBCONF'}/pbfilter") {
|
---|
509 | $mfile00 = "$ENV{'PBCONF'}/pbfilter/all.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/all.pbf");
|
---|
510 | $mfile0 = "$ENV{'PBCONF'}/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/$dtype.pbf");
|
---|
511 | $mfile1 = "$ENV{'PBCONF'}/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/$dfam.pbf");
|
---|
512 | $mfile2 = "$ENV{'PBCONF'}/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/$ddir.pbf");
|
---|
513 | $mfile3 = "$ENV{'PBCONF'}/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/$ddir-$dver.pbf");
|
---|
514 |
|
---|
515 | push @ffiles,$mfile00 if (defined $mfile00);
|
---|
516 | push @ffiles,$mfile0 if (defined $mfile0);
|
---|
517 | push @ffiles,$mfile1 if (defined $mfile1);
|
---|
518 | push @ffiles,$mfile2 if (defined $mfile2);
|
---|
519 | push @ffiles,$mfile3 if (defined $mfile3);
|
---|
520 | }
|
---|
521 |
|
---|
522 | if (-d "$ENV{'PBCONF'}/$pbpkg/pbfilter") {
|
---|
523 | $ffile00 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/all.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/all.pbf");
|
---|
524 | $ffile0 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf");
|
---|
525 | $ffile1 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf");
|
---|
526 | $ffile2 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf");
|
---|
527 | $ffile3 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
|
---|
528 |
|
---|
529 | push @ffiles,$ffile00 if (defined $ffile00);
|
---|
530 | push @ffiles,$ffile0 if (defined $ffile0);
|
---|
531 | push @ffiles,$ffile1 if (defined $ffile1);
|
---|
532 | push @ffiles,$ffile2 if (defined $ffile2);
|
---|
533 | push @ffiles,$ffile3 if (defined $ffile3);
|
---|
534 | }
|
---|
535 | if (@ffiles) {
|
---|
536 | print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
|
---|
537 |
|
---|
538 | my $config = AppConfig->new({
|
---|
539 | # Auto Create variables mentioned in Conf file
|
---|
540 | CREATE => 1,
|
---|
541 | DEBUG => 0,
|
---|
542 | GLOBAL => {
|
---|
543 | # Each conf item is a hash
|
---|
544 | ARGCOUNT => AppConfig::ARGCOUNT_HASH
|
---|
545 | }
|
---|
546 | });
|
---|
547 |
|
---|
548 | $config->file(@ffiles);
|
---|
549 | $ptr = $config->get("filter");
|
---|
550 | print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
|
---|
551 | } else {
|
---|
552 | $ptr = { };
|
---|
553 | }
|
---|
554 | %ptr = %$ptr;
|
---|
555 | return(\%ptr);
|
---|
556 | }
|
---|
557 |
|
---|
558 | # Function which applies filter on pb build files
|
---|
559 | sub pb_filter_file_pb {
|
---|
560 |
|
---|
561 | my $f=shift;
|
---|
562 | my $ptr=shift;
|
---|
563 | my %filter=%$ptr;
|
---|
564 | my $destfile=shift;
|
---|
565 | my $dtype=shift;
|
---|
566 | my $pbsuf=shift;
|
---|
567 | my $pbpkg=shift;
|
---|
568 | my $pbver=shift;
|
---|
569 | my $pbtag=shift;
|
---|
570 | my $pbrev=shift;
|
---|
571 | my $pbdate=shift;
|
---|
572 | my $defpkgdir = shift;
|
---|
573 | my $extpkgdir = shift;
|
---|
574 | my $pbpackager = shift;
|
---|
575 |
|
---|
576 | # For the moment not dynamic
|
---|
577 | my $debug = 0; # Debug level
|
---|
578 | my $LOG = *STDOUT; # Where to log
|
---|
579 |
|
---|
580 | print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
|
---|
581 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
582 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
583 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
584 | while (<FILE>) {
|
---|
585 | my $line = $_;
|
---|
586 | foreach my $s (keys %filter) {
|
---|
587 | # Process single variables
|
---|
588 | print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug >= 1);
|
---|
589 | my $tmp = $filter{$s};
|
---|
590 | next if (not defined $tmp);
|
---|
591 | # Expand variables if any single one found
|
---|
592 | print $LOG "DEBUG tmp: $tmp\n" if ($debug >= 1);
|
---|
593 | if ($tmp =~ /\$/) {
|
---|
594 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
595 | # special case for ChangeLog only for pb
|
---|
596 | } elsif (($tmp =~ /^yes$/) && ($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
|
---|
597 | $tmp = "";
|
---|
598 | my $p = $defpkgdir->{$pbpkg};
|
---|
599 | $p = $extpkgdir->{$pbpkg} if (not defined $p);
|
---|
600 | pb_changelog($dtype, $pbpkg, $pbtag, $pbsuf, $p, \*DEST);
|
---|
601 | }
|
---|
602 | $line =~ s|$s|$tmp|;
|
---|
603 | }
|
---|
604 | print DEST $line;
|
---|
605 | }
|
---|
606 | close(FILE);
|
---|
607 | close(DEST);
|
---|
608 | }
|
---|
609 |
|
---|
610 | # Function which applies filter on files (external call)
|
---|
611 | sub pb_filter_file {
|
---|
612 |
|
---|
613 | my $f=shift;
|
---|
614 | my $ptr=shift;
|
---|
615 | my %filter=%$ptr;
|
---|
616 | my $destfile=shift;
|
---|
617 | my $pbpkg=shift;
|
---|
618 | my $pbver=shift;
|
---|
619 | my $pbtag=shift;
|
---|
620 | my $pbrev=shift;
|
---|
621 | my $pbdate=shift;
|
---|
622 | my $pbpackager=shift;
|
---|
623 |
|
---|
624 | # For the moment not dynamic
|
---|
625 | my $debug = 0; # Debug level
|
---|
626 | my $LOG = *STDOUT; # Where to log
|
---|
627 |
|
---|
628 | print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
|
---|
629 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
630 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
631 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
632 | while (<FILE>) {
|
---|
633 | my $line = $_;
|
---|
634 | foreach my $s (keys %filter) {
|
---|
635 | # Process single variables
|
---|
636 | print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
|
---|
637 | my $tmp = $filter{$s};
|
---|
638 | next if (not defined $tmp);
|
---|
639 | # Expand variables if any single one found
|
---|
640 | if ($tmp =~ /\$/) {
|
---|
641 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
642 | }
|
---|
643 | $line =~ s|$s|$tmp|;
|
---|
644 | }
|
---|
645 | print DEST $line;
|
---|
646 | }
|
---|
647 | close(FILE);
|
---|
648 | close(DEST);
|
---|
649 | }
|
---|
650 |
|
---|
651 |
|
---|
652 | 1;
|
---|