diff options
author | Simon Lipp <simon.lipp@scilab.org> | 2008-07-04 14:24:05 +0000 |
---|---|---|
committer | Simon Lipp <simon.lipp@scilab.org> | 2008-07-04 14:24:05 +0000 |
commit | 74862482635d990086d4338dfbcb7665f9905306 (patch) | |
tree | 1e65bdf8bab341dbe490150b8d08daf1ed46b29d /atoms_cc/buildtoolbox.pl | |
parent | 1dbcbec6322578bc0a3b6682124c642c613381cb (diff) | |
download | scilab-74862482635d990086d4338dfbcb7665f9905306.zip scilab-74862482635d990086d4338dfbcb7665f9905306.tar.gz |
get buildtoolbox.pl hardly working on Windows
Diffstat (limited to 'atoms_cc/buildtoolbox.pl')
-rwxr-xr-x | atoms_cc/buildtoolbox.pl | 103 |
1 files changed, 68 insertions, 35 deletions
diff --git a/atoms_cc/buildtoolbox.pl b/atoms_cc/buildtoolbox.pl index 5f4ed97..791050f 100755 --- a/atoms_cc/buildtoolbox.pl +++ b/atoms_cc/buildtoolbox.pl | |||
@@ -57,12 +57,24 @@ sub common_die { | |||
57 | exit(1); | 57 | exit(1); |
58 | } | 58 | } |
59 | 59 | ||
60 | # common_exec(command): | 60 | # common_exec(command, args...): |
61 | # Execute given command, places its outputs to log files. | 61 | # Execute given command, places its outputs to log files. |
62 | # Returns a file handle on STDOUT | 62 | # Returns a file handle on STDOUT |
63 | # Die if return code is non-zero | 63 | # Die if return code is non-zero or if standard error is non-empty. |
64 | sub common_exec { | 64 | sub common_exec { |
65 | my $cmd = shift; | 65 | # pretty_arg: |
66 | # Human-readable form of the arguments array | ||
67 | sub pretty_arg { | ||
68 | my $_ = shift; | ||
69 | if(/\s|["']/) { | ||
70 | s/"/\\"/g; | ||
71 | s/^/"/; | ||
72 | s/$/"/; | ||
73 | } | ||
74 | return $_; | ||
75 | } | ||
76 | |||
77 | my $cmd = join(" ", map { pretty_arg $_ } @_); | ||
66 | my $commandnum = 1; | 78 | my $commandnum = 1; |
67 | 79 | ||
68 | # Find commandnum: log files are (stage)-1.out for first | 80 | # Find commandnum: log files are (stage)-1.out for first |
@@ -75,25 +87,45 @@ sub common_exec { | |||
75 | 87 | ||
76 | common_log("$cmd\nstdout=$stdout\nstderr=$stderr", "\$"); | 88 | common_log("$cmd\nstdout=$stdout\nstderr=$stderr", "\$"); |
77 | 89 | ||
78 | my $pid = fork(); | 90 | # Save I/O, setup I/O for subprocess |
79 | if($pid == 0) { | 91 | open OLD_STDOUT, ">&STDOUT"; |
80 | open STDOUT, ">$stdout"; | 92 | open OLD_STDERR, ">&STDERR"; |
81 | open STDERR, ">$stderr"; | 93 | open OLD_STDIN, "<&STDIN"; |
82 | close STDIN; | 94 | open STDOUT, ">$stdout"; |
83 | exec $cmd; | 95 | open STDERR, ">$stderr"; |
84 | } | 96 | close STDIN; |
85 | else { | 97 | |
86 | waitpid($pid, 0); | 98 | # Exec suprocess |
87 | common_log("$?", "?"); | 99 | system { $_[0] } @_; |
88 | common_die("\"$cmd\" failed (non-zero exit code)") if($? != 0); | 100 | |
89 | common_die("\"$cmd\" failed (non-empty error output)") if(-s $stderr); | 101 | # Restore I/O |
90 | } | 102 | open STDIN, "<&OLD_STDIN"; |
103 | open STDOUT, ">&OLD_STDOUT"; | ||
104 | open STDERR, ">&OLD_STDERR"; | ||
105 | close OLD_STDOUT; | ||
106 | close OLD_STDERR; | ||
107 | close OLD_STDIN; | ||
108 | |||
109 | common_log("$?", "?"); | ||
110 | common_die("\"$cmd\" failed (non-zero exit code)") if($? != 0); | ||
111 | common_die("\"$cmd\" failed (non-empty error output)") if(-s $stderr); | ||
91 | 112 | ||
92 | open my ($fd), $stdout; | 113 | open my ($fd), $stdout; |
93 | 114 | ||
94 | return $fd; | 115 | return $fd; |
95 | } | 116 | } |
96 | 117 | ||
118 | # scilab_exe: | ||
119 | # Get Scilab executable name (scilab on linux, scilex on Windows) | ||
120 | sub scilab_exe { | ||
121 | if($^O =~ /mswin/i) { | ||
122 | return "scilex"; | ||
123 | } | ||
124 | else { | ||
125 | return "scilab"; | ||
126 | } | ||
127 | } | ||
128 | |||
97 | # is_zip: | 129 | # is_zip: |
98 | # Return true if toolbox file extension is zip | 130 | # Return true if toolbox file extension is zip |
99 | sub is_zip { | 131 | sub is_zip { |
@@ -105,7 +137,7 @@ sub is_zip { | |||
105 | sub get_tree_from_tgz { | 137 | sub get_tree_from_tgz { |
106 | my %files; | 138 | my %files; |
107 | 139 | ||
108 | my $fd = common_exec("zcat ${TOOLBOXFILE} | tar -t"); | 140 | my $fd = common_exec("tar", "-tf", $TOOLBOXFILE); |
109 | 141 | ||
110 | while(<$fd>) { | 142 | while(<$fd>) { |
111 | chomp; | 143 | chomp; |
@@ -122,7 +154,7 @@ sub get_tree_from_zip { | |||
122 | my (%files, $line); | 154 | my (%files, $line); |
123 | 155 | ||
124 | # tail & head are here to skip header & footer | 156 | # tail & head are here to skip header & footer |
125 | my $fd = common_exec("unzip -l ${TOOLBOXFILE}"); | 157 | my $fd = common_exec("unzip", "-l", $TOOLBOXFILE); |
126 | 158 | ||
127 | while(<$fd>) { | 159 | while(<$fd>) { |
128 | if(((/^\s*-+/)...(/^\s*-+/)) && !/^\s*-+/) { # Delete header & footer | 160 | if(((/^\s*-+/)...(/^\s*-+/)) && !/^\s*-+/) { # Delete header & footer |
@@ -153,14 +185,14 @@ sub get_tree { | |||
153 | # Extract given file from the .zip archive | 185 | # Extract given file from the .zip archive |
154 | sub read_file_from_tgz { | 186 | sub read_file_from_tgz { |
155 | my $filename = shift; | 187 | my $filename = shift; |
156 | return common_exec("zcat ${TOOLBOXFILE} | tar -xO ${TOOLBOXNAME}/$filename"); | 188 | return common_exec("tar", "-xOf", $TOOLBOXFILE, "$TOOLBOXNAME/$filename"); |
157 | } | 189 | } |
158 | 190 | ||
159 | # read_file_from_tgz(filename): | 191 | # read_file_from_tgz(filename): |
160 | # Extract given file from the .tar.gz archive | 192 | # Extract given file from the .tar.gz archive |
161 | sub read_file_from_zip { | 193 | sub read_file_from_zip { |
162 | my $filename = shift; | 194 | my $filename = shift; |
163 | return common_exec("unzip -p ${TOOLBOXFILE} ${TOOLBOXNAME}/$filename"); | 195 | return common_exec("unzip", "-p", $TOOLBOXFILE, "$TOOLBOXNAME/$filename"); |
164 | } | 196 | } |
165 | 197 | ||
166 | # read_file_from_archive(filename): | 198 | # read_file_from_archive(filename): |
@@ -409,10 +441,10 @@ sub stage_unpack { | |||
409 | common_enter_stage("unpack"); | 441 | common_enter_stage("unpack"); |
410 | 442 | ||
411 | if(is_zip()) { | 443 | if(is_zip()) { |
412 | common_exec("unzip -o ${TOOLBOXFILE}"); | 444 | common_exec("unzip", "-o", $TOOLBOXFILE); |
413 | } | 445 | } |
414 | else { | 446 | else { |
415 | common_exec("zcat ${TOOLBOXFILE} | tar -vx"); | 447 | common_exec("tar", "-xvf", $TOOLBOXFILE); |
416 | } | 448 | } |
417 | 449 | ||
418 | common_leave_stage(); | 450 | common_leave_stage(); |
@@ -454,7 +486,7 @@ sub stage_tbdeps { | |||
454 | my @depsarray; | 486 | my @depsarray; |
455 | my (%deps, %desc); | 487 | my (%deps, %desc); |
456 | 488 | ||
457 | my $SCILABX = "scilab -nwni -nb -e "; | 489 | my @SCILABX = (scilab_exe, "-nwni", "-nb", "-e"); |
458 | 490 | ||
459 | common_enter_stage("tbdeps"); | 491 | common_enter_stage("tbdeps"); |
460 | 492 | ||
@@ -479,15 +511,15 @@ sub stage_tbdeps { | |||
479 | # Install dependencies | 511 | # Install dependencies |
480 | # fixme: we always install the last version, but some packages | 512 | # fixme: we always install the last version, but some packages |
481 | # needs some versions... at most. Need to deal with that. | 513 | # needs some versions... at most. Need to deal with that. |
482 | close(common_exec("$SCILABX 'installToolbox(\"$_\"); quit;'")) | 514 | close(common_exec(@SCILABX, "installToolbox('$_'); quit;")) |
483 | foreach(keys %deps); | 515 | foreach(keys %deps); |
484 | 516 | ||
485 | # Find toolboxes directory | 517 | # Find toolboxes directory |
486 | $fd = common_exec("$SCILABX 'printf(\"path: %s\\n\", cd(atomsToolboxDirectory())); quit;'"); | 518 | $fd = common_exec(@SCILABX, "printf('path: %s\\n', cd(atomsToolboxDirectory())); quit;"); |
487 | 519 | ||
488 | my $tbpath; | 520 | my $tbpath; |
489 | while(<$fd>) { | 521 | while(<$fd>) { |
490 | if(/^path: (.+)$/) { | 522 | if(/^path: (.+?)\r?$/) { |
491 | $tbpath = $1; | 523 | $tbpath = $1; |
492 | last; | 524 | last; |
493 | } | 525 | } |
@@ -537,24 +569,26 @@ sub stage_build { | |||
537 | 569 | ||
538 | # Generate ccbuilder.sce (see __DATA__ section) | 570 | # Generate ccbuilder.sce (see __DATA__ section) |
539 | common_log("Generating ccbuilder.sce"); | 571 | common_log("Generating ccbuilder.sce"); |
572 | my $ccbuilder; | ||
573 | $ccbuilder .= $_ while(<DATA>); | ||
540 | open CCBUILDER, ">ccbuilder.sce"; | 574 | open CCBUILDER, ">ccbuilder.sce"; |
541 | print CCBUILDER while(<DATA>); | 575 | print CCBUILDER $ccbuilder; |
542 | close CCBUILDER; | 576 | close CCBUILDER; |
543 | 577 | common_log("Generated ccbuilder.sce:\n$ccbuilder"); | |
544 | common_exec("cat ccbuilder.sce"); # For logging purposes only | ||
545 | 578 | ||
546 | # Run build script | 579 | # Run build script |
547 | common_log("Running ccbuilder.sce"); | 580 | common_log("Running ccbuilder.sce"); |
548 | my $fd = common_exec("cd $TOOLBOXNAME; scilab -nb -nwni -e 'exec(\"../ccbuilder.sce\");'"); | 581 | my $fd = common_exec(scilab_exe, "-nb", "-nwni", "-e", |
582 | "chdir('$TOOLBOXNAME'); exec('../ccbuilder.sce');"); | ||
549 | 583 | ||
550 | # Check result | 584 | # Check result |
551 | common_log("Checking build result"); | 585 | common_log("Checking build result"); |
552 | my $done = 0; | 586 | my $done = 0; |
553 | 587 | ||
554 | while(<$fd>) { | 588 | while(<$fd>) { |
555 | $done = 1 if(/^atoms_cc_builder:done$/); | 589 | $done = 1 if(/^atoms_cc_builder:done\r?$/); |
556 | if(/^atoms_cc_ilib_compile:\s*(.+?)\s*$/) { | 590 | if(/^atoms_cc_ilib_compile:\s*(.+?)\s*$/) { |
557 | common_die("Generated library \"$1\" is invalid") unless($1 && -x $1 && ! -d $1); | 591 | common_die("Generated library \"$1\" is invalid") unless($1 && ! -d $1 && (-x $1 || $^O =~ /win/i)); |
558 | } | 592 | } |
559 | } | 593 | } |
560 | 594 | ||
@@ -573,16 +607,15 @@ sub stage_pack { | |||
573 | DESCRIPTION macros src help sci_gateway demos tests locales includes loader.sce); | 607 | DESCRIPTION macros src help sci_gateway demos tests locales includes loader.sce); |
574 | push(@files, "etc/$TOOLBOXNAME.start"); | 608 | push(@files, "etc/$TOOLBOXNAME.start"); |
575 | push(@files, "etc/$TOOLBOXNAME.quit"); | 609 | push(@files, "etc/$TOOLBOXNAME.quit"); |
576 | my $files_str = join(" ", map { "$TOOLBOXNAME/$_" } @files); | ||
577 | 610 | ||
578 | my $output = $TOOLBOXFILE; | 611 | my $output = $TOOLBOXFILE; |
579 | $output =~ s/(\.zip|\.tar.gz)$//; | 612 | $output =~ s/(\.zip|\.tar.gz)$//; |
580 | $output .= "-bin"; | 613 | $output .= "-bin"; |
581 | 614 | ||
582 | common_log("Making binary .tar.gz archive ($output.tar.gz)"); | 615 | common_log("Making binary .tar.gz archive ($output.tar.gz)"); |
583 | common_exec("tar -czvf $output.tar.gz $files_str"); | 616 | common_exec("tar", "-cvf", "$output.tar.gz", map { "$TOOLBOXNAME/$_" } @files); |
584 | common_log("Making binary .zip archive ($output.zip)"); | 617 | common_log("Making binary .zip archive ($output.zip)"); |
585 | common_exec("zip -r $output.zip $files_str"); | 618 | common_exec("zip", "-r", "$output.zip", map { "$TOOLBOXNAME/$_" } @files); |
586 | 619 | ||
587 | common_leave_stage(); | 620 | common_leave_stage(); |
588 | } | 621 | } |