From f8f77db1d6cd1434b1cada62d2954b4561ef12b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 25 Sep 2026 02:24:42 -0300 Subject: [PATCH] refactor(xcat-dep): share the mock config resolver mockbuild-all.pl finds the mock config by its file in /etc/mock, and knows that /etc/os-release says almalinux where mock names the file alma. Move that resolver into MockBuildUtils, with the config directory as an optional argument, so a per-package builder can use it. The behavior of mockbuild-all.pl does not change. --- MockBuildUtils.pm | 28 +++++++++++++++++++++++++++- mockbuild-all.pl | 24 +----------------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/MockBuildUtils.pm b/MockBuildUtils.pm index ff62ed0..5e4a1d9 100644 --- a/MockBuildUtils.pm +++ b/MockBuildUtils.pm @@ -23,7 +23,7 @@ our @EXPORT_OK = qw( parse_evr evr_cmp evr_constraint_ok parse_pin rpmkeys_checksig_problem rpm_version rpm_release rpm_sigmd5 rpm_is_signed restamp_release_line cross_copy_genesis finalize_xcat_dep bump_dep_release_suffix - build_mock_uniqueext rpm_in_cell + build_mock_uniqueext rpm_in_cell resolve_mock_cfg ); # install_deps_packages($os_id): the host packages mockbuild-all.pl needs to run at all, for the @@ -723,4 +723,30 @@ sub build_mock_uniqueext { return sprintf("mba-%02d-%s-%s", $idx, $run_part, $label_part); } +# resolve_mock_cfg($os_id, $rel, $arch[, $cfg_dir]): the mock config for EL release $rel on this +# host, +epel--. /etc/os-release says 'almalinux' where mock-core-configs names the +# file 'alma', so the short form is tried too. $cfg_dir defaults to /etc/mock. +sub resolve_mock_cfg { + my ($os_id, $rel, $arch, $cfg_dir) = @_; + $cfg_dir //= '/etc/mock'; + my %short_forms = ( + almalinux => 'alma', + 'centos-stream' => 'centos-stream', + rocky => 'rocky', + ); + # Resolve by CONFIG-FILE existence, not by running `mock --print-root-path`: the latter can fail + # transiently (bootstrap chroot setup, a concurrent mock holding a lock) and made el10 flakily + # "resolve" to the long form that has no .cfg. Checking /.cfg is deterministic. + for my $id ($os_id, (exists $short_forms{$os_id} ? ($short_forms{$os_id}) : ())) { + my $candidate = "${id}+epel-${rel}-${arch}"; + if (-f "$cfg_dir/${candidate}.cfg") { + print "Mock config resolved: $candidate\n" if $id ne $os_id; + return $candidate; + } + } + my $short = $short_forms{$os_id} // $os_id; + die "Could not find mock config for ${os_id}+epel-${rel}-${arch} " + . "(tried $cfg_dir/${os_id}+epel-${rel}-${arch}.cfg and $cfg_dir/${short}+epel-${rel}-${arch}.cfg)\n"; +} + 1; diff --git a/mockbuild-all.pl b/mockbuild-all.pl index 3f3efad..7efb057 100755 --- a/mockbuild-all.pl +++ b/mockbuild-all.pl @@ -15,7 +15,7 @@ use Parallel::ForkManager; use POSIX qw(strftime); use FindBin qw($RealBin); use lib $RealBin, "$RealBin/lib"; -use MockBuildUtils qw(sh_quote print_step version_matches required_pkgs rpm_in_cell +use MockBuildUtils qw(sh_quote print_step version_matches required_pkgs rpm_in_cell resolve_mock_cfg carry_over_rpms rpm_name rpm_arch rpm_source_rpm rpm_digests_ok install_deps_packages install_deps_command missing_perl_modules read_manifest verify_repo_packages verify_repo_signature verify_rpm_signatures @@ -2129,28 +2129,6 @@ sub collect_srpms { return ($copied, $skipped_non_src, $missing_roots); } -sub resolve_mock_cfg { - my ($os_id, $rel, $arch) = @_; - my %short_forms = ( - almalinux => 'alma', - 'centos-stream' => 'centos-stream', - rocky => 'rocky', - ); - # Resolve by CONFIG-FILE existence, not by running `mock --print-root-path`: the latter can fail - # transiently (bootstrap chroot setup, a concurrent mock holding a lock) and made el10 flakily - # "resolve" to the long form that has no .cfg. Checking /etc/mock/.cfg is deterministic. - for my $id ($os_id, (exists $short_forms{$os_id} ? ($short_forms{$os_id}) : ())) { - my $candidate = "${id}+epel-${rel}-${arch}"; - if (-f "/etc/mock/${candidate}.cfg") { - print "Mock config resolved: $candidate\n" if $id ne $os_id; - return $candidate; - } - } - my $short = $short_forms{$os_id} // $os_id; - die "Could not find mock config for ${os_id}+epel-${rel}-${arch} " - . "(tried /etc/mock/${os_id}+epel-${rel}-${arch}.cfg and /etc/mock/${short}+epel-${rel}-${arch}.cfg)\n"; -} - sub resolve_xcat_source { my ($requested, $root) = @_; # Prefer the sibling ../xcat-core (the real layout: source/xcat-core beside source/xcat-dep)