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: see at end |
---|
11 | |
---|
12 | use strict 'vars'; |
---|
13 | use Getopt::Std; |
---|
14 | use Data::Dumper; |
---|
15 | use English; |
---|
16 | use AppConfig qw(:argcount :expand); |
---|
17 | use File::Basename; |
---|
18 | use File::Copy; |
---|
19 | use Time::localtime qw(localtime); |
---|
20 | use POSIX qw(strftime); |
---|
21 | |
---|
22 | # Global variables |
---|
23 | use lib qw (lib); |
---|
24 | use ProjectBuilder::Distribution qw (pb_distro_init); |
---|
25 | use ProjectBuilder::Version qw (pb_version_init); |
---|
26 | use ProjectBuilder::Base qw (pb_conf_read pb_conf_get pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb pb_cms_export pb_cms_log pb_cms_isdiff pb_cms_copy pb_cms_checkout); |
---|
27 | |
---|
28 | my %opts; # CLI Options |
---|
29 | my $action; # action to realize |
---|
30 | my $test = "FALSE"; |
---|
31 | my $option = ""; |
---|
32 | my @pkgs; |
---|
33 | my $pbtag; # Global Tag variable |
---|
34 | my $pbver; # Global Version variable |
---|
35 | my $pbscript; # Name of the script |
---|
36 | my %pbver; # per package |
---|
37 | my %pbtag; # per package |
---|
38 | my $pbrev; # Global REVISION variable |
---|
39 | my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst()); |
---|
40 | my $pbdate = strftime("%Y-%m-%d", @date); |
---|
41 | my $pbdatecvs = strftime("%Y-%m-%d %H:%M:%S", @date); |
---|
42 | my $debug = 0; |
---|
43 | my $pbaccount; # Login to use to connect to the VM |
---|
44 | my $pbport; # Port to use to connect to the VM |
---|
45 | my $newver; # New version to create |
---|
46 | my $iso; # ISO iage for the VM to create |
---|
47 | my $LOG = \*STDOUT; |
---|
48 | |
---|
49 | getopts('a:hi:l:m:P:p:qr:s:tvV:',\%opts); |
---|
50 | |
---|
51 | my ($projectbuilderver,$projectbuilderrev) = pb_version_init(); |
---|
52 | if (defined $opts{'h'}) { |
---|
53 | pb_syntax(); |
---|
54 | exit(0); |
---|
55 | } |
---|
56 | if (defined $opts{'v'}) { |
---|
57 | $debug++; |
---|
58 | } |
---|
59 | if (defined $opts{'q'}) { |
---|
60 | $debug=-1; |
---|
61 | } |
---|
62 | if (defined $opts{'l'}) { |
---|
63 | open(LOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!"; |
---|
64 | $LOG = *LOG; |
---|
65 | $debug = 0 if ($debug == -1); |
---|
66 | } |
---|
67 | # Handles test option |
---|
68 | if (defined $opts{'t'}) { |
---|
69 | $test = "TRUE"; |
---|
70 | # Works only for SVN |
---|
71 | $option = "-r BASE"; |
---|
72 | } |
---|
73 | |
---|
74 | # Handle root of the project if defined |
---|
75 | if (defined $opts{'r'}) { |
---|
76 | $ENV{'PBROOT'} = $opts{'r'}; |
---|
77 | } |
---|
78 | # Handle virtual machines if any |
---|
79 | if (defined $opts{'m'}) { |
---|
80 | $ENV{'PBVM'} = $opts{'m'}; |
---|
81 | } |
---|
82 | if (defined $opts{'s'}) { |
---|
83 | $pbscript = $opts{'s'}; |
---|
84 | } |
---|
85 | if (defined $opts{'a'}) { |
---|
86 | $pbaccount = $opts{'a'}; |
---|
87 | } |
---|
88 | if (defined $opts{'P'}) { |
---|
89 | $pbport = $opts{'P'}; |
---|
90 | } |
---|
91 | if (defined $opts{'V'}) { |
---|
92 | $newver = $opts{'V'}; |
---|
93 | } |
---|
94 | if (defined $opts{'i'}) { |
---|
95 | $iso = $opts{'i'}; |
---|
96 | } |
---|
97 | |
---|
98 | # Get Action |
---|
99 | $action = shift @ARGV; |
---|
100 | die pb_syntax() if (not defined $action); |
---|
101 | |
---|
102 | my ($pbrc, $filteredfiles, $defpkgdir, $extpkgdir); |
---|
103 | |
---|
104 | # Handles project name if any |
---|
105 | # And get global params |
---|
106 | if (defined $opts{'p'}) { |
---|
107 | ($ENV{'PBPROJ'},$debug,$LOG, $pbrc, $filteredfiles, $defpkgdir, $extpkgdir) |
---|
108 | = pb_env_init($opts{'p'}); |
---|
109 | } else { |
---|
110 | ($ENV{'PBPROJ'},$debug,$LOG, $pbrc, $filteredfiles, $defpkgdir, $extpkgdir) |
---|
111 | = pb_env_init(); |
---|
112 | } |
---|
113 | |
---|
114 | print $LOG "Project: $ENV{'PBPROJ'}\n" if ($debug >= 0); |
---|
115 | print $LOG "Action: $action\n" if ($debug >= 0); |
---|
116 | |
---|
117 | # Keep those project values to store them at the end each time |
---|
118 | my $pbprojtag = $ENV{'PBTAG'}; |
---|
119 | my $pbprojver = $ENV{'PBVER'}; |
---|
120 | |
---|
121 | # Act depending on action |
---|
122 | if ($action =~ /^cms2build$/) { |
---|
123 | pb_cms2build(); |
---|
124 | } elsif ($action =~ /^build2pkg$/) { |
---|
125 | pb_build2pkg(); |
---|
126 | } elsif ($action =~ /^cms2pkg$/) { |
---|
127 | pb_cms2build(); |
---|
128 | pb_build2pkg(); |
---|
129 | } elsif ($action =~ /^build2ssh$/) { |
---|
130 | pb_build2ssh(); |
---|
131 | } elsif ($action =~ /^cms2ssh$/) { |
---|
132 | pb_cms2build(); |
---|
133 | pb_build2ssh(); |
---|
134 | } elsif ($action =~ /^pkg2ssh$/) { |
---|
135 | pb_pkg2ssh(); |
---|
136 | } elsif ($action =~ /^build2vm$/) { |
---|
137 | pb_build2vm(); |
---|
138 | } elsif ($action =~ /^cms2vm$/) { |
---|
139 | pb_cms2build(); |
---|
140 | pb_build2vm(); |
---|
141 | } elsif ($action =~ /^launchvm$/) { |
---|
142 | pb_launchvm($ENV{'PBVM'},0); |
---|
143 | } elsif ($action =~ /^script2vm$/) { |
---|
144 | pb_script2vm($pbscript); |
---|
145 | } elsif ($action =~ /^newver$/) { |
---|
146 | pb_newver(); |
---|
147 | } elsif ($action =~ /^newvm$/) { |
---|
148 | pb_launchvm($ENV{'PBVM'},1); |
---|
149 | } elsif ($action =~ /^clean$/) { |
---|
150 | } else { |
---|
151 | print $LOG "'$action' is not available\n"; |
---|
152 | pb_syntax(); |
---|
153 | } |
---|
154 | |
---|
155 | sub pb_cms2build { |
---|
156 | |
---|
157 | my $ptr = pb_get_pkg($defpkgdir,$extpkgdir); |
---|
158 | @pkgs = @$ptr; |
---|
159 | my $cms=pb_cms_init($ENV{'PBPROJ'}); |
---|
160 | |
---|
161 | my ($pkgv, $pkgt) = pb_conf_read("$ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb","pkgver","pkgtag"); |
---|
162 | |
---|
163 | # declare packager for filtering |
---|
164 | my ($tmp) = pb_conf_get("packager"); |
---|
165 | my $pbpackager = $tmp->{$ENV{'PBPROJ'}}; |
---|
166 | |
---|
167 | foreach my $pbpkg (@pkgs) { |
---|
168 | $ENV{'PBPKG'} = $pbpkg; |
---|
169 | if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) { |
---|
170 | $pbver = $pkgv->{$pbpkg}; |
---|
171 | $ENV{'PBVER'} = $pbver; |
---|
172 | } else { |
---|
173 | $pbver = $ENV{'PBVER'}; |
---|
174 | } |
---|
175 | if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) { |
---|
176 | $pbtag = $pkgt->{$pbpkg}; |
---|
177 | $ENV{'PBTAG'} = $pbtag; |
---|
178 | } else { |
---|
179 | $pbtag = $ENV{'PBTAG'}; |
---|
180 | } |
---|
181 | |
---|
182 | $pbrev = $ENV{'PBREVISION'}; |
---|
183 | print $LOG "\n"; |
---|
184 | print $LOG "Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n"; |
---|
185 | die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'}); |
---|
186 | # Clean up dest if necessary. The export will recreate it |
---|
187 | my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver"; |
---|
188 | pb_rm_rf($dest) if (-d $dest); |
---|
189 | |
---|
190 | # Export CMS tree for the concerned package to dest |
---|
191 | # And generate some additional files |
---|
192 | $OUTPUT_AUTOFLUSH=1; |
---|
193 | |
---|
194 | # computes in which dir we have to work |
---|
195 | my $dir = $defpkgdir->{$pbpkg}; |
---|
196 | $dir = $extpkgdir->{$pbpkg} if (not defined $dir); |
---|
197 | print "def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n" if ($debug >= 1); |
---|
198 | pb_cms_export($cms,$pbdatecvs,"$ENV{'PBROOT'}/$dir",$dest); |
---|
199 | |
---|
200 | # Extract cms log history and store it |
---|
201 | pb_cms_log($cms,"$ENV{'PBROOT'}/$dir","$dest/$ENV{'PBCMSLOGFILE'}"); |
---|
202 | |
---|
203 | my %build; |
---|
204 | |
---|
205 | my ($ptr) = pb_conf_get("vmlist"); |
---|
206 | foreach my $d (split(/,/,$ptr->{$ENV{'PBPROJ'}})) { |
---|
207 | my ($name,$ver) = split(/_/,$d); |
---|
208 | chomp($ver); |
---|
209 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver); |
---|
210 | print $LOG "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf)."\n" if ($debug >= 1); |
---|
211 | print $LOG "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1); |
---|
212 | |
---|
213 | # Filter build files from the less precise up to the most with overloading |
---|
214 | # Filter all files found, keeping the name, and generating in dest |
---|
215 | |
---|
216 | # Find all build files first relatively to PBROOT |
---|
217 | my %bfiles; |
---|
218 | print $LOG "DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n" if ($debug >= 1); |
---|
219 | $build{"$ddir-$dver"} = "yes"; |
---|
220 | if (-d "$ENV{'PBCONF'}/$pbpkg/$dtype") { |
---|
221 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dtype") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dtype: $!"; |
---|
222 | foreach my $f (readdir(BDIR)) { |
---|
223 | next if ($f =~ /^\./); |
---|
224 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dtype/$f"; |
---|
225 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~; |
---|
226 | } |
---|
227 | closedir(BDIR); |
---|
228 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$dfam") { |
---|
229 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dfam") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dfam: $!"; |
---|
230 | foreach my $f (readdir(BDIR)) { |
---|
231 | next if ($f =~ /^\./); |
---|
232 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dfam/$f"; |
---|
233 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~; |
---|
234 | } |
---|
235 | closedir(BDIR); |
---|
236 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir") { |
---|
237 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir: $!"; |
---|
238 | foreach my $f (readdir(BDIR)) { |
---|
239 | next if ($f =~ /^\./); |
---|
240 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir/$f"; |
---|
241 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~; |
---|
242 | } |
---|
243 | closedir(BDIR); |
---|
244 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") { |
---|
245 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir-$dver: $!"; |
---|
246 | foreach my $f (readdir(BDIR)) { |
---|
247 | next if ($f =~ /^\./); |
---|
248 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver/$f"; |
---|
249 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~; |
---|
250 | } |
---|
251 | closedir(BDIR); |
---|
252 | } else { |
---|
253 | $build{"$ddir-$dver"} = "no"; |
---|
254 | next; |
---|
255 | } |
---|
256 | print $LOG "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1); |
---|
257 | |
---|
258 | # Get all filters to apply |
---|
259 | my $ptr = pb_get_filters($pbpkg, $dtype, $dfam, $ddir, $dver); |
---|
260 | |
---|
261 | # Apply now all the filters on all the files concerned |
---|
262 | # destination dir depends on the type of file |
---|
263 | if (defined $ptr) { |
---|
264 | foreach my $f (values %bfiles) { |
---|
265 | pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$defpkgdir,$extpkgdir,$pbpackager); |
---|
266 | } |
---|
267 | } |
---|
268 | } |
---|
269 | if ($debug >= 0) { |
---|
270 | my @found; |
---|
271 | my @notfound; |
---|
272 | foreach my $b (keys %build) { |
---|
273 | push @found,$b if ($build{$b} =~ /yes/); |
---|
274 | push @notfound,$b if ($build{$b} =~ /no/); |
---|
275 | } |
---|
276 | print $LOG "Build files generated for ".join(',',@found)."\n"; |
---|
277 | print $LOG "No Build files found for ".join(',',@notfound)."\n"; |
---|
278 | } |
---|
279 | # Get the generic filter (all.pbf) and |
---|
280 | # apply those to the non-build files including those |
---|
281 | # generated by pbinit if applicable |
---|
282 | |
---|
283 | # Get only all.pbf filter |
---|
284 | $ptr = pb_get_filters($pbpkg); |
---|
285 | |
---|
286 | my $liste =""; |
---|
287 | if (defined $filteredfiles->{$pbpkg}) { |
---|
288 | foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) { |
---|
289 | pb_filter_file("$ENV{'PBROOT'}/$dir/$f",$ptr,"$dest/$f",$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager); |
---|
290 | $liste = "$f $liste"; |
---|
291 | } |
---|
292 | } |
---|
293 | print $LOG "Files ".$liste."have been filtered\n"; |
---|
294 | |
---|
295 | # Prepare the dest directory for archive |
---|
296 | if (-x "$ENV{'PBCONF'}/$pbpkg/pbinit") { |
---|
297 | pb_filter_file("$ENV{'PBCONF'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager); |
---|
298 | chmod 0755,"$ENV{'PBTMP'}/pbinit"; |
---|
299 | pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBCONF'}/$pbpkg/pbinit"); |
---|
300 | } |
---|
301 | |
---|
302 | # Archive dest dir |
---|
303 | chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}"; |
---|
304 | # Possibility to look at PBSRC to guess more the filename |
---|
305 | pb_system("tar cfz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed"); |
---|
306 | print $LOG "Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n" if ($debug >= 0); |
---|
307 | |
---|
308 | # Keep track of what is generated for default |
---|
309 | open(LAST,"> $pbrc->{$ENV{'PBPROJ'}}") || die "Unable to create $pbrc->{$ENV{'PBPROJ'}}"; |
---|
310 | print LAST "pbroot $pbprojver-$pbprojtag = $ENV{'PBROOT'}\n"; |
---|
311 | close(LAST); |
---|
312 | |
---|
313 | # Keep track of per package version |
---|
314 | if (! -f "$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") { |
---|
315 | open(PKG,">$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb"; |
---|
316 | print PKG "# Empty\n"; |
---|
317 | close(PKG); |
---|
318 | } |
---|
319 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg"); |
---|
320 | $pkg = { } if (not defined $pkg); |
---|
321 | if ((not defined $pkg->{$pbpkg}) || ($pkg->{$pbpkg} ne "$pbver-$pbtag")) { |
---|
322 | $pkg->{$pbpkg} = "$pbver-$pbtag"; |
---|
323 | } |
---|
324 | |
---|
325 | print $LOG "DEBUG pkg: ".Dumper($pkg)."\n" if ($debug >= 1); |
---|
326 | open(PKG,"> $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb"; |
---|
327 | foreach my $p (keys %$pkg) { |
---|
328 | print PKG "pbpkg $p = $pkg->{$p}\n"; |
---|
329 | } |
---|
330 | close(PKG); |
---|
331 | } |
---|
332 | } |
---|
333 | |
---|
334 | sub pb_build2pkg { |
---|
335 | |
---|
336 | # Get list of packages to build |
---|
337 | my $ptr = pb_get_pkg($defpkgdir,$extpkgdir); |
---|
338 | @pkgs = @$ptr; |
---|
339 | |
---|
340 | # Get the running distro to build on |
---|
341 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init(); |
---|
342 | print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n" if ($debug >= 1); |
---|
343 | |
---|
344 | # Get content saved in cms2build |
---|
345 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg"); |
---|
346 | $pkg = { } if (not defined $pkg); |
---|
347 | |
---|
348 | # declare packager |
---|
349 | my ($tmp) = pb_conf_get("packager"); |
---|
350 | my $pbpackager = $tmp->{$ENV{'PBPROJ'}}; |
---|
351 | |
---|
352 | chdir "$ENV{'PBBUILDDIR'}"; |
---|
353 | my $made = ""; # pkgs made during build |
---|
354 | foreach my $pbpkg (@pkgs) { |
---|
355 | my $vertag = $pkg->{$pbpkg}; |
---|
356 | # get the version of the current package - maybe different |
---|
357 | ($pbver,$pbtag) = split(/-/,$vertag); |
---|
358 | |
---|
359 | my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz"; |
---|
360 | # Suse 10.0 forces tar.bz2 usage :-( |
---|
361 | if (($ddir eq "suse") && ($dver eq "10.0")) { |
---|
362 | print "SuSE 10.0 needs bz2 type of packages so recompressing...\n"; |
---|
363 | my $newsrc="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.bz2"; |
---|
364 | system "gzip -cd $src | bzip2 -c6 > $newsrc"; |
---|
365 | $src = $newsrc; |
---|
366 | } |
---|
367 | print $LOG "Source file: $src\n" if ($debug >= 0); |
---|
368 | |
---|
369 | print $LOG "Working directory: $ENV{'PBBUILDDIR'}\n" if ($debug >= 0); |
---|
370 | if ($dtype eq "rpm") { |
---|
371 | foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') { |
---|
372 | if (! -d "$ENV{'PBBUILDDIR'}/$d") { |
---|
373 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/$d") || die "Please ensure that you can write into $ENV{'PBBUILDDIR'} to create $d\nchown the $ENV{'PBBUILDDIR'} directory to your uid"; |
---|
374 | } |
---|
375 | } |
---|
376 | |
---|
377 | symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES"; |
---|
378 | # We need to first extract the spec file |
---|
379 | my @specfile; |
---|
380 | @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS"); |
---|
381 | |
---|
382 | print $LOG "specfile: ".Dumper(\@specfile)."\n" if ($debug >= 1); |
---|
383 | # set LANGUAGE to check for correct log messages |
---|
384 | $ENV{'LANGUAGE'}="C"; |
---|
385 | #system("ls -R $ENV{'PBBUILDDIR'}") if ($debug >= 1); |
---|
386 | foreach my $f (@specfile) { |
---|
387 | if ($f =~ /\.spec$/) { |
---|
388 | pb_system("rpmbuild --define \"packager $pbpackager\" --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}"); |
---|
389 | last; |
---|
390 | } |
---|
391 | } |
---|
392 | $made="$made RPMS/*/$pbpkg-$pbver-$pbtag$pbsuf.*.rpm SRPMS/$pbpkg-$pbver-$pbtag$pbsuf.src.rpm"; |
---|
393 | if (-f "/usr/bin/rpmlint") { |
---|
394 | pb_system("rpmlint $made","Checking validity of rpms with rpmlint"); |
---|
395 | } |
---|
396 | } elsif ($dtype eq "deb") { |
---|
397 | chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}"; |
---|
398 | pb_system("tar xpfz $src","Extracting sources"); |
---|
399 | |
---|
400 | chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver"; |
---|
401 | symlink "pbconf/$ddir-$dver","debian" || die "Unable to symlink to pbconf/$ddir-$dver"; |
---|
402 | chmod 0755,"debian/rules"; |
---|
403 | pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package"); |
---|
404 | $made="$made $pbpkg"."_*.deb $pbpkg"."_*.dsc $pbpkg"."_*.tar.gz"; |
---|
405 | } elsif ($dtype eq "ebuild") { |
---|
406 | my @ebuildfile; |
---|
407 | # For gentoo we need to take pb as subsystem name |
---|
408 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/$pbpkg") if (! -d "$ENV{'PBBUILDDIR'}/portage/pb/$pbpkg"); |
---|
409 | |
---|
410 | # We need to first extract the ebuild file |
---|
411 | @ebuildfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/portage/pb/$pbpkg"); |
---|
412 | |
---|
413 | # Prepare the build env for gentoo |
---|
414 | my $found = 0; |
---|
415 | my $pbbd = $ENV{'PBBUILDDIR'}; |
---|
416 | $pbbd =~ s|/|\\/|g; |
---|
417 | open(MAKE,"/etc/make.conf") || die "Unable to open /etc/make.conf"; |
---|
418 | while (<MAKE>) { |
---|
419 | $found = 1 if (/$pbbd\/portage/); |
---|
420 | } |
---|
421 | close(MAKE); |
---|
422 | if ($found == 0) { |
---|
423 | pb_system("sudo \'echo \"$ENV{'PBBUILDDIR'}/portage\" >> /etc/make.conf\'"); |
---|
424 | } |
---|
425 | $found = 0; |
---|
426 | open(KEYW,"/etc/portage/package.keywords") || die "Unable to open /etc/portage/package.keywords"; |
---|
427 | while (<KEYW>) { |
---|
428 | $found = 1 if (/portage\/pb/); |
---|
429 | } |
---|
430 | close(KEYW); |
---|
431 | if ($found == 0) { |
---|
432 | pb_system("sudo \'echo \"portage/pb\" >> /etc/portage/package.keywords\'"); |
---|
433 | } |
---|
434 | |
---|
435 | # Build |
---|
436 | foreach my $f (@ebuildfile) { |
---|
437 | if ($f =~ /\.ebuild$/) { |
---|
438 | pb_system("ebuild $f digest ; ebuild $f package"); |
---|
439 | } |
---|
440 | } |
---|
441 | print $LOG "ebuild file: ".Dumper(\@ebuildfile)."\n" if ($debug >= 1); |
---|
442 | |
---|
443 | $made="$made portage/pb/$pbpkg/$pbpkg-$pbver.ebuild"; |
---|
444 | } elsif ($dtype eq "slackware") { |
---|
445 | $made="$made build-$pbpkg/$pbpkg-$pbver-*-$pbtag.tgz"; |
---|
446 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install"); |
---|
447 | } else { |
---|
448 | die "Unknown dtype format $dtype"; |
---|
449 | } |
---|
450 | } |
---|
451 | # Keep track of what is generated so that we can get them back from VMs |
---|
452 | open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag"; |
---|
453 | print KEEP "$made\n"; |
---|
454 | close(KEEP); |
---|
455 | } |
---|
456 | |
---|
457 | sub pb_build2ssh { |
---|
458 | pb_send2ssh("Sources"); |
---|
459 | } |
---|
460 | |
---|
461 | sub pb_pkg2ssh { |
---|
462 | pb_send2ssh("Packages"); |
---|
463 | } |
---|
464 | |
---|
465 | # By default deliver to the the public site hosting the |
---|
466 | # ftp structure (or whatever) or a VM |
---|
467 | sub pb_send2ssh { |
---|
468 | |
---|
469 | my $cmt = shift; |
---|
470 | my $vm = shift || undef; |
---|
471 | my $vmexist = shift || 0; # 0 is FALSE |
---|
472 | my $vmpid = shift || 0; # 0 is FALSE |
---|
473 | my $host = shift || "sshhost"; |
---|
474 | my $login = shift || "sshlogin"; |
---|
475 | my $dir = shift || "sshdir"; |
---|
476 | my $port = shift || "sshport"; |
---|
477 | my $tmout = shift || "vmtmout"; |
---|
478 | my $cmd = ""; |
---|
479 | |
---|
480 | # Get list of packages to build |
---|
481 | my $ptr = pb_get_pkg($defpkgdir,$extpkgdir); |
---|
482 | @pkgs = @$ptr; |
---|
483 | |
---|
484 | # Get the running distro to consider |
---|
485 | my ($odir,$over) = (undef, undef); |
---|
486 | if (defined $vm) { |
---|
487 | ($odir,$over) = split(/_/,$vm); |
---|
488 | } |
---|
489 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($odir,$over); |
---|
490 | print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n" if ($debug >= 1); |
---|
491 | |
---|
492 | # Get content saved in cms2build |
---|
493 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg"); |
---|
494 | $pkg = { } if (not defined $pkg); |
---|
495 | |
---|
496 | my $src = ""; |
---|
497 | chdir "$ENV{'PBBUILDDIR'}"; |
---|
498 | foreach my $pbpkg (@pkgs) { |
---|
499 | my $vertag = $pkg->{$pbpkg}; |
---|
500 | # get the version of the current package - maybe different |
---|
501 | ($pbver,$pbtag) = split(/-/,$vertag); |
---|
502 | |
---|
503 | if (($cmt eq "Sources") || ($cmt eq "VMs")) { |
---|
504 | $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz"; |
---|
505 | if ($cmd eq "") { |
---|
506 | $cmd = "ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz"; |
---|
507 | } else { |
---|
508 | $cmd = "$cmd ; ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz"; |
---|
509 | } |
---|
510 | } |
---|
511 | } |
---|
512 | if ($cmt eq "VMs") { |
---|
513 | $src="$src $ENV{'PBDESTDIR'}/pbscript $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb $ENV{'PBETC'}"; |
---|
514 | } elsif ($cmt eq "Script") { |
---|
515 | $src="$src $ENV{'PBDESTDIR'}/pbscript"; |
---|
516 | } elsif ($cmt eq "Packages") { |
---|
517 | # Get package list from file made during build2pkg |
---|
518 | open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag"; |
---|
519 | $src = <KEEP>; |
---|
520 | chomp($src); |
---|
521 | close(KEEP); |
---|
522 | if ($dtype eq "rpm") { |
---|
523 | # Also make a pbscript to generate yum/urpmi bases |
---|
524 | # $src = "$src $ENV{'PBDESTDIR'}/pbscript" |
---|
525 | } elsif ($dtype eq "deb") { |
---|
526 | # Also make a pbscript to generate apt bases |
---|
527 | # $src = "$src $ENV{'PBDESTDIR'}/pbscript" |
---|
528 | } |
---|
529 | } |
---|
530 | # Remove potential leading spaces (cause pb with basename) |
---|
531 | $src =~ s/^ *//; |
---|
532 | my $basesrc = ""; |
---|
533 | foreach my $i (split(/ +/,$src)) { |
---|
534 | $basesrc .= " ".basename($i); |
---|
535 | } |
---|
536 | |
---|
537 | print $LOG "Sources handled ($cmt): $src\n" if ($debug >= 0); |
---|
538 | my ($sshhost,$sshlogin,$sshdir,$sshport,$vmtmout) = pb_conf_get($host,$login,$dir,$port,$tmout); |
---|
539 | my $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}"; |
---|
540 | # Overwrite account value if passed as parameter |
---|
541 | $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount); |
---|
542 | my $tdir; |
---|
543 | my $bdir; |
---|
544 | if (($cmt eq "Sources") || ($cmt eq "Script")) { |
---|
545 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}/src"; |
---|
546 | } elsif ($cmt eq "VMs") { |
---|
547 | $tdir = dirname("$sshdir->{$ENV{'PBPROJ'}}")."/delivery"; |
---|
548 | $bdir = dirname("$sshdir->{$ENV{'PBPROJ'}}")."/build"; |
---|
549 | # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home |
---|
550 | $bdir =~ s|\$ENV.+\}/||; |
---|
551 | } elsif ($cmt eq "Packages") { |
---|
552 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver"; |
---|
553 | } else { |
---|
554 | return; |
---|
555 | } |
---|
556 | my $nport = $sshport->{$ENV{'PBPROJ'}}; |
---|
557 | $nport = "$pbport" if (defined $pbport); |
---|
558 | |
---|
559 | # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home |
---|
560 | $tdir =~ s|\$ENV.+\}/||; |
---|
561 | |
---|
562 | my $tm = $vmtmout->{$ENV{'PBPROJ'}}; |
---|
563 | pb_system("ssh -q -p $nport $mac \"mkdir -p $tdir ; cd $tdir ; echo \'for i in $basesrc; do if [ -f \$i ]; then rm -f \$i; fi; done\ ; $cmd' | bash\"","Preparing $tdir on $mac"); |
---|
564 | pb_system("cd $ENV{'PBBUILDDIR'} ; scp -p -P $nport $src $mac:$tdir 2> /dev/null","$cmt delivery in $tdir on $mac"); |
---|
565 | pb_system("ssh -q -p $nport $mac \"echo \'cd $tdir ; if [ -f pbscript ]; then ./pbscript; fi\' | bash\"","Executing pbscript on $mac if needed"); |
---|
566 | if ($cmt eq "VMs") { |
---|
567 | # Get back info on pkg produced, compute their name and get them from the VM |
---|
568 | pb_system("scp -p -P $nport $mac:$bdir/pbgen-$pbprojver-$pbprojtag $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $bdir on $mac"); |
---|
569 | open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag"; |
---|
570 | my $src = <KEEP>; |
---|
571 | chomp($src); |
---|
572 | close(KEEP); |
---|
573 | $src =~ s/^ *//; |
---|
574 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over"); |
---|
575 | # Change pgben to make the next send2ssh happy |
---|
576 | my $made = ""; |
---|
577 | open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag"; |
---|
578 | foreach my $p (split(/ +/,$src)) { |
---|
579 | my $j = basename($p); |
---|
580 | pb_system("scp -p -P $nport $mac:\'$bdir/$p\' $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Package recovery of $j in $bdir from $mac"); |
---|
581 | $made="$made $odir/$over/$j" if (($dtype ne "rpm") || ($j !~ /.src.rpm$/)); |
---|
582 | } |
---|
583 | print KEEP "$made\n"; |
---|
584 | close(KEEP); |
---|
585 | pb_system("ssh -q -p $nport $mac \"rm -rf $tdir $bdir\"","VM cleanup on $mac"); |
---|
586 | if (! $vmexist) { |
---|
587 | pb_system("ssh -q -p $nport $mac \"sudo /sbin/halt -p \"; sleep $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $vm halt (pid $vmpid)"); |
---|
588 | } |
---|
589 | pb_send2ssh("Packages","$odir"."_"."$over"); |
---|
590 | pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir"); |
---|
591 | } |
---|
592 | } |
---|
593 | |
---|
594 | sub pb_script2vm { |
---|
595 | my $pbscript=shift; |
---|
596 | |
---|
597 | # Prepare the script to be executed on the VM |
---|
598 | # in $ENV{'PBDESTDIR'}/pbscript |
---|
599 | if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript")) { |
---|
600 | copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript"; |
---|
601 | chmod 0755,"$ENV{'PBDESTDIR'}/pbscript"; |
---|
602 | } |
---|
603 | |
---|
604 | my ($vm,$all) = pb_get_vm(); |
---|
605 | |
---|
606 | foreach my $v (@$vm) { |
---|
607 | # Launch the VM |
---|
608 | my ($vmexist,$vmpid) = pb_launchvm($v,0); |
---|
609 | |
---|
610 | # Gather all required files to send them to the VM |
---|
611 | # and launch the build thourgh pbscript |
---|
612 | pb_send2ssh("Script","$v",$vmexist,$vmpid,"vmhost","vmlogin","pbrc","vmport","vmtmout"); |
---|
613 | |
---|
614 | } |
---|
615 | } |
---|
616 | |
---|
617 | sub pb_launchvm { |
---|
618 | my $vm = shift; |
---|
619 | my $create = shift || 0; # By default do not create a VM |
---|
620 | |
---|
621 | die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0)); |
---|
622 | die "No VM defined, unable to launch" if (not defined $vm); |
---|
623 | # Keep only the first VM in case many were given |
---|
624 | $vm =~ s/,.*//; |
---|
625 | |
---|
626 | # Launch the VMs |
---|
627 | my ($ptr,$vmopt,$vmport,$vmpath,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmport","vmpath","vmtmout","vmsize"); |
---|
628 | my $vmtype = $ptr->{$ENV{'PBPROJ'}}; |
---|
629 | if (not defined $ENV{'PBVMOPT'}) { |
---|
630 | $ENV{'PBVMOPT'} = ""; |
---|
631 | } |
---|
632 | if (defined $vmopt->{$ENV{'PBPROJ'}}) { |
---|
633 | $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}"; |
---|
634 | } |
---|
635 | my $nport = $vmport->{$ENV{'PBPROJ'}}; |
---|
636 | $nport = "$pbport" if (defined $pbport); |
---|
637 | |
---|
638 | my $cmd; |
---|
639 | my $vmcmd; # has to be used for pb_check_ps |
---|
640 | my $vmm; # has to be used for pb_check_ps |
---|
641 | if ($vmtype eq "qemu") { |
---|
642 | my $arch = `uname -m`; |
---|
643 | chomp($arch); |
---|
644 | my $qemucmd32; |
---|
645 | my $qemucmd64; |
---|
646 | if ($arch eq "x86_64") { |
---|
647 | $qemucmd32 = "/usr/bin/qemu-system-i386"; |
---|
648 | $qemucmd64 = "/usr/bin/qemu"; |
---|
649 | } else { |
---|
650 | $qemucmd32 = "/usr/bin/qemu"; |
---|
651 | $qemucmd64 = "/usr/bin/qemu-system-x86_64"; |
---|
652 | } |
---|
653 | if ($vm =~ /_64/) { |
---|
654 | $vmcmd = "$qemucmd64 -no-kqemu"; |
---|
655 | } else { |
---|
656 | $vmcmd = "$qemucmd32"; |
---|
657 | } |
---|
658 | $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$vm.qemu"; |
---|
659 | if ($create != 0) { |
---|
660 | $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d"; |
---|
661 | } |
---|
662 | $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm" |
---|
663 | } elsif ($vmtype eq "xen") { |
---|
664 | } elsif ($vmtype eq "vmware") { |
---|
665 | } else { |
---|
666 | die "VM of type $vmtype not supported. Report to the dev team"; |
---|
667 | } |
---|
668 | my ($tmpcmd,$void) = split(/ +/,$cmd); |
---|
669 | my $vmexist = pb_check_ps($tmpcmd,$vmm); |
---|
670 | my $vmpid = 0; |
---|
671 | if (! $vmexist) { |
---|
672 | if ($create != 0) { |
---|
673 | pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM"); |
---|
674 | } |
---|
675 | if (! -f "$vmm") { |
---|
676 | die "Unable to find VM $vmm"; |
---|
677 | } |
---|
678 | pb_system("$cmd &","Launching the VM $vmm"); |
---|
679 | pb_system("sleep $vmtmout->{$ENV{'PBPROJ'}}","Waiting for VM $vm to come up"); |
---|
680 | $vmpid = pb_check_ps($tmpcmd,$vmm); |
---|
681 | } else { |
---|
682 | print "Found an existing VM $vmm (pid $vmexist)\n"; |
---|
683 | } |
---|
684 | return($vmexist,$vmpid); |
---|
685 | } |
---|
686 | |
---|
687 | sub pb_build2vm { |
---|
688 | # Prepare the script to be executed on the VM |
---|
689 | # in $ENV{'PBDESTDIR'}/pbscript |
---|
690 | my ($ntp) = pb_conf_get("vmntp"); |
---|
691 | my $vmntp = $ntp->{$ENV{'PBPROJ'}}; |
---|
692 | open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript"; |
---|
693 | print SCRIPT "#!/bin/bash\n"; |
---|
694 | print SCRIPT "echo ... Execution needed\n"; |
---|
695 | print SCRIPT "# This is in directory delivery\n"; |
---|
696 | print SCRIPT "# Setup the variables required for building\n"; |
---|
697 | print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n"; |
---|
698 | print SCRIPT "# Preparation for pb\n"; |
---|
699 | print SCRIPT "mkdir -p ../pbconf\n"; |
---|
700 | print SCRIPT "mv $ENV{'PBPROJ'}.pb ../pbconf\n"; |
---|
701 | print SCRIPT "mv .pbrc \$HOME\n"; |
---|
702 | print SCRIPT "cd ..\n"; |
---|
703 | # Force new date to be in the future compared to the date of the tar file by adding 1 minute |
---|
704 | my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst()); |
---|
705 | $date[1]++; |
---|
706 | my $upddate = strftime("%m%d%H%M%Y", @date); |
---|
707 | print SCRIPT "echo Setting up date on $vmntp...\n"; |
---|
708 | # Or use ntpdate if available |
---|
709 | print SCRIPT "sudo date $upddate\n"; |
---|
710 | print SCRIPT "export PBROOT=\`pwd\`\n"; |
---|
711 | print SCRIPT "# Build\n"; |
---|
712 | my $p = ""; |
---|
713 | $p = join(' ',@ARGV) if (defined $ARGV[0]); |
---|
714 | print SCRIPT "echo Building packages on VM...\n"; |
---|
715 | print SCRIPT "pb -p $ENV{'PBPROJ'} build2pkg $p\n"; |
---|
716 | close(SCRIPT); |
---|
717 | chmod 0755,"$ENV{'PBDESTDIR'}/pbscript"; |
---|
718 | |
---|
719 | my ($vm,$all) = pb_get_vm(); |
---|
720 | |
---|
721 | # Send tar files when we do a global generation |
---|
722 | pb_build2ssh() if ($all == 1); |
---|
723 | |
---|
724 | foreach my $v (@$vm) { |
---|
725 | # Launch the VM |
---|
726 | my ($vmexist,$vmpid) = pb_launchvm($v,0); |
---|
727 | |
---|
728 | # Gather all required files to send them to the VM |
---|
729 | # and launch the build thourgh pbscript |
---|
730 | pb_send2ssh("VMs","$v",$vmexist,$vmpid,"vmhost","vmlogin","pbrc","vmport","vmtmout"); |
---|
731 | } |
---|
732 | } |
---|
733 | |
---|
734 | |
---|
735 | sub pb_newver { |
---|
736 | |
---|
737 | die "-V Version parameter needed" if ((not defined $newver) || ($newver eq "")); |
---|
738 | my $cms=pb_cms_init($ENV{'PBPROJ'}); |
---|
739 | if ($cms->{$ENV{'PBPROJ'}} ne "svn") { |
---|
740 | die "Only SVN is supported at the moment"; |
---|
741 | } |
---|
742 | my $res = pb_cms_isdiff($cms); |
---|
743 | die "You need to have no differences before creating a new version" if ($res != 0); |
---|
744 | my $cmsurl = pb_cms_getinfo($cms); |
---|
745 | my $newurl = dirname($cmsurl)."/$newver"; |
---|
746 | pb_cms_copy($cms,$cmsurl,$newurl); |
---|
747 | pb_cms_checkout($cms,$newurl,"$ENV{'PBROOT'}/../$newver"); |
---|
748 | my $oldver=basename($cmsurl); |
---|
749 | open(FILE,"$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb"; |
---|
750 | open(OUT,"> $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new"; |
---|
751 | while(<FILE>) { |
---|
752 | s/projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/projver $ENV{'PBPROJ'} = $newver/; |
---|
753 | print OUT $_; |
---|
754 | } |
---|
755 | close(FILE); |
---|
756 | close(OUT); |
---|
757 | rename("$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb"); |
---|
758 | pb_cms_checkin($cms,"$ENV{'PBROOT'}/../$newver"); |
---|
759 | } |
---|
760 | |
---|
761 | sub pb_get_pkg { |
---|
762 | |
---|
763 | my @pkgs; |
---|
764 | my $defpkgdir = shift; |
---|
765 | my $extpkgdir = shift; |
---|
766 | |
---|
767 | # Get packages list |
---|
768 | if (not defined $ARGV[0]) { |
---|
769 | @pkgs = keys %$defpkgdir; |
---|
770 | } elsif ($ARGV[0] =~ /^all$/) { |
---|
771 | @pkgs = keys %$defpkgdir; |
---|
772 | push(@pkgs, keys %$extpkgdir); |
---|
773 | } else { |
---|
774 | @pkgs = @ARGV; |
---|
775 | } |
---|
776 | print $LOG "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0); |
---|
777 | return(\@pkgs); |
---|
778 | } |
---|
779 | |
---|
780 | # |
---|
781 | # Return the list of VMs we are working on |
---|
782 | # $all is a flag to know if we return all of them |
---|
783 | # or only some (if all we publish also tar files in addition to pkgs |
---|
784 | # |
---|
785 | sub pb_get_vm { |
---|
786 | |
---|
787 | my @vm; |
---|
788 | my $all = 0; |
---|
789 | |
---|
790 | # Get VM list |
---|
791 | if ((not defined $ENV{'PBVM'}) || ($ENV{'PBVM'} =~ /^all$/)) { |
---|
792 | my ($ptr) = pb_conf_get("vmlist"); |
---|
793 | $ENV{'PBVM'} = $ptr->{$ENV{'PBPROJ'}}; |
---|
794 | $all = 1; |
---|
795 | } |
---|
796 | @vm = split(/,/,$ENV{'PBVM'}); |
---|
797 | print $LOG "VMs: ".join(',',@vm)."\n"; |
---|
798 | return(\@vm,$all); |
---|
799 | } |
---|
800 | |
---|
801 | # Returns the pid of a running VM command using a specific VM file |
---|
802 | sub pb_check_ps { |
---|
803 | my $vmcmd = shift; |
---|
804 | my $vmm = shift; |
---|
805 | my $vmexist = 0; # FALSE by default |
---|
806 | |
---|
807 | open(PS, "ps auxhww|") || die "Unable to call ps"; |
---|
808 | while (<PS>) { |
---|
809 | next if (! /$vmcmd/); |
---|
810 | next if (! /$vmm/); |
---|
811 | my ($void1, $void2); |
---|
812 | ($void1, $vmexist, $void2) = split(/ +/); |
---|
813 | last; |
---|
814 | } |
---|
815 | return($vmexist); |
---|
816 | } |
---|
817 | |
---|
818 | |
---|
819 | sub pb_extract_build_files { |
---|
820 | |
---|
821 | my $src=shift; |
---|
822 | my $dir=shift; |
---|
823 | my $ddir=shift; |
---|
824 | my @files; |
---|
825 | |
---|
826 | if ($src =~ /tar\.gz$/) { |
---|
827 | pb_system("tar xfpz $src $dir","Extracting build files"); |
---|
828 | } elsif ($src =~ /tar\.bz2$/) { |
---|
829 | pb_system("tar xfpj $src $dir","Extracting build files"); |
---|
830 | } else { |
---|
831 | die "Unknown compression algorithm for $src"; |
---|
832 | } |
---|
833 | opendir(DIR,"$dir") || die "Unable to open directory $dir"; |
---|
834 | foreach my $f (readdir(DIR)) { |
---|
835 | next if ($f =~ /^\./); |
---|
836 | move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir"; |
---|
837 | print $LOG "mv $dir/$f $ddir\n" if ($debug >= 1); |
---|
838 | push @files,"$ddir/$f"; |
---|
839 | } |
---|
840 | closedir(DIR); |
---|
841 | # Not enough but still a first cleanup |
---|
842 | pb_rm_rf("$dir"); |
---|
843 | return(@files); |
---|
844 | } |
---|
845 | |
---|
846 | sub pb_syntax { |
---|
847 | |
---|
848 | print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n"; |
---|
849 | print "\n"; |
---|
850 | print "Syntax: pb [-vhqt][-r pbroot][-p project][[-s script -a account -P port] -m \"mach-1[,...]\"] <action> [<pkg1>...]\n"; |
---|
851 | print "\n"; |
---|
852 | print "-h : This help file\n"; |
---|
853 | print "-q : Quiet mode\n"; |
---|
854 | print "-t : Test mode (not done yet)\n"; |
---|
855 | print "-v : Verbose mode\n"; |
---|
856 | print "\n"; |
---|
857 | print "-m machine : Name of the Virtual Machines (VM) you want\n"; |
---|
858 | print " to build on (coma separated). All if none precised\n"; |
---|
859 | print " (or use the env variable PBVM) \n"; |
---|
860 | print "\n"; |
---|
861 | print "-s script : Name of the script you want\n"; |
---|
862 | print " to execute on the related VMs.\n"; |
---|
863 | print "\n"; |
---|
864 | print "-a account : Name of the account to use\n"; |
---|
865 | print " to connect on the related VMs.\n"; |
---|
866 | print "\n"; |
---|
867 | print "-P port : Number of the port to use\n"; |
---|
868 | print " to connect on the related VMs.\n"; |
---|
869 | print "\n"; |
---|
870 | print "-p project : Name of the project you're working on\n"; |
---|
871 | print " (or use the env variable PBPROJ) \n"; |
---|
872 | print "\n"; |
---|
873 | print "-r pbroot : Path Name of project under the CMS \n"; |
---|
874 | print " (or use the env variable PBROOT) \n"; |
---|
875 | print "\n"; |
---|
876 | print "-V newver : New version of the project to create\n"; |
---|
877 | print " from the current one. \n"; |
---|
878 | print "\n"; |
---|
879 | print "<action> can be:\n"; |
---|
880 | print "\n"; |
---|
881 | print "\tcms2build: Create tar files for the project under your CMS\n"; |
---|
882 | print "\t CMS supported are SVN and CVS\n"; |
---|
883 | print "\t parameters are packages to build\n"; |
---|
884 | print "\t if not using default list\n"; |
---|
885 | print "\n"; |
---|
886 | print "\tbuild2pkg: Create packages for your running distribution \n"; |
---|
887 | print "\n"; |
---|
888 | print "\tcms2pkg: cms2build + build2pkg\n"; |
---|
889 | print "\n"; |
---|
890 | print "\tbuild2ssh: Send the tar files to a SSH host \n"; |
---|
891 | print "\n"; |
---|
892 | print "\tcms2ssh: cms2build + build2ssh\n"; |
---|
893 | print "\n"; |
---|
894 | print "\tpkg2ssh: Send the packages built to a SSH host \n"; |
---|
895 | print "\n"; |
---|
896 | print "\tbuild2vm: Create packages in VMs, launching them if needed\n"; |
---|
897 | print "\t and send those packages to a SSH host once built\n"; |
---|
898 | print "\t VM type supported are QEMU \n"; |
---|
899 | print "\n"; |
---|
900 | print "\tcms2vm: cms2build + build2vm\n"; |
---|
901 | print "\n"; |
---|
902 | print "\tlaunchvm: Launch one virtual machine\n"; |
---|
903 | print "\n"; |
---|
904 | print "\tscript2vm: Launch one virtual machine if needed \n"; |
---|
905 | print "\t and executes a script on it \n"; |
---|
906 | print "\n"; |
---|
907 | print "\tnewvm: Create a new virtual machine\n"; |
---|
908 | print "\n"; |
---|
909 | print "\tnewver: Create a new version of the project derived \n"; |
---|
910 | print "\t from the current one \n"; |
---|
911 | print "\n"; |
---|
912 | } |
---|