commit b0382ccc58b9286e066bf5980f80cf041e287067
Author: Nicolas Vigier <boklm(a)torproject.org>
Date: Tue Feb 14 23:55:10 2017 +0100
Add the build_log option
---
NEWS | 2 ++
doc/rbm_cli.asc | 4 ++++
doc/rbm_config.asc | 4 ++++
lib/RBM.pm | 24 ++++++++++++++++++++++--
lib/RBM/DefaultConfig.pm | 1 +
rbm | 2 +-
6 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/NEWS b/NEWS
index 1a1789f..663a281 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+- Add the build_log option
+
- Add support for optional local configuration file rbm.local.conf
- add the git_submodule option
diff --git a/doc/rbm_cli.asc b/doc/rbm_cli.asc
index 66f6025..adb8b27 100644
--- a/doc/rbm_cli.asc
+++ b/doc/rbm_cli.asc
@@ -42,6 +42,10 @@ The following options can be set on the command line :
--output-dir=<directory>::
Set the output directory
+ --build-log=<filename>::
+ Set the file where the build logs will be written. If the value is `-`
+ (the default), the logs will be output on stdout and stderr.
+
--version=<version>::
Set the package version
diff --git a/doc/rbm_config.asc b/doc/rbm_config.asc
index e8decd9..a461b3d 100644
--- a/doc/rbm_config.asc
+++ b/doc/rbm_config.asc
@@ -140,6 +140,10 @@ output_dir::
The directory where output files (tarballs, spec files or
packages) are created. The default value is +out+.
+build_log::
+ The file where the build logs will be written. If the value is `-` (the
+ default), the logs will be output on stdout and stderr.
+
fetch::
The value should be 0 or 1, depending on whether the commits
from the remote git or hg repository should be fetched
diff --git a/lib/RBM.pm b/lib/RBM.pm
index 4b5bfe9..2248b41 100644
--- a/lib/RBM.pm
+++ b/lib/RBM.pm
@@ -884,6 +884,18 @@ sub input_files {
return \%res_getfnames if $action eq 'getfnames';
}
+sub system_log {
+ my ($log_file, @args) = @_;
+ return system(@args) if $log_file eq '-';
+ if (my $pid = fork) {
+ waitpid($pid, 0);
+ return ${^CHILD_ERROR_NATIVE};
+ }
+ exit_error "Could not open $log_file" unless open(STDOUT, '>>', $log_file);
+ open(STDERR, '>&', *STDOUT);
+ exec(@args);
+}
+
sub build_run {
my ($project, $script_name, $options) = @_;
my $old_step = $config->{step};
@@ -959,6 +971,14 @@ sub build_run {
write_file("$srcdir/$s", $build_script{$s});
chmod 0700, "$srcdir/$s";
}
+ my $build_log = project_config($project, "build_log", $options);
+ if ($build_log ne '-') {
+ $build_log = path($build_log);
+ make_path(dirname($build_log));
+ my $now = localtime;
+ write_file($build_log, {append => 1}, "Starting build: $now\n");
+ print "Build log: $build_log\n";
+ }
chdir $srcdir;
my $res;
if ($remote_tmp_src && $remote_tmp_dst) {
@@ -982,7 +1002,7 @@ sub build_run {
exec_name => $s,
exec_as_root => $scripts_root{$s},
});
- if (run_script($project, $cmd, sub { system(@_) }) != 0) {
+ if (run_script($project, $cmd, sub { system_log($build_log, @_) }) != 0) {
$error = "Error running $script_name";
if (project_config($project, 'debug', $options)) {
print STDERR $error, "\nOpening debug shell\n";
@@ -1019,7 +1039,7 @@ sub build_run {
foreach my $s (@scripts) {
my $cmd = $scripts_root{$s} ? project_config($project, 'suexec',
{ suexec_cmd => "$srcdir/$s" }) : "$srcdir/$s";
- if (system($cmd) != 0) {
+ if (system_log($build_log, $cmd) != 0) {
$error = "Error running $script_name";
if (project_config($project, 'debug', $options)) {
print STDERR $error, "\nOpening debug shell\n";
diff --git a/lib/RBM/DefaultConfig.pm b/lib/RBM/DefaultConfig.pm
index aad9451..ec03ff0 100644
--- a/lib/RBM/DefaultConfig.pm
+++ b/lib/RBM/DefaultConfig.pm
@@ -112,6 +112,7 @@ our %default_config = (
fetch => 'if_needed',
rpmspec => '[% SET tmpl = project _ ".spec"; INCLUDE $tmpl -%]',
build => '[% INCLUDE build -%]',
+ build_log => '-',
notmpl => [ qw(projects_dir) ],
describe => \&git_describe,
abbrev_lenght => '12',
diff --git a/rbm b/rbm
index c618ada..050cff5 100755
--- a/rbm
+++ b/rbm
@@ -95,7 +95,7 @@ sub set_options {
gpg-keyring=s gpg-keyring-dir=s gpg-args=s gpg-bin=s
sysconf-file=s debsign-keyid=s use-pbuilder!
step=s target=s@ publish-src-dir=s debug! hg-clone-dir=s
- hg-hash=s localconf-file=s);
+ hg-hash=s localconf-file=s build-log=s);
my %val;
Getopt::Long::GetOptionsFromArray(\@_, \%val, @options) || exit 1;
foreach my $k (keys %val) {