From b2fa9c8271b752a5e243f40479039da0318d3548 Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Thu, 19 Jan 2023 20:16:19 +0000 Subject: iurt: Add support for DynamicBuildRequires See https://fedoraproject.org/wiki/Changes/DynamicBuildRequires --- NEWS | 2 ++ iurt | 6 ++++++ lib/Iurt/Urpmi.pm | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 1016a8f..d037983 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +- iurt: Add support for DynamicBuildRequires + 0.7.18 - ulri: Fix false positives of iurt dying on the build machine - iurt: Fix cleaning chroots (eg: when using --clean-all) diff --git a/iurt b/iurt index 2489d03..c797848 100755 --- a/iurt +++ b/iurt @@ -795,6 +795,12 @@ retry: return $srpm; } + $ok = $urpmi->install_dynamic_buildrequires(\%run, $config, $chroot_tmp, '', $luser, $spec, $srpm); + if (!$ok) { + $run{status}{$srpm} ||= 'install_deps_failure'; + return $srpm; + } + perform_command("rpm --root $chroot_tmp -qa | sort", \%run, $config, logname => "rpm_qa", diff --git a/lib/Iurt/Urpmi.pm b/lib/Iurt/Urpmi.pm index 7d079ea..0f084c9 100644 --- a/lib/Iurt/Urpmi.pm +++ b/lib/Iurt/Urpmi.pm @@ -385,13 +385,13 @@ sub install_packages { @to_install or return 1; - (my $log_dirname = $title) =~ s/.*:(.*)\.src.rpm/$1/; + (my $log_dirname = $title) =~ s/^[^:]*:?([^:]*)\.(buildreqs\.nosrc|src).rpm/$1/; my $log_spool = "$local_spool/log/$log_dirname/"; mkdir $log_spool; - my @rpm = grep { !/\.src\.rpm$/ } @to_install; + my @rpm = grep { !/src\.rpm$/ } @to_install; if ($opt->{check} && -f "$chroot_tmp/bin/rpm" @@ -553,4 +553,64 @@ sub recreate_srpm { ($ret, "$prefix$new_srpm", $spec); } +# return ("exit_code", srpm, spec) +sub install_dynamic_buildrequires { + my ($self, $run, $config, $chroot_tmp, $dir, $luser, $spec, $srpm) = @_; + my $program_name = $run->{program_name}; + my $with_flags = $run->{with_flags}; + + plog('INFO', "handling dynamic buildrequires"); + + if (`rpm -qp --requires "$chroot_tmp/home/$luser/rpmbuild/SRPMS/$srpm"` !~ /rpmlib\(DynamicBuildRequires\)/) { + plog('DEBUG', "DynamicBuildRequires not required for $srpm"); + return 1; + } + + my $nosrc = $srpm =~ s/src.rpm$/buildreqs.nosrc.rpm/r; + + while (1) { + # There is no way with perform_command to get the actual error code. + # We can however tell it that error 11 (missing BuildRequires) is ok so + # that we get an error if it fails for any other reason. + my $ret = perform_command(qq(chroot $chroot_tmp su $luser -c "rpmbuild -br $with_flags /home/$luser/rpmbuild/SPECS/$spec"), + $run, $config, + use_iurt_root_command => 1, + mail => $config->{admin}, + error => "[DYNAMIC BUILDREQUIRES] cannot create $srpm in $chroot_tmp", + debug_mail => $run->{debug}, + hash => "generatebuildrequires_$srpm", + error_ok => [11] + ); + + return 1 if $ret; + + # Unfortunately iurt_root_command hides the original error code so + # we need to find out if the file was created rather than relying on + # the command exiting with 11. + if (-f "$chroot_tmp/home/$luser/rpmbuild/SRPMS/$nosrc") { + plog("INFO: Some dynamic BuildRequires are missing"); + my @packages = ("$chroot_tmp/home/$luser/rpmbuild/SRPMS/$nosrc"); + if (!$self->install_packages( + $nosrc, + $chroot_tmp, + $run->{local_spool}, + 'dynamic_buildrequires', + "[DYNAMIC BUILDREQUIRES] installation of dynamic BuildRequires failed for $srpm on $run->{my_arch}", + {}, + @packages + )) { + plog('ERROR', "Failed to install dynamic BuildRequires."); + return 0; + } + # TODO: Have a max retry counter for safety + # Delete the file if it exists so that we know if it got created again + unlink("$chroot_tmp/home/$luser/rpmbuild/SRPMS/$nosrc"); + } else { + # This was a failure for another reason, no point retrying + plog('ERROR', "Failed to generate dynamic BuildRequires."); + return 0; + } + } +} + 1; -- cgit v1.2.1