summaryrefslogtreecommitdiffstats
path: root/atoms_cc
diff options
context:
space:
mode:
authorSimon Lipp <simon.lipp@scilab.org>2008-06-27 15:40:47 +0000
committerSimon Lipp <simon.lipp@scilab.org>2008-06-27 15:40:47 +0000
commite4a29b649fa8f8560e4e90af7f1556f499810856 (patch)
treec77dd894e9e6fb7f3428c3252226b8ee2519190b /atoms_cc
parent503d5df36288573d88b976eeb32fe6f8e6cf2b09 (diff)
downloadscilab-e4a29b649fa8f8560e4e90af7f1556f499810856.zip
scilab-e4a29b649fa8f8560e4e90af7f1556f499810856.tar.gz
atoms_cc/buildtoolbox.pl:
* print log in stdout too * close stdin to prevent subprocess to wait for user input forever (see also bug#3182) * add ScilabVersion to required field in DESCRIPTION files * implement unpack and tbdeps stages
Diffstat (limited to 'atoms_cc')
-rwxr-xr-xatoms_cc/buildtoolbox.pl128
1 files changed, 126 insertions, 2 deletions
diff --git a/atoms_cc/buildtoolbox.pl b/atoms_cc/buildtoolbox.pl
index c2453dd..6a7572e 100755
--- a/atoms_cc/buildtoolbox.pl
+++ b/atoms_cc/buildtoolbox.pl
@@ -29,6 +29,7 @@ sub common_log {
29 chomp $message; 29 chomp $message;
30 30
31 print LOGFILE "[".time()."]${type}${message}\n"; 31 print LOGFILE "[".time()."]${type}${message}\n";
32 print "[$type] $message \n";
32} 33}
33 34
34# common_enter_stage: 35# common_enter_stage:
@@ -78,6 +79,7 @@ sub common_exec {
78 if($pid == 0) { 79 if($pid == 0) {
79 open STDOUT, ">$stdout"; 80 open STDOUT, ">$stdout";
80 open STDERR, ">$stderr"; 81 open STDERR, ">$stderr";
82 close STDIN;
81 exec $cmd; 83 exec $cmd;
82 } 84 }
83 else { 85 else {
@@ -180,8 +182,8 @@ sub read_file_from_archive {
180# get_description) 182# get_description)
181sub read_description { 183sub read_description {
182 my $fd = shift; 184 my $fd = shift;
183 my @required = qw(Toolbox Version Title Author Maintainer 185 my @required = qw(Toolbox Version Title Author Maintainer License
184 Description License Category); 186 Description ScilabVersion Category);
185 my @optional = qw(Date Depends URL Entity); 187 my @optional = qw(Date Depends URL Entity);
186 my (%infos, $key, $val); 188 my (%infos, $key, $val);
187 my (%lines, %correct); 189 my (%lines, %correct);
@@ -397,6 +399,125 @@ sub stage_check {
397 common_leave_stage("check"); 399 common_leave_stage("check");
398} 400}
399 401
402# stage_unpack:
403# Extract the archive
404sub stage_unpack {
405 common_enter_stage("unpack");
406
407 if(is_zip()) {
408 common_exec("unzip -o ${TOOLBOXFILE}");
409 }
410 else {
411 common_exec("zcat ${TOOLBOXFILE} | tar -vx");
412 }
413
414 common_leave_stage("unpack");
415}
416
417# stage_makeenv:
418# Build up the environment
419sub stage_makeenv {
420 common_enter_stage("makeenv");
421 # TODO
422 common_leave_stage("makeenv");
423}
424
425# compare_versions:
426# Returns -1 if version a < version b, 0 if equals, 1 else
427sub compare_versions {
428 my $versa = shift;
429 my $versb = shift;
430 my @va = split(/\./, $versa);
431 my @vb = split(/\./, $versb);
432
433 if($#va < $#vb) {
434 return -compare_versions($versb, $versa);
435 }
436
437 for(my $i = 0; $i < $#vb; ++$i) {
438 return 1 if $va[$i] > $vb[$i];
439 return -1 if $va[$i] < $vb[$i];
440 }
441
442 return 1 if($#va > $#vb);
443 return 0;
444}
445
446# stage_tbdeps:
447# Install toolbox dependencies
448sub stage_tbdeps {
449 my $fd;
450 my @depsarray;
451 my (%deps, %desc);
452
453 my $SCILABX = "scilab -nwni -nb -e ";
454
455 common_enter_stage("tbdeps");
456
457 # We alreay made the check, reading description should be OK
458 open $fd, "$TOOLBOXNAME/DESCRIPTION";
459 %desc = read_description($fd);
460 close($fd);
461
462 # Make a hash depname => depvers
463 @depsarray = split(/\s*,\s*/, $desc{"Depends"} || "");
464 foreach (@depsarray) {
465 if(/^(\S+?)\s*\([<>]=\s*([^)]+)\)$/) { # toolbox-name (version-comparator version)
466 $deps{$1} = $2;
467 }
468 else {
469 $deps{$_} = "*";
470 }
471 }
472
473 common_log("Dependencies: " . join(",", map { "$_ $deps{$_}" } keys %deps));
474
475 # Install dependencies
476 # fixme: we always install the last version, but some packages
477 # needs some versions... at most. Need to deal with that.
478 close(common_exec("$SCILABX 'installToolbox(\"$_\"); quit;'"))
479 foreach(keys %deps);
480
481 # Find toolboxes directory
482 $fd = common_exec("$SCILABX 'printf(\"path: %s\\n\", cd(toolboxDirectory())); quit;'");
483
484 my $tbpath;
485 while(<$fd>) {
486 if(/^path: (.+)$/) {
487 $tbpath = $1;
488 last;
489 }
490 }
491
492 if(!defined($tbpath)) {
493 common_die("Can't find toolboxes directory");
494 }
495
496 common_log("Toolboxes directory: $tbpath\n");
497
498 # Check if required toolboxes are installed
499 foreach my $dep (keys %deps) {
500 common_log("Checking $dep");
501 if(! -r "$tbpath/$dep/DESCRIPTION") {
502 common_die("Needed toolbox \"$dep\" is not installed");
503 }
504
505 next if($deps{$dep} eq "*");
506
507 open $fd, "$tbpath/$dep/DESCRIPTION";
508 my %desc2 = read_description($fd);
509 close $fd;
510
511 # fixme: we only check wether neededVersion <= installedVersion
512 # Others tests (=, <=) are still to be implemented
513 if(compare_versions($deps{$dep}, $desc2{"Version"}) > 1) {
514 common_die("We need \"$dep\" >= $deps{$dep}, but version $desc2{Version} installed");
515 }
516 }
517
518 common_leave_stage("tbdeps");
519}
520
400# Init global vars, check arguments 521# Init global vars, check arguments
401$TOOLBOXFILE = shift; 522$TOOLBOXFILE = shift;
402if(!defined($TOOLBOXFILE)) { 523if(!defined($TOOLBOXFILE)) {
@@ -415,5 +536,8 @@ common_log "Toolbox: $TOOLBOXNAME";
415common_log "Source file: $TOOLBOXFILE"; 536common_log "Source file: $TOOLBOXFILE";
416 537
417stage_check; 538stage_check;
539stage_unpack;
540stage_makeenv;
541stage_tbdeps;
418 542
419close LOGFILE; 543close LOGFILE;