Clean up exit/die/return mess for exe*()

The exe*() functions were inconsistent of where they exited. So, make
sure that all exe*() confesses upon errors, and let the calling
functions use eval{} to avoid the exception when needed.

Change-Id: Ia6e4edb22a83ac32d924b792e8a2eea657a6a149
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
This commit is contained in:
Marius Storm-Olsen
2012-04-08 22:25:26 -05:00
committed by Qt by Nokia
parent 9fa0f5ddf4
commit 8ddc280393

29
build
View File

@@ -155,11 +155,10 @@ sub exe
print "+ @cmd\n" unless ($self->{quiet});
# dry-run > 1 means run sub-processes with dry-run too
if ($self->{'dry-run'} != 1) {
confess "@cmd exited with status $CHILD_ERROR" if (system(@cmd) != 0);
}
return 0;
}
sub dropPrivileges()
@@ -189,29 +188,33 @@ sub dropPrivileges()
sub exeHighPriv()
{
my ($self, @cmd) = @_;
return $self->exe(@cmd);
# confesses upon system() failure
$self->exe(@cmd);
}
sub exeLowPriv()
{
my ($self, @cmd) = @_;
if ("$Config{osname}" =~ /mswin/i) {
# Just like exeHighPriv for now
return $self->exe(@cmd);
} else {
if ("$Config{osname}" !~ /mswin/i) {
my $ret;
my $pid = fork();
die "Couldn't fork" unless defined $pid;
if ($pid == 0) {
$self->dropPrivileges;
$self->exe(@cmd);
exit 0;
# just exit on error, exception propagated below
eval { $self->exe(@cmd); };
exit $?;
} else {
waitpid($pid, 0);
return $?;
# propagate exception upon system() failure in fork
die if ($? != 0);
return;
}
}
# Just like exeHighPriv for now, and confesses upon failure
$self->exe(@cmd);
}
sub which {
@@ -422,15 +425,15 @@ sub build_project
my $install_command = $self->{'instcmds'}->{$module};
if (!defined $build_command) {
if (!-e "$module/Makefile") {
$self->exeLowPriv("cd $module && qmake -r") && die "'cd $module && qmake -r' failed: $?";
$self->exeLowPriv("cd $module && qmake -r");
}
$build_command = "$self->{MAKE} $self->{MAKEOPTS}";
}
$self->exeLowPriv("cd $module && $build_command") && die "'cd $module && $build_command' failed: $?";
$self->exeLowPriv("cd $module && $build_command");
$install_command = "$self->{MAKE} install" if (!defined $install_command);
### TODO: Should be fixed after the alpha
unless ("$Config{osname}" =~ /(dar|ms)win/i) {
$self->exeHighPriv("cd $module && $install_command") && die "'cd $module && $install_command failed: $?";
$self->exeHighPriv("cd $module && $install_command");
}
$self->mark_as_finished($module);
return 0;