summaryrefslogtreecommitdiffstats
path: root/atoms_cc
diff options
context:
space:
mode:
authorSimon Lipp <simon.lipp@scilab.org>2008-07-07 08:47:29 +0000
committerSimon Lipp <simon.lipp@scilab.org>2008-07-07 08:47:29 +0000
commit7b11fd2170d589bc6d47aeace191119d5246ef53 (patch)
tree5553912bdafda40d9fd669ee9e7ddbe41bef9519 /atoms_cc
parentd9982dd684cecb65cba814fc54708702ee85096f (diff)
downloadscilab-7b11fd2170d589bc6d47aeace191119d5246ef53.zip
scilab-7b11fd2170d589bc6d47aeace191119d5246ef53.tar.gz
atoms_cc/buildtoolbox.pl: make it more reliable on windows (bsdtar compatibility, don't rely on closed stdin to avoid scilab interaction)
Diffstat (limited to 'atoms_cc')
-rwxr-xr-xatoms_cc/buildtoolbox.pl73
1 files changed, 43 insertions, 30 deletions
diff --git a/atoms_cc/buildtoolbox.pl b/atoms_cc/buildtoolbox.pl
index 791050f..e07e810 100755
--- a/atoms_cc/buildtoolbox.pl
+++ b/atoms_cc/buildtoolbox.pl
@@ -10,6 +10,11 @@ my ($TOOLBOXFILE, # Toolbox archive to compile
10 $TOOLBOXNAME, # Name of the toolbox 10 $TOOLBOXNAME, # Name of the toolbox
11 $STAGE); # Current stage 11 $STAGE); # Current stage
12 12
13# Save standard I/O for common_exec
14open OLD_STDOUT, ">&STDOUT";
15open OLD_STDERR, ">&STDERR";
16open OLD_STDIN, "<&STDIN";
17
13# common_log(message, type): 18# common_log(message, type):
14# Print a log message. Second argument is the type of the 19# Print a log message. Second argument is the type of the
15# message: 20# message:
@@ -57,9 +62,12 @@ sub common_die {
57 exit(1); 62 exit(1);
58} 63}
59 64
60# common_exec(command, args...): 65# common_exec(command, args..., [opts]):
61# Execute given command, places its outputs to log files. 66# Execute given command, places its outputs to log files. If last argument
62# Returns a file handle on STDOUT 67# is a reference to a hash, it's considered as options for the function.
68# Right now, only one option is available, "stderr_to_stdout", which do the
69# same as 2>&1 in shell.
70# Returns a file handle on STDOUT.
63# Die if return code is non-zero or if standard error is non-empty. 71# Die if return code is non-zero or if standard error is non-empty.
64sub common_exec { 72sub common_exec {
65 # pretty_arg: 73 # pretty_arg:
@@ -74,6 +82,10 @@ sub common_exec {
74 return $_; 82 return $_;
75 } 83 }
76 84
85 my $refopts = pop if ref($_[-1]) eq "HASH";
86 my %opts;
87 %opts = %$refopts if defined($refopts);
88
77 my $cmd = join(" ", map { pretty_arg $_ } @_); 89 my $cmd = join(" ", map { pretty_arg $_ } @_);
78 my $commandnum = 1; 90 my $commandnum = 1;
79 91
@@ -87,12 +99,15 @@ sub common_exec {
87 99
88 common_log("$cmd\nstdout=$stdout\nstderr=$stderr", "\$"); 100 common_log("$cmd\nstdout=$stdout\nstderr=$stderr", "\$");
89 101
90 # Save I/O, setup I/O for subprocess 102 # Setup I/O for subprocess
91 open OLD_STDOUT, ">&STDOUT";
92 open OLD_STDERR, ">&STDERR";
93 open OLD_STDIN, "<&STDIN";
94 open STDOUT, ">$stdout"; 103 open STDOUT, ">$stdout";
95 open STDERR, ">$stderr"; 104 open STDERR, ">$stderr";
105
106 if(defined($opts{"stderr_to_stdout"})) {
107 close STDERR;
108 open STDERR, ">&STDOUT";
109 }
110
96 close STDIN; 111 close STDIN;
97 112
98 # Exec suprocess 113 # Exec suprocess
@@ -102,10 +117,7 @@ sub common_exec {
102 open STDIN, "<&OLD_STDIN"; 117 open STDIN, "<&OLD_STDIN";
103 open STDOUT, ">&OLD_STDOUT"; 118 open STDOUT, ">&OLD_STDOUT";
104 open STDERR, ">&OLD_STDERR"; 119 open STDERR, ">&OLD_STDERR";
105 close OLD_STDOUT; 120
106 close OLD_STDERR;
107 close OLD_STDIN;
108
109 common_log("$?", "?"); 121 common_log("$?", "?");
110 common_die("\"$cmd\" failed (non-zero exit code)") if($? != 0); 122 common_die("\"$cmd\" failed (non-zero exit code)") if($? != 0);
111 common_die("\"$cmd\" failed (non-empty error output)") if(-s $stderr); 123 common_die("\"$cmd\" failed (non-empty error output)") if(-s $stderr);
@@ -115,15 +127,16 @@ sub common_exec {
115 return $fd; 127 return $fd;
116} 128}
117 129
118# scilab_exe: 130# common_exec_scilab(script):
119# Get Scilab executable name (scilab on linux, scilex on Windows) 131# Execute scilab script
120sub scilab_exe { 132sub common_exec_scilab {
121 if($^O =~ /mswin/i) { 133 my $script = shift;
122 return "scilex"; 134 $script = "try; $script; catch; write(%io(2), lasterror()); end; quit;";
123 } 135
124 else { 136 my $scilab = "scilex" if($^O =~ /mswin/i);
125 return "scilab"; 137 $scilab = "scilab" unless(defined($scilab));
126 } 138
139 return common_exec($scilab, "-nwni", "-nb", "-e", $script);
127} 140}
128 141
129# is_zip: 142# is_zip:
@@ -444,7 +457,8 @@ sub stage_unpack {
444 common_exec("unzip", "-o", $TOOLBOXFILE); 457 common_exec("unzip", "-o", $TOOLBOXFILE);
445 } 458 }
446 else { 459 else {
447 common_exec("tar", "-xvf", $TOOLBOXFILE); 460 common_exec("tar", "-xvf", $TOOLBOXFILE,
461 {'stderr_to_stdout' => 1});
448 } 462 }
449 463
450 common_leave_stage(); 464 common_leave_stage();
@@ -486,8 +500,6 @@ sub stage_tbdeps {
486 my @depsarray; 500 my @depsarray;
487 my (%deps, %desc); 501 my (%deps, %desc);
488 502
489 my @SCILABX = (scilab_exe, "-nwni", "-nb", "-e");
490
491 common_enter_stage("tbdeps"); 503 common_enter_stage("tbdeps");
492 504
493 # We alreay made the check, reading description should be OK 505 # We alreay made the check, reading description should be OK
@@ -511,11 +523,10 @@ sub stage_tbdeps {
511 # Install dependencies 523 # Install dependencies
512 # fixme: we always install the last version, but some packages 524 # fixme: we always install the last version, but some packages
513 # needs some versions... at most. Need to deal with that. 525 # needs some versions... at most. Need to deal with that.
514 close(common_exec(@SCILABX, "installToolbox('$_'); quit;")) 526 close(common_exec_scilab("installToolbox('$_')")) foreach(keys %deps);
515 foreach(keys %deps);
516 527
517 # Find toolboxes directory 528 # Find toolboxes directory
518 $fd = common_exec(@SCILABX, "printf('path: %s\\n', cd(atomsToolboxDirectory())); quit;"); 529 $fd = common_exec_scilab("printf('path: %s\\n', cd(atomsToolboxDirectory()))");
519 530
520 my $tbpath; 531 my $tbpath;
521 while(<$fd>) { 532 while(<$fd>) {
@@ -578,8 +589,7 @@ sub stage_build {
578 589
579 # Run build script 590 # Run build script
580 common_log("Running ccbuilder.sce"); 591 common_log("Running ccbuilder.sce");
581 my $fd = common_exec(scilab_exe, "-nb", "-nwni", "-e", 592 my $fd = common_exec_scilab("chdir('$TOOLBOXNAME'); exec('../ccbuilder.sce')");
582 "chdir('$TOOLBOXNAME'); exec('../ccbuilder.sce');");
583 593
584 # Check result 594 # Check result
585 common_log("Checking build result"); 595 common_log("Checking build result");
@@ -613,7 +623,8 @@ sub stage_pack {
613 $output .= "-bin"; 623 $output .= "-bin";
614 624
615 common_log("Making binary .tar.gz archive ($output.tar.gz)"); 625 common_log("Making binary .tar.gz archive ($output.tar.gz)");
616 common_exec("tar", "-cvf", "$output.tar.gz", map { "$TOOLBOXNAME/$_" } @files); 626 common_exec("tar", "-cvf", "$output.tar.gz", (map { "$TOOLBOXNAME/$_" } @files),
627 {"stderr_to_stdout" => 1});
617 common_log("Making binary .zip archive ($output.zip)"); 628 common_log("Making binary .zip archive ($output.zip)");
618 common_exec("zip", "-r", "$output.zip", map { "$TOOLBOXNAME/$_" } @files); 629 common_exec("zip", "-r", "$output.zip", map { "$TOOLBOXNAME/$_" } @files);
619 630
@@ -657,6 +668,9 @@ stage_pack;
657stage_cleanenv; 668stage_cleanenv;
658 669
659close LOGFILE; 670close LOGFILE;
671close OLD_STDERR;
672close OLD_STDOUT;
673close OLD_STDIN;
660 674
661# Overwrite some scilab functions to get its return value and extra infos 675# Overwrite some scilab functions to get its return value and extra infos
662__DATA__ 676__DATA__
@@ -671,5 +685,4 @@ endfunction
671 685
672exec("builder.sce"); 686exec("builder.sce");
673mprintf("\natoms_cc_builder:done\n"); 687mprintf("\natoms_cc_builder:done\n");
674quit;
675 688