Skip to content

Commit

Permalink
pbuild: add singlejob mode
Browse files Browse the repository at this point in the history
shows build output directly and gives --shell support
  • Loading branch information
adrianschroeter committed Apr 20, 2021
1 parent 37a1466 commit 53e6331
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
18 changes: 11 additions & 7 deletions PBuild/Job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ use PBuild::RepoMgr;
# Fork and exec the build tool
#
sub forkjob {
my ($args) = @_;
my ($opts, $args) = @_;
my $pid = PBuild::Util::xfork();
return $pid if $pid;
open(STDIN, '<', '/dev/null');
open(STDOUT, '>', '/dev/null');
open(STDERR, '>&STDOUT');
unless ($opts->{'singlejob'}) {
open(STDIN, '<', '/dev/null');
open(STDOUT, '>', '/dev/null');
open(STDERR, '>&STDOUT');
};
exec(@$args);
die("$args->[0]: $!\n");
}
Expand Down Expand Up @@ -75,7 +77,7 @@ sub updatelines {
# Wait for one or more build jobs to finish
#
sub waitjob {
my (@jobs) = @_;
my ($opts, @jobs) = @_;
local $| = 1;
my $oldmsg;
while (1) {
Expand All @@ -99,7 +101,7 @@ sub waitjob {
return $job;
}
$msg .= ' ]';
print "\r$msg" if !$oldmsg || $oldmsg ne $msg;
print "\r$msg" if !$opts->{'singlejob'} && (!$oldmsg || $oldmsg ne $msg);
$oldmsg = $msg;
}
}
Expand Down Expand Up @@ -277,6 +279,8 @@ sub createjob {
}

push @args, '--clean' unless $opts->{'noclean'};
push @args, '--shell' if $opts->{'shell'};
push @args, '--shell-after-fail' if $opts->{'shell-after-fail'};
push @args, '--skip-bundle';
push @args, '--changelog';
#push @args, '--oldpackages', $oldpkgdir if $oldpkgdir && -d $oldpkgdir;
Expand Down Expand Up @@ -315,7 +319,7 @@ sub createjob {
unlink("$buildroot/.build.log");
#print "building $p->{'pkg'}/$p->{'recipe'}\n";

my $pid = forkjob(\@args);
my $pid = forkjob($opts, \@args);
return { 'name' => $jobname, 'nbuilders' => $nbuilders, 'pid' => $pid, 'buildroot' => $buildroot, 'vm_type' => $vm, 'pdata' => $p, 'logfile' => "$buildroot/.build.log", 'logfile_lines' => 0, 'starttime' => time() };
}

Expand Down
9 changes: 9 additions & 0 deletions PBuild/Options.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ my %known_options = (
'no-clean' => 'noclean',
'nochecks' => 'nochecks',
'no-checks' => 'nochecks',
'singlejob' => 'singlejob',
'shell' => 'shell',
'shell-after-fail' => 'shell-after-fail',
'arch' => 'arch:',
'hostarch' => 'hostarch:',
'host-arch' => 'hostarch:',
Expand Down Expand Up @@ -176,6 +179,12 @@ sub parse_options {
# default to KVM for builds as non-root user
$opts{'vm-type'} = 'kvm' if !$opts{'vm-type'} && $< > 0;

if ($opts{'shell'} || $opts{'shell-after-fail'}) {
$opts{'noclean'} = 1;
$opts{'singlejob'} = 1;
$opts{'buildjobs'} = 1;
}

return (\%opts, @back);
}

Expand Down
2 changes: 1 addition & 1 deletion pbuild
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ while (1) {
last unless @building;

# wait for one job to finish
my $job = PBuild::Job::waitjob(@building);
my $job = PBuild::Job::waitjob($opts, @building);
for (@builders) {
delete $_->{'job'} if $_->{'job'} && $_->{'job'} == $job;
}
Expand Down

0 comments on commit 53e6331

Please sign in to comment.