diff options
Diffstat (limited to 'lib/Iurt/Urpmi.pm')
-rw-r--r-- | lib/Iurt/Urpmi.pm | 159 |
1 files changed, 107 insertions, 52 deletions
diff --git a/lib/Iurt/Urpmi.pm b/lib/Iurt/Urpmi.pm index 7ac6a74..53d0756 100644 --- a/lib/Iurt/Urpmi.pm +++ b/lib/Iurt/Urpmi.pm @@ -5,6 +5,7 @@ use RPM4::Header; use File::Basename; use File::NCopy qw(copy); use MDV::Distribconf::Build; +use MDK::Common qw(cat_); use Iurt::Chroot qw(add_local_user create_temp_chroot); use Iurt::Process qw(perform_command clean_process sudo); use Iurt::Config qw(get_package_prefix); @@ -21,31 +22,15 @@ sub new { my $config = $self->{config}; my $run = $self->{run}; - if ($run->{chrooted_urpmi}) { - $run->{chrooted_media} = $run->{chrooted_urpmi}{rooted_media} . - "/$run->{distro}/$run->{my_arch}"; - - # Now squash all slashes that don't follow colon - $run->{chrooted_media} =~ s|(?<!:)/+|/|g; - - plog('DEBUG', "installation media: $run->{chrooted_media}"); - } - $self->{use__urpmi_root} = !urpm::is_local_url($config->{repository}); $self->{distrib_url} = "$config->{repository}/$run->{distro}/$run->{my_arch}"; $self; } -sub set_command__urpmi_root { +sub set_command { my ($self, $chroot_tmp) = @_; - $self->{use_iurt_root_command} = 1; $self->{urpmi_command} = "urpmi $self->{urpmi_options} --urpmi-root $chroot_tmp"; } -sub set_command__use_distrib { - my ($self, $chroot_tmp) = @_; - $self->{use_iurt_root_command} = 1; - $self->{urpmi_command} = "urpmi $self->{urpmi_options} --use-distrib $self->{distrib_url} --root $chroot_tmp"; -} sub set_local_media { my ($self, $local_media) = @_; @@ -65,10 +50,7 @@ sub urpmi_command { my $run = $self->{run}; my $local_media = $self->{local_media}; - if ($run->{chrooted_urpmi}) { - # FIXME chrooted_urpmi should always use urpmi_root and not support local media - $self->{use__urpmi_root} ? &set_command__urpmi_root : &set_command__use_distrib; - + &set_command; # Here should be added only the needed media for the given package # main/release -> main/release # main/testing -> main/release main/testing @@ -82,18 +64,17 @@ sub urpmi_command { my $m_name = $m; $m_name =~ s,/,_,g; if (!add_media($self, $chroot_tmp, $m_name, - "$m_name $run->{chrooted_media}/media/$m")) { + "$m_name $self->{distrib_url}/media/$m")) { $run->{chrooted_urpmi} = 0; - plog('ERROR', "Failed to add media $m_name. Disabling chrooted_urpmi."); + plog('ERROR', "Failed to add media $m_name."); return; } } } else { # FIXME Do not hardcode Core - if (!add_media($self, $chroot_tmp, 'Core', "--distrib $run->{chrooted_media}")) { - if (!add_media($self, $chroot_tmp, 'Core', "--wget --distrib $run->{chrooted_media}")) { - $run->{chrooted_urpmi} = 0; - plog('ERROR', "Failed to add media $run->{chrooted_media}. Disabling chrooted_urpmi."); + if (!add_media($self, $chroot_tmp, 'Core', "--distrib $self->{distrib_url}")) { + if (!add_media($self, $chroot_tmp, 'Core', "--wget --distrib $self->{distrib_url}")) { + plog('ERROR', "Failed to add media $self->{distrib_url}."); return; } } @@ -149,9 +130,6 @@ sub urpmi_command { } return 1; - } else { - &set_command__use_distrib; - } } sub check_media_added { @@ -188,12 +166,9 @@ sub add_media { my $run = $self->{run}; my $config = $self->{config}; - plog("add chroot media: $run->{chrooted_media}"); + plog("add chroot media: $self->{distrib_url}"); - my $cmd = "chroot $chroot urpmi.addmedia $media"; - if ($run->{chrooted_urpmi}) { - $cmd = "urpmi-addmedia -v --urpmi-root $chroot $media"; - } + my $cmd = "urpmi-addmedia -v --urpmi-root $chroot $media"; perform_command($cmd, $run, $config, mail => $config->{admin}, @@ -208,6 +183,24 @@ sub add_media { 1; } +sub update { + my ($self, $chroot) = @_; + my $run = $self->{run}; + my $config = $self->{config}; + + plog('INFO', "updating packages in $chroot"); + + my $cmd = "urpmi --urpmi-root $chroot --auto-update --auto"; + perform_command($cmd, + $run, $config, + mail => $config->{admin}, + retry => 2, + use_iurt_root_command => 1, + debug_mail => $run->{debug}) + or return; + 1; +} + sub get_local_provides { my ($self) = @_; my $run = $self->{run}; @@ -341,8 +334,6 @@ sub _install_callback { # it seems the is needed urpmi error is due to something else (likely a # database corruption error). # my @missing_deps = $output =~ /(?:(\S+) is needed by )|(?:\(due to unsatisfied ([^[ ]*)(?: (.*)|\[(.*)\])?\))/g; - # - my @missing_deps = $output =~ /([^ \n]+) \(due to unsatisfied ([^[ \n]*)(?: ([^\n]*)|\[([^\n]*)\])?\)/g; # <mrl> 20071106 FIXME: This should not be needed anymore @@ -392,13 +383,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" @@ -415,7 +406,7 @@ sub install_packages { if (!perform_command( join(' ', $self->{urpmi_command}, @options, @to_install), $run, $config, - use_iurt_root_command => $self->{use_iurt_root_command}, + use_iurt_root_command => 1, error => $error, logname => $log, hash => "${log}_$title", @@ -452,16 +443,16 @@ sub install_packages { $ok; } -sub clean_urpmi_process { - my ($self) = @_; - my $run = $self->{run}; - my $program_name = $run->{program_name}; - if (!$run->{chrooted_urpmi}) { - my $match = $self->{urpmi_command} or return; - if (!clean_process($match)) { - die "FATAL $program_name: Could not have urpmi working !"; - } +sub get_srpm_name { + my ($run, $config, $chroot_tmp, $srpm, $luser, $spec) = @_; + if (!perform_command(qq(chroot $chroot_tmp su $luser -c "rpmspec -q --qf %{NVR}.src.rpm --srpm /home/$luser/rpmbuild/SPECS/$spec > /home/$luser/rpmbuild/SPECS/$spec.srpm_name"), + $run, $config, + use_iurt_root_command => 1, + hash => "identify_$srpm")) { + plog("ERROR: failed to get the name of the generated src.rpm"); + return; } + return cat_("$chroot_tmp/home/$luser/rpmbuild/SPECS/$spec.srpm_name"); } # return ("exit_code", srpm, spec) @@ -518,7 +509,7 @@ sub recreate_srpm { my $filelist = `rpm -qlp $oldsrpm`; my ($name) = $srpm =~ /(?:.*:)?(.*)-[^-]+-[^-]+\.src\.rpm$/; foreach my $file (split "\n", $filelist) { - if ($file =~ /(.*)\.spec/) { + if ($file =~ /(.*)\.spec$/) { if (!$spec) { $spec = $file; } elsif ($1 eq $name) { @@ -545,8 +536,12 @@ sub recreate_srpm { # return 0 unless $ret; - my $file = (glob "$chroot_tmp/home/$luser/rpmbuild/SRPMS/$name-*.src.rpm")[0]; - my ($new_srpm) = basename($file); + my $new_srpm = get_srpm_name($run, $config, $chroot_tmp, $srpm, $luser, $spec); + if (!$new_srpm) { + plog("ERROR: failed to get the name of the generated src.rpm"); + return; + } + my $file = "$chroot_tmp/home/$luser/rpmbuild/SRPMS/$new_srpm"; my $prefix = get_package_prefix($srpm); my $newfile = "$chroot_tmp/home/$luser/rpmbuild/SRPMS/$prefix$new_srpm"; if (-f $file && $newfile ne $file) { @@ -561,4 +556,64 @@ sub recreate_srpm { ($ret, "$prefix$new_srpm", $spec); } +sub install_dynamic_buildrequires { + my ($self, $run, $config, $chroot_tmp, $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 $new_srpm = get_srpm_name($run, $config, $chroot_tmp, $srpm, $luser, $spec); + if (!$new_srpm) { + plog("ERROR: failed to get the name of the generated src.rpm"); + return; + } + my $nosrc = $new_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, + hash => "generatebuildrequires_$srpm" + ); + 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( + $srpm, + $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."); + $run->{status}{$srpm} = 'build_failure'; + return 0; + } + } +} + 1; |