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::Changelog qw (pb_changelog);
|
---|
26 | use ProjectBuilder::Version qw (pb_version_init);
|
---|
27 | 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);
|
---|
28 |
|
---|
29 | my %opts; # CLI Options
|
---|
30 | my $action; # action to realize
|
---|
31 | my $test = "FALSE";
|
---|
32 | my $option = "";
|
---|
33 | my @pkgs;
|
---|
34 | my $pbtag; # Global Tag variable
|
---|
35 | my $pbver; # Global Version variable
|
---|
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 $debug = 0;
|
---|
42 | my $LOG = \*STDOUT;
|
---|
43 |
|
---|
44 | getopts('hl:m:p:qr:tv',\%opts);
|
---|
45 |
|
---|
46 | my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
|
---|
47 | if (defined $opts{'h'}) {
|
---|
48 | pb_syntax();
|
---|
49 | exit(0);
|
---|
50 | }
|
---|
51 | if (defined $opts{'v'}) {
|
---|
52 | $debug++;
|
---|
53 | }
|
---|
54 | if (defined $opts{'q'}) {
|
---|
55 | $debug=-1;
|
---|
56 | }
|
---|
57 | if (defined $opts{'l'}) {
|
---|
58 | open(LOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
|
---|
59 | $LOG = *LOG;
|
---|
60 | $debug = 0 if ($debug == -1);
|
---|
61 | }
|
---|
62 | # Handles test option
|
---|
63 | if (defined $opts{'t'}) {
|
---|
64 | $test = "TRUE";
|
---|
65 | # Works only for SVN
|
---|
66 | $option = "-r BASE";
|
---|
67 | }
|
---|
68 |
|
---|
69 | # Handle root of the project if defined
|
---|
70 | if (defined $opts{'r'}) {
|
---|
71 | $ENV{'PBROOT'} = $opts{'r'};
|
---|
72 | }
|
---|
73 | # Handle virtual machines if any
|
---|
74 | if (defined $opts{'m'}) {
|
---|
75 | $ENV{'PBVM'} = $opts{'m'};
|
---|
76 | }
|
---|
77 |
|
---|
78 | # Get Action
|
---|
79 | $action = shift @ARGV;
|
---|
80 | die pb_syntax() if (not defined $action);
|
---|
81 |
|
---|
82 | my ($pbrc, $filteredfiles, $defpkgdir, $extpkgdir);
|
---|
83 |
|
---|
84 | # Handles project name if any
|
---|
85 | # And get global params
|
---|
86 | if (defined $opts{'p'}) {
|
---|
87 | ($ENV{'PBPROJ'},$debug,$LOG, $pbrc, $filteredfiles, $defpkgdir, $extpkgdir)
|
---|
88 | = pb_env_init($opts{'p'});
|
---|
89 | } else {
|
---|
90 | ($ENV{'PBPROJ'},$debug,$LOG, $pbrc, $filteredfiles, $defpkgdir, $extpkgdir)
|
---|
91 | = pb_env_init();
|
---|
92 | }
|
---|
93 | my %pbrc = %$pbrc;
|
---|
94 | my %filteredfiles = %$filteredfiles;
|
---|
95 | my %defpkgdir = %$defpkgdir;
|
---|
96 | my %extpkgdir = %$extpkgdir;
|
---|
97 |
|
---|
98 | print $LOG "Project: $ENV{'PBPROJ'}\n" if ($debug >= 0);
|
---|
99 | print $LOG "Action: $action\n" if ($debug >= 0);
|
---|
100 |
|
---|
101 | # Keep those project values to store them at the end each time
|
---|
102 | my $pbprojtag = $ENV{'PBTAG'};
|
---|
103 | my $pbprojver = $ENV{'PBVER'};
|
---|
104 |
|
---|
105 | # Act depending on action
|
---|
106 | if ($action =~ /^cms2build$/) {
|
---|
107 | pb_cms2build();
|
---|
108 | } elsif ($action =~ /^build2pkg$/) {
|
---|
109 | pb_build2pkg();
|
---|
110 | } elsif ($action =~ /^cms2pkg$/) {
|
---|
111 | pb_cms2build();
|
---|
112 | pb_build2pkg();
|
---|
113 | } elsif ($action =~ /^build2ssh$/) {
|
---|
114 | pb_build2ssh();
|
---|
115 | } elsif ($action =~ /^pkg2ssh$/) {
|
---|
116 | pb_pkg2ssh();
|
---|
117 | } elsif ($action =~ /^build2vm$/) {
|
---|
118 | pb_build2vm();
|
---|
119 | } elsif ($action =~ /^cms2vm$/) {
|
---|
120 | pb_cms2build();
|
---|
121 | pb_build2vm();
|
---|
122 | } elsif ($action =~ /^cms2ssh$/) {
|
---|
123 | pb_cms2build();
|
---|
124 | pb_build2vm();
|
---|
125 | pb_build2ssh();
|
---|
126 | pb_pkg2ssh();
|
---|
127 | } elsif ($action =~ /^clean$/) {
|
---|
128 | } else {
|
---|
129 | print $LOG "'$action' is not available\n";
|
---|
130 | pb_syntax();
|
---|
131 | }
|
---|
132 |
|
---|
133 | sub pb_cms2build {
|
---|
134 |
|
---|
135 | my $ptr = pb_get_pkg(\%defpkgdir,\%extpkgdir);
|
---|
136 | @pkgs = @$ptr;
|
---|
137 | my $cms=pb_cms_init($ENV{'PBPROJ'},$pbdate);
|
---|
138 |
|
---|
139 | my ($pkgv, $pkgt) = pb_conf_read("$ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb","pkgver","pkgtag");
|
---|
140 | foreach my $pbpkg (@pkgs) {
|
---|
141 | if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
|
---|
142 | $pbver = $pkgv->{$pbpkg};
|
---|
143 | } else {
|
---|
144 | $pbver = $ENV{'PBVER'};
|
---|
145 | }
|
---|
146 | if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
|
---|
147 | $pbtag = $pkgt->{$pbpkg};
|
---|
148 | } else {
|
---|
149 | $pbtag = $ENV{'PBTAG'};
|
---|
150 | }
|
---|
151 |
|
---|
152 | $pbrev = $ENV{'PBREVISION'};
|
---|
153 | print $LOG "\n" if ($debug >= 0);
|
---|
154 | print $LOG "Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n" if ($debug >= 0);
|
---|
155 | die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
|
---|
156 | # Clean up dest if necessary. The export will recreate it
|
---|
157 | my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
|
---|
158 | pb_rm_rf($dest) if (-d $dest);
|
---|
159 |
|
---|
160 | # Export CMS tree for the concerned package to dest
|
---|
161 | # And generate some additional files
|
---|
162 | $OUTPUT_AUTOFLUSH=1;
|
---|
163 |
|
---|
164 | # computes in which dir we have to work
|
---|
165 | my $dir = $defpkgdir{$pbpkg};
|
---|
166 | $dir = $extpkgdir{$pbpkg} if (not defined $dir);
|
---|
167 | pb_cms_export($cms,$pbdate,"$ENV{'PBROOT'}/$dir",$dest);
|
---|
168 |
|
---|
169 | # Extract cms log history and store it
|
---|
170 | pb_cms_log($cms,"$ENV{'PBROOT'}/$dir","$dest/$ENV{'PBCMSLOGFILE'}");
|
---|
171 |
|
---|
172 | my %build;
|
---|
173 |
|
---|
174 | my ($ptr) = pb_conf_get("vmlist");
|
---|
175 | foreach my $d (split(/,/,$ptr->{$ENV{'PBPROJ'}})) {
|
---|
176 | my ($name,$ver) = split(/_/,$d);
|
---|
177 | chomp($ver);
|
---|
178 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
|
---|
179 | print $LOG "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf)."\n" if ($debug >= 1);
|
---|
180 | print $LOG "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1);
|
---|
181 |
|
---|
182 | # Filter build files from the less precise up to the most with overloading
|
---|
183 | # Filter all files found, keeping the name, and generating in dest
|
---|
184 |
|
---|
185 | # Find all build files first relatively to PBROOT
|
---|
186 | my %bfiles;
|
---|
187 | print $LOG "DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n" if ($debug >= 1);
|
---|
188 | $build{"$ddir-$dver"} = "yes";
|
---|
189 | if (-d "$ENV{'PBCONF'}/$pbpkg/$dtype") {
|
---|
190 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dtype") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dtype: $!";
|
---|
191 | foreach my $f (readdir(BDIR)) {
|
---|
192 | next if ($f =~ /^\./);
|
---|
193 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dtype/$f";
|
---|
194 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
195 | }
|
---|
196 | closedir(BDIR);
|
---|
197 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$dfam") {
|
---|
198 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dfam") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dfam: $!";
|
---|
199 | foreach my $f (readdir(BDIR)) {
|
---|
200 | next if ($f =~ /^\./);
|
---|
201 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dfam/$f";
|
---|
202 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
203 | }
|
---|
204 | closedir(BDIR);
|
---|
205 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir") {
|
---|
206 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir: $!";
|
---|
207 | foreach my $f (readdir(BDIR)) {
|
---|
208 | next if ($f =~ /^\./);
|
---|
209 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir/$f";
|
---|
210 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
211 | }
|
---|
212 | closedir(BDIR);
|
---|
213 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") {
|
---|
214 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir-$dver: $!";
|
---|
215 | foreach my $f (readdir(BDIR)) {
|
---|
216 | next if ($f =~ /^\./);
|
---|
217 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver/$f";
|
---|
218 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
219 | }
|
---|
220 | closedir(BDIR);
|
---|
221 | } else {
|
---|
222 | $build{"$ddir-$dver"} = "no";
|
---|
223 | next;
|
---|
224 | }
|
---|
225 | print $LOG "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1);
|
---|
226 |
|
---|
227 | # Get all filters to apply
|
---|
228 | my $ptr = pb_get_filters($pbpkg, $dtype, $dfam, $ddir, $dver);
|
---|
229 |
|
---|
230 | # Apply now all the filters on all the files concerned
|
---|
231 | # destination dir depends on the type of file
|
---|
232 | if (defined $ptr) {
|
---|
233 | foreach my $f (values %bfiles) {
|
---|
234 | pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,\%defpkgdir,\%extpkgdir);
|
---|
235 | }
|
---|
236 | if (defined $filteredfiles{$pbpkg}) {
|
---|
237 | foreach my $f (split(/,/,$filteredfiles{$pbpkg})) {
|
---|
238 | pb_filter_file("$ENV{'PBROOT'}/$dir/$f",$ptr,"$dest/$f",$pbsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate);
|
---|
239 | }
|
---|
240 | }
|
---|
241 | }
|
---|
242 | }
|
---|
243 | if ($debug >= 0) {
|
---|
244 | my @found;
|
---|
245 | my @notfound;
|
---|
246 | foreach my $b (keys %build) {
|
---|
247 | push @found,$b if ($build{$b} =~ /yes/);
|
---|
248 | push @notfound,$b if ($build{$b} =~ /no/);
|
---|
249 | }
|
---|
250 | print $LOG "Build files generated for ".join(',',@found)."\n";
|
---|
251 | print $LOG "No Build files found for ".join(',',@notfound)."\n";
|
---|
252 | }
|
---|
253 | # Prepare the dest directory for archive
|
---|
254 | if (-x "$ENV{'PBCONF'}/$pbpkg/pbinit") {
|
---|
255 | #pb_system("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit","Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit");
|
---|
256 | print $LOG "Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit\n";
|
---|
257 | system("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit");
|
---|
258 | }
|
---|
259 |
|
---|
260 | # Archive dest dir
|
---|
261 | chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
|
---|
262 | # Possibility to look at PBSRC to guess more the filename
|
---|
263 | pb_system("tar cfz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed");
|
---|
264 | print $LOG "Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n" if ($debug >= 0);
|
---|
265 |
|
---|
266 | # Keep track of what is generated for default
|
---|
267 | open(LAST,"> $pbrc{$ENV{'PBPROJ'}}") || die "Unable to create $pbrc{$ENV{'PBPROJ'}}";
|
---|
268 | print LAST "pbroot $pbprojver-$pbprojtag = $ENV{'PBROOT'}\n";
|
---|
269 | close(LAST);
|
---|
270 |
|
---|
271 | # Keep track of per package version
|
---|
272 | if (! -f "$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") {
|
---|
273 | open(PKG,">$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb";
|
---|
274 | print PKG "# Empty\n";
|
---|
275 | close(PKG);
|
---|
276 | }
|
---|
277 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
|
---|
278 | $pkg = { } if (not defined $pkg);
|
---|
279 | if ((not defined $pkg->{$pbpkg}) || ($pkg->{$pbpkg} ne "$pbver-$pbtag")) {
|
---|
280 | $pkg->{$pbpkg} = "$pbver-$pbtag";
|
---|
281 | }
|
---|
282 |
|
---|
283 | print $LOG "DEBUG pkg: ".Dumper($pkg)."\n" if ($debug >= 1);
|
---|
284 | open(PKG,"> $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb";
|
---|
285 | foreach my $p (keys %$pkg) {
|
---|
286 | print PKG "pbpkg $p = $pkg->{$p}\n";
|
---|
287 | }
|
---|
288 | close(PKG);
|
---|
289 | }
|
---|
290 | }
|
---|
291 |
|
---|
292 | sub pb_build2pkg {
|
---|
293 |
|
---|
294 | # Get list of packages to build
|
---|
295 | my $ptr = pb_get_pkg(\%defpkgdir,\%extpkgdir);
|
---|
296 | @pkgs = @$ptr;
|
---|
297 |
|
---|
298 | # Get the running distro to build on
|
---|
299 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
|
---|
300 | print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n" if ($debug >= 1);
|
---|
301 |
|
---|
302 | # Get content saved in cms2build
|
---|
303 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
|
---|
304 | $pkg = { } if (not defined $pkg);
|
---|
305 |
|
---|
306 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
307 | foreach my $pbpkg (@pkgs) {
|
---|
308 | my $vertag = $pkg->{$pbpkg};
|
---|
309 | # get the version of the current package - maybe different
|
---|
310 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
311 |
|
---|
312 | my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
313 | print $LOG "Source file: $src\n" if ($debug >= 0);
|
---|
314 |
|
---|
315 | if ($dtype eq "rpm") {
|
---|
316 | print $LOG "Working under $ENV{'PBBUILDDIR'}\n" if ($debug >= 0);
|
---|
317 | foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
|
---|
318 | if (! -d "$ENV{'PBBUILDDIR'}/$d") {
|
---|
319 | 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";
|
---|
320 | }
|
---|
321 | }
|
---|
322 |
|
---|
323 | # We need to first extract the spec file
|
---|
324 | symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
|
---|
325 | my @specfile;
|
---|
326 | @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
|
---|
327 |
|
---|
328 | print $LOG "specfile: ".Dumper(\@specfile)."\n" if ($debug >= 1);
|
---|
329 | # set LANGUAGE to check for correct log messages
|
---|
330 | $ENV{'LANGUAGE'}="C";
|
---|
331 | #system("ls -R $ENV{'PBBUILDDIR'}") if ($debug >= 1);
|
---|
332 | foreach my $f (@specfile) {
|
---|
333 | if ($f =~ /\.spec$/) {
|
---|
334 | pb_system("rpmbuild --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}");
|
---|
335 | last;
|
---|
336 | }
|
---|
337 | }
|
---|
338 | } elsif ($dtype eq "tgz") {
|
---|
339 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install");
|
---|
340 | } elsif ($dtype eq "ebuild") {
|
---|
341 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage") if (! -d "$ENV{'PBBUILDDIR'}/portage");
|
---|
342 | } else {
|
---|
343 | }
|
---|
344 | }
|
---|
345 | }
|
---|
346 |
|
---|
347 | sub pb_build2ssh {
|
---|
348 | pb_send2ssh("Sources");
|
---|
349 | }
|
---|
350 |
|
---|
351 | sub pb_pkg2ssh {
|
---|
352 | pb_send2ssh("Packages");
|
---|
353 | }
|
---|
354 |
|
---|
355 | # By default deliver to the the public site hosting the
|
---|
356 | # ftp structure (or whatever) or a VM
|
---|
357 | sub pb_send2ssh {
|
---|
358 |
|
---|
359 | my $cmt = shift;
|
---|
360 | my $host = shift || "sshhost";
|
---|
361 | my $login = shift || "sshlogin";
|
---|
362 | my $dir = shift || "sshdir";
|
---|
363 | my $port = shift || "sshport";
|
---|
364 |
|
---|
365 | my @src;
|
---|
366 |
|
---|
367 | # Get list of packages to build
|
---|
368 | my $ptr = pb_get_pkg(\%defpkgdir,\%extpkgdir);
|
---|
369 | @pkgs = @$ptr;
|
---|
370 |
|
---|
371 | # Get the running distro to build on
|
---|
372 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
|
---|
373 | print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n" if ($debug >= 1);
|
---|
374 |
|
---|
375 | # Get content saved in cms2build
|
---|
376 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
|
---|
377 | $pkg = { } if (not defined $pkg);
|
---|
378 |
|
---|
379 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
380 | my $src;
|
---|
381 | foreach my $pbpkg (@pkgs) {
|
---|
382 | my $vertag = $pkg->{$pbpkg};
|
---|
383 | # get the version of the current package - maybe different
|
---|
384 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
385 |
|
---|
386 | if ($cmt eq "Sources") {
|
---|
387 | $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
388 | } elsif ($cmt eq "VMs") {
|
---|
389 | $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/pbscript $ENV{'PBETC'}";
|
---|
390 | } elsif ($cmt eq "Packages") {
|
---|
391 | if ($dtype eq "rpm") {
|
---|
392 | $src="$ENV{'PBBUILDDIR'}/RPMS/*/$pbpkg-$pbver-$pbtag$pbsuf.*.rpm $ENV{'PBBUILDDIR'}/SRPMS/$pbpkg-$pbver-$pbtag$pbsuf.src.rpm"
|
---|
393 | } elsif ($dtype eq "deb") {
|
---|
394 | my $tmp = "$ENV{'PBBUILDDIR'}/$pbpkg";
|
---|
395 | $src="$tmp"."_*.deb $tmp"."_*.dsc $tmp"."_*.tar.gz"
|
---|
396 | } elsif ($dtype eq "ebuild") {
|
---|
397 | $src="$ENV{'PBBUILDDIR'}/portage/*/$pbpkg/$pbpkg-$pbver.ebuild"
|
---|
398 | } elsif ($dtype eq "slackware") {
|
---|
399 | $src="$ENV{'PBBUILDDIR'}/build-$pbpkg/$pbpkg-$pbver-*-$pbtag.tgz"
|
---|
400 | } else {
|
---|
401 | die "Unknown dtype format $dtype";
|
---|
402 | }
|
---|
403 | # Also make a pbscript to generate yum/urpmi/apt bases
|
---|
404 | # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
|
---|
405 | }
|
---|
406 | print $LOG "$cmt: $src\n" if ($debug >= 0);
|
---|
407 | push @src, $src;
|
---|
408 | }
|
---|
409 | my ($sshhost,$sshlogin,$sshdir,$sshport) = pb_conf_get($host,$login,$dir,$port);
|
---|
410 | my $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
|
---|
411 | my $tdir;
|
---|
412 | if ($cmt eq "Sources") {
|
---|
413 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}/src";
|
---|
414 | } elsif ($cmt eq "VMs") {
|
---|
415 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}";
|
---|
416 | } elsif ($cmt eq "Packages") {
|
---|
417 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
|
---|
418 | } else {
|
---|
419 | return;
|
---|
420 | }
|
---|
421 | $src = join(' ',@src);
|
---|
422 | pb_system("ssh -q $mac \"mkdir -p $tdir ; cd $tdir ; rm -f $src\"","Preparing $tdir on $mac");
|
---|
423 | pb_system("scp -p -P $sshport $src $mac:$tdir","$cmt delivery in $tdir on $mac");
|
---|
424 | pb_system("ssh -q $mac \"cd $tdir ; if [-f pbscript]; then chmod 755 ./pbscript ; ./pbscript\"","Executing pbscript on $mac");
|
---|
425 | if ($cmt eq "VMs") {
|
---|
426 | pb_system("scp -p -P $sshport $mac:$tdir/.... ...","Package recovery in $tdir from $mac");
|
---|
427 | }
|
---|
428 | }
|
---|
429 |
|
---|
430 | sub pb_build2vm {
|
---|
431 | my ($vm,$all) = pb_get_vm();
|
---|
432 |
|
---|
433 | # Prepare the script to be executed on the VM
|
---|
434 | # in $ENV{'PBDESTDIR'}/pbscript
|
---|
435 | # Launch the VM
|
---|
436 | # Gather all required files to send them to the VM
|
---|
437 | pb_send2ssh("VMs","vmhost","vmlogin","vmdir","vmport");
|
---|
438 |
|
---|
439 | # Send tar files when we do a global generation
|
---|
440 | pb_build2ssh() if ($all == 1);
|
---|
441 | }
|
---|
442 |
|
---|
443 | sub pb_get_pkg {
|
---|
444 |
|
---|
445 | my @pkgs;
|
---|
446 | my $defpkgdir = shift;
|
---|
447 | my $extpkgdir = shift;
|
---|
448 |
|
---|
449 | my %defpkgdir = %$defpkgdir;
|
---|
450 | my %extpkgdir = %$extpkgdir;
|
---|
451 |
|
---|
452 | # Get packages list
|
---|
453 | if (not defined $ARGV[0]) {
|
---|
454 | @pkgs = keys %defpkgdir;
|
---|
455 | } elsif ($ARGV[0] =~ /^all$/) {
|
---|
456 | @pkgs = keys %defpkgdir;
|
---|
457 | push(@pkgs, keys %extpkgdir);
|
---|
458 | } else {
|
---|
459 | @pkgs = @ARGV;
|
---|
460 | }
|
---|
461 | print $LOG "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0);
|
---|
462 | return(\@pkgs);
|
---|
463 | }
|
---|
464 |
|
---|
465 | #
|
---|
466 | # Return the list of VMs we are working on
|
---|
467 | # $all is a flag to know if we return all of them
|
---|
468 | # or only some (if all we publish also tar files in addition to pkgs
|
---|
469 | #
|
---|
470 | sub pb_get_vm {
|
---|
471 |
|
---|
472 | my @vm;
|
---|
473 | my $all = 0;
|
---|
474 |
|
---|
475 | # Get VM list
|
---|
476 | if ((not defined $ENV{'PBVM'}) || ($ENV{'PBVM'} =~ /^all$/)) {
|
---|
477 | my ($ptr) = pb_conf_get("vmlist");
|
---|
478 | $ENV{'PBVM'} = $ptr->{$ENV{'PBPROJ'}};
|
---|
479 | $all = 1;
|
---|
480 | }
|
---|
481 | @vm = split(/,/,$ENV{'PBVM'});
|
---|
482 | print $LOG "VMs: ".join(',',@vm)."\n";
|
---|
483 | return(\@vm,$all);
|
---|
484 | }
|
---|
485 |
|
---|
486 | sub pb_extract_build_files {
|
---|
487 |
|
---|
488 | my $src=shift;
|
---|
489 | my $dir=shift;
|
---|
490 | my $ddir=shift;
|
---|
491 | my @files;
|
---|
492 |
|
---|
493 | pb_system("tar xfpz $src $dir","Extracting build files");
|
---|
494 | opendir(DIR,"$dir") || die "Unable to open directory $dir";
|
---|
495 | foreach my $f (readdir(DIR)) {
|
---|
496 | next if ($f =~ /^\./);
|
---|
497 | move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
|
---|
498 | print $LOG "mv $dir/$f $ddir\n" if ($debug >= 1);
|
---|
499 | push @files,"$ddir/$f";
|
---|
500 | }
|
---|
501 | closedir(DIR);
|
---|
502 | # Not enough but still a first cleanup
|
---|
503 | pb_rm_rf("$dir");
|
---|
504 | return(@files);
|
---|
505 | }
|
---|
506 |
|
---|
507 | sub pb_syntax {
|
---|
508 |
|
---|
509 | print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n";
|
---|
510 | print "\n";
|
---|
511 | print "Syntax: pb [-vhqt][-r pbroot][-p project][-m \"mach-1[,...]\"] <action> [<pkg1>...]\n";
|
---|
512 | print "\n";
|
---|
513 | print "-h : This help file\n";
|
---|
514 | print "-q : Quiet mode\n";
|
---|
515 | print "-t : Test mode (not done yet)\n";
|
---|
516 | print "-v : Verbose mode\n";
|
---|
517 | print "\n";
|
---|
518 | print "-m machine : Name of the virtual Machines you want\n";
|
---|
519 | print " to build on (space separated) \n";
|
---|
520 | print " (or use the env variable PBVM) \n";
|
---|
521 | print "\n";
|
---|
522 | print "-p project : Name of the project you're working on\n";
|
---|
523 | print " (or use the env variable PBPROJ) \n";
|
---|
524 | print "\n";
|
---|
525 | print "-r pbroot : Path Name of project under the CMS \n";
|
---|
526 | print " (or use the env variable PBROOT) \n";
|
---|
527 | print "\n";
|
---|
528 | print "<params> can be the name of packages\n";
|
---|
529 | print "<action> can be:\n";
|
---|
530 | print "\n";
|
---|
531 | print "\tcms2build: Create tar files for the project under your CMS\n";
|
---|
532 | print "\t CMS supported are SVN and CVS\n";
|
---|
533 | print "\t parameters are packages to build\n";
|
---|
534 | print "\t if not using default list\n";
|
---|
535 | print "\n";
|
---|
536 | print "\tbuild2pkg: Create packages for your running distribution \n";
|
---|
537 | print "\t first parameter is version-tag to build\n";
|
---|
538 | print "\t if not using default version-tag\n";
|
---|
539 | print "\t following parameters are packages to build\n";
|
---|
540 | print "\t if not using default list\n";
|
---|
541 | print "\n";
|
---|
542 | print "\tbuild2ssh: Send the tar files to a SSH host \n";
|
---|
543 | print "\n";
|
---|
544 | print "\tpkg2ssh: Send the packages built to a SSH host \n";
|
---|
545 | print "\n";
|
---|
546 | print "\tcms2pkg: cms2build + build2pkg\n";
|
---|
547 | print "\n";
|
---|
548 | }
|
---|