Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit Early for Several Commands When A Child Process Fails #4

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion autobuild.pl
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,16 @@ (\%)
my $LINE_FROM = $command->{LINE_FROM};
my $LINE_TO = $command->{LINE_FROM};
my $args = $command->{ARGS};
my $required = $command->{REQUIRED};

if (!defined($required)) {
if (exists($command_table{$NAME}->{required_by_default})) {
$required = $command_table{$NAME}->{required_by_default};
}
else {
$required = 0;
}
}

my $CMD = "Executing \"$NAME\" line";
if (!defined $LINE_TO || $LINE_FROM == $LINE_TO) {
Expand Down Expand Up @@ -883,7 +893,7 @@ (\%)
if (defined ($failure)) {
print STDERR "ERROR: While $CMD $CMD2:\n" if ($verbose <= 1);
print STDERR " The command failed";
if ($failure eq 'fatal') {
if ($required || $failure eq 'fatal') {
$status = 1;
if (!$keep_going) {
print STDERR ", exiting.\n";
Expand Down
17 changes: 7 additions & 10 deletions command/anonymous_shell.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use Cwd;
use FileHandle;
use File::Path;

use common::utility;

###############################################################################
# Constructor

Expand Down Expand Up @@ -54,20 +56,15 @@ sub Run ($)
$root = $1;
}

my $current_dir = getcwd ();

if (!chdir $root) {
print STDERR __FILE__, ": Cannot change to $root\n";
return 0;
}
my $cd = ChangeDir->new({dir => $root});
return {'failure' => 'fatal'} unless ($cd);

print "Running: ${options}\n";

system ($options);

chdir $current_dir;
my $result = {};
utility::run_command ($options, $result);

return 1;
return $result;
}

##############################################################################
Expand Down
7 changes: 5 additions & 2 deletions command/auto_run_tests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use Cwd;
use FileHandle;
use File::Path;

use common::utility;

###############################################################################
# Constructor

Expand Down Expand Up @@ -178,9 +180,10 @@ sub Run ($)
print "Running: $command\n";
}

system ($command);
my $result = {};
utility::run_command ($command, $result);
chdir $current_dir;
return 1;
return $result;
}

##############################################################################
Expand Down
138 changes: 71 additions & 67 deletions command/check_compiler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ use warnings;

use Cwd;

use common::utility;

###############################################################################
# Constructor

sub new
{
my $proto = shift;
my $class = ref ($proto) || $proto;
my $self = {};
my $self = {
'required_by_default' => 1,
};

bless ($self, $class);
return $self;
Expand Down Expand Up @@ -44,94 +48,94 @@ sub Run ($)

print "================ Compiler version ================\n";

if($compiler =~ m/^(\w*-)*(gcc|g\+\+|g\+\+-?[0-9]|ccsimpc|ccpentium|ccppc|c\+\+ppc|c\+\+pentium)/ || $compiler =~ m/^clang(\+\+)?(-[0-9\.]+)?/){
system($compiler." -v 2>&1");
if($compiler =~ m/^(\w*-)*(gcc|g\+\+|g\+\+-?[0-9])/ || $compiler =~ m/^clang(\+\+)?(-[0-9\.]+)?/){
my $linker = `$compiler -print-prog-name=ld`;
chomp $linker;
if($linker =~ m/ld$/){
system($linker." -v 2>&1");
}
elsif($linker =~ m/ccs/){
system($linker." -V 2>&1");
}
}
}
elsif(lc $compiler =~ m/^(sun_cc|studio|suncc)/) {
system("CC -V");
}
elsif(lc $compiler eq "mingwcygwin"){
system("g++ -v -mno-cygwin");
}
elsif(lc $compiler eq "bcc32"){
system("bcc32 --version");
if ($compiler =~ m/^(\w*-)*(gcc|g\+\+|clang|ccsimpc|(cc|c\+\+)(pentium|ppc))/) {
if (!utility::run_command ("$compiler -v 2>&1")) {
return 0;
}
if ($compiler =~ /^(\w*-)*(gcc|g\+\+|clang)/) {
my $linker = `$compiler -print-prog-name=ld`;
chomp $linker;
if ($linker =~ m/ld$/) {
return utility::run_command ($linker." -v 2>&1");
}
elsif ($linker =~ m/ccs/) {
return utility::run_command ($linker." -V 2>&1");
}
else {
print STDERR __FILE__, ": ERROR: Unexpected Linker: $linker\n";
}
}
}
elsif(lc $compiler eq "bcc32c"){
system("bcc32c --version");
elsif (lc $compiler =~ m/^(sun_cc|studio|suncc)/) {
return utility::run_command ("CC -V");
}
elsif(lc $compiler eq "bcc64"){
system("bcc64 --version");
elsif (lc $compiler eq "mingwcygwin") {
return utility::run_command ("g++ -v -mno-cygwin");
}
elsif(lc $compiler eq "bccx"){
system("bccx --version");
elsif (lc $compiler =~ m/^(bcc(.*))$/) {
return utility::run_command ("$1 --version");
}
elsif(lc $compiler eq "kylix"){
system("bc++ -V");
elsif (lc $compiler eq "kylix") {
return utility::run_command ("bc++ -V");
}
elsif($compiler =~ m/^(dcc|dplus)/){
system($compiler . " -V");
elsif ($compiler =~ m/^(dcc|dplus)/) {
return utility::run_command ($compiler . " -V");
}
elsif(lc $compiler eq "dm"){
system("scppn");
elsif (lc $compiler eq "dm") {
return utility::run_command ("scppn");
}
elsif(lc $compiler =~ m/^(msvc|vc|cl)/){
system("cl");
elsif (lc $compiler =~ m/^(msvc|vc|cl)/) {
return utility::run_command ("cl");
}
elsif(lc $compiler eq "deccxx"){
system("cxx/VERSION");
elsif (lc $compiler eq "deccxx") {
return utility::run_command ("cxx/VERSION");
}
elsif(lc $compiler eq "cxx"){
system("cxx -V");
elsif (lc $compiler eq "cxx") {
return utility::run_command ("cxx -V");
}
elsif(lc $compiler eq "acc"){
system("aCC -V");
elsif (lc $compiler eq "acc") {
return utility::run_command ("aCC -V");
}
elsif(lc $compiler eq "pgcc"){
system("pgCC -V");
elsif (lc $compiler eq "pgcc") {
return utility::run_command ("pgCC -V");
}
elsif(lc $compiler eq "mipspro"){
system("CC -version");
elsif (lc $compiler eq "mipspro") {
return utility::run_command ("CC -version");
}
elsif(lc $compiler eq "doxygen"){
system("doxygen --version");
elsif (lc $compiler eq "doxygen") {
return utility::run_command ("doxygen --version");
}
elsif($compiler =~ m/^(ecc|icc|icpc)/){
system($compiler." -V 2>&1");
elsif ($compiler =~ m/^(ecc|icc|icpc)/) {
return utility::run_command ("$compiler -V 2>&1");
}
elsif(lc $compiler eq "icl"){
system("icl");
elsif (lc $compiler eq "icl") {
return utility::run_command ("icl");
}
elsif($compiler =~ m/^(ibmcxx)/i ){
if(-x "/usr/bin/lslpp"){
system("/usr/bin/lslpp -l ibmcxx.cmp | grep ibmcxx.cmp");
}else {
print "ERROR: Could not find /usr/bin/lslpp!!\n";
elsif ($compiler =~ m/^(ibmcxx)/i) {
if (-x "/usr/bin/lslpp") {
return utility::run_command ("/usr/bin/lslpp -l ibmcxx.cmp | grep ibmcxx.cmp");
}
else {
print STDERR __FILE__, ": " .
"ERROR: Could not find /usr/bin/lslpp!!\n";
}
}
elsif($compiler =~ m/^(vacpp)/i ){
if(-x "/usr/bin/lslpp"){
system("/usr/bin/lslpp -l | grep -i \'C++ Compiler\'");
}else {
print "ERROR: Could not find /usr/bin/lslpp!!\n";
elsif ($compiler =~ m/^(vacpp)/i) {
if (-x "/usr/bin/lslpp") {
return utility::run_command ("/usr/bin/lslpp -l | grep -i \'C++ Compiler\'");
}
else {
print STDERR __FILE__, ": " .
"ERROR: Could not find /usr/bin/lslpp!!\n";
}
}
elsif(lc $compiler eq "c89"){
system("c89 -Whelp 2>&1 | tail -2");
elsif (lc $compiler eq "c89") {
return utility::run_command ("c89 -Whelp 2>&1 | tail -2");
}
else{
system($compiler);
else {
print STDERR __FILE__, ": " . "Invalid Compiler Option: $compiler\n";
}
return 1;
return 0;
}

##############################################################################
Expand Down
18 changes: 10 additions & 8 deletions command/make.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use warnings;
use Cwd;
use File::Path;

use common::utility;

###############################################################################
# Constructor

Expand Down Expand Up @@ -121,7 +123,7 @@ sub Run ($)
{
if(!chdir $dir) {
print STDERR __FILE__, ": Cannot change to $dir\n";
return 1;
return 0;
}
}

Expand All @@ -134,7 +136,8 @@ sub Run ($)

my $command;
my $pattern;
my $ret = 0;
my $success = 0;
my $result = {};

if ($options =~ s/find=([^\s]*)//) {
$pattern = $1;
Expand All @@ -146,18 +149,17 @@ sub Run ($)
next unless -f $makefile; # skip directories
$command = "$make_program -f $makefile $options";
print "Running: $command\n";
$ret = system ($command);
$success = utility::run_command ($command, $result);
}
}
else {
$options =~ s/'/"/g;
$command = "$make_program $options";
print "Running: $command\n";
$ret = system ($command);
$success = utility::run_command ($command, $result);
}

if( $ret != 0 )
{
if (!$success) {
my $working_dir = getcwd();

## If we used 'make -C' to change the directory, let's
Expand All @@ -168,15 +170,15 @@ sub Run ($)
$working_dir = "$working_dir/$1";
}

print "[BUILD ERROR detected in $working_dir]\n ";
print STDERR "[BUILD ERROR detected in $working_dir]\n ";
}

chdir $current_dir;

## Return PWD to the correct setting
$ENV{PWD} = getcwd();

return 1;
return $result;
}

##############################################################################
Expand Down
17 changes: 7 additions & 10 deletions command/shell.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use Cwd;
use FileHandle;
use File::Path;

use common::utility;

###############################################################################
# Constructor

Expand Down Expand Up @@ -56,20 +58,15 @@ sub Run ($)

main::PrintStatus ('Setup', 'Shell');

my $current_dir = getcwd ();

if (!chdir $root) {
print STDERR __FILE__, ": Cannot change to $root\n";
return 0;
}
my $cd = ChangeDir->new({dir => $root});
return {'failure' => 'fatal'} unless ($cd);

print "Running: ${options}\n";

system ($options);

chdir $current_dir;
my $result = {};
utility::run_command ($options, $result);

return 1;
return $result;
}

##############################################################################
Expand Down
Loading