From ef77eae1e3c3ff7a7463c5532a318132e27ccf7a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Thu, 16 Jan 2014 13:54:46 +0100 Subject: [PATCH] Allow to pass prepared mock environment to F:R:Package::rebuild Sharing mock between each rebuild allows to reuse mock cache which prevents from costly downaloading and building minimal build root. --- lib/Fedora/Rebuild/Package.pm | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/Fedora/Rebuild/Package.pm b/lib/Fedora/Rebuild/Package.pm index fed9778..84fc2a5 100644 --- a/lib/Fedora/Rebuild/Package.pm +++ b/lib/Fedora/Rebuild/Package.pm @@ -847,10 +847,12 @@ sub submitbuild { # "koji" wait for package build in Koji, # "local" build locally using fedpkg. # "mock" build locally using mock. +# Second argument is Mock object to use instead of fresh one (value undef). +# (This is safe only in single-threaded run. This is limitation of mock.) # Requires `clone'. Sould be called after `update' or `submitbuild'. # Return true on success. sub build { - my ($self, $build_config) = @_; + my ($self, $build_config, $mock) = @_; my $lock = Fedora::Rebuild::Package::StateLock->new(package => $self, state => 'build'); if ($lock->is_done) { return 1; } @@ -895,26 +897,32 @@ sub build { } my ($mock_config_dir, $mock_config_root); eval { - ($mock_config_dir, $mock_config_root) = - Fedora::Rebuild::Mock->new( + if (!defined $mock) { + $mock = Fedora::Rebuild::Mock->new( architecture => $build_config->architecture(), repositories => $build_config->repositories(), install_group => $build_config->mock_install_group(), - )->make_configuration; + ); + $mock->make_configuration; + } + $mock_config_dir = $mock->config_dir; + $mock_config_root = $mock->config_root; }; if ($@) { $lock->log("Could not configure mock: $@\n"); File::Path::remove_tree($mock_config_dir); return $lock->mark_failed; } - if (!$lock->do(undef, 'mock', '--resultdir', $self->mockdir, + my $success = $lock->do(undef, 'mock', '--resultdir', $self->mockdir, '--configdir', $mock_config_dir, '--root', $mock_config_root, - '--rebuild', $srpm_name)) { - $lock->log("Could not build `" . $nevra . "' in mock.\n"); + '--rebuild', $srpm_name); + if (defined $mock && !$mock->shared) { File::Path::remove_tree($mock_config_dir); + } + if (!$success) { + $lock->log("Could not build `" . $nevra . "' in mock.\n"); return $lock->mark_failed; } - File::Path::remove_tree($mock_config_dir); } else { $lock->log("Could not build `" . $nevra . "' because of unknown building mode `" . $build_config->mode() . @@ -1075,8 +1083,10 @@ sub get_binarydependencies { # "local" build locally without pushing commits to server, # "mock" build in mock without pushing commits to server. # Second argument is anonymous clone boolean. +# Third argument is Mock object to use instead of fresh one (value undef). +# (This is safe only in single-threaded run. This is limitation of mock.) sub rebuild { - my ($self, $build_config, $anonymous) = @_; + my ($self, $build_config, $anonymous, $mock) = @_; my $ok; print "Rebuilding `" . $self->name . "'...\n"; @@ -1084,7 +1094,7 @@ sub rebuild { $ok = $self->clone($anonymous); $ok = $self->update($build_config->mode()) if $ok; $ok = $self->submitbuild if ($ok and $build_config->mode() eq 'koji'); - $ok = $self->build($build_config) if $ok; + $ok = $self->build($build_config, $mock) if $ok; $ok = $self->binaryrpm($build_config) if $ok; $ok = $self->get_binaryprovides if $ok; $ok = $self->get_binaryrequires if $ok; -- 2.11.4.GIT