diff --git a/build-utils/lib/XCAT/BuildUtils.pm b/build-utils/lib/XCAT/BuildUtils.pm new file mode 100644 index 000000000..60ecf0877 --- /dev/null +++ b/build-utils/lib/XCAT/BuildUtils.pm @@ -0,0 +1,27 @@ +package XCAT::BuildUtils; + +use strict; +use warnings; + +use Exporter qw(import); + +our @EXPORT_OK = qw(targetarch_from_target); + +sub targetarch_from_target { + my ( $target, $default_arch ) = @_; + return $default_arch unless defined($target) && length($target); + + my @parts = map { + my $part = lc($_); + $part =~ s/^\s+|\s+$//g; + $part; + } split /-/, $target; + + for my $part (reverse @parts) { + return $part + if $part =~ /^(?:x86_64|i[3-6]86|ppc64le|ppc64|aarch64|riscv64|s390x|armv7hl)$/; + } + return $parts[-1]; +} + +1; diff --git a/buildrpms.pl b/buildrpms.pl index 8029c8def..72f95ba97 100755 --- a/buildrpms.pl +++ b/buildrpms.pl @@ -51,6 +51,8 @@ use Pod::Usage qw(pod2usage); use autodie; use autodie qw(cp); +require "$Bin/build-utils/lib/XCAT/BuildUtils.pm"; + my $SOURCES = "$ENV{HOME}/rpmbuild/SOURCES"; # Ensure the rpmbuild tree exists. buildrpms stages source tarballs into $SOURCES, but it only # runs rpmdev-setuptree in the one-time env-setup path -- so on a host where that never ran (or @@ -294,20 +296,6 @@ sub genesis_tarch_from_targetarch { return $targetarch; } -sub targetarch_from_target { - my ($target) = @_; - return $ARCH unless defined $target && length $target; - # mock configs are named --, but a site config may carry a - # suffix (e.g. rocky-10-riscv64-xcat, the forcearch config for riscv64 builds on an - # x86_64 host), so take the last part that names an architecture and only fall back - # to the last part when none does. - my @parts = map { my $p = lc $_; $p =~ s/^\s+|\s+$//g; $p } split /-/, $target; - for my $part (reverse @parts) { - return $part if $part =~ /^(?:x86_64|i[3-6]86|ppc64le|ppc64|aarch64|riscv64|s390x|armv7hl)$/; - } - return $parts[-1]; -} - # product(\@A, \@B) returns the catersian product of \@A and \@B sub product { my ($a, $b) = @_; @@ -467,7 +455,8 @@ sub buildspkgs { my $ext = $opts{mock_uniqueext} ? "-$opts{mock_uniqueext}" : ""; my $chroot = "$pkg-$target$ext"; - my $targetarch = targetarch_from_target($target); + my $targetarch = + XCAT::BuildUtils::targetarch_from_target( $target, $ARCH ); my $genesis_tarch = genesis_tarch_from_targetarch($targetarch); my $diskcache = ( @@ -523,7 +512,8 @@ sub buildpkgs { my $chroot = "$pkg-$target$ext"; # get x86_64 from alma+epel-9-x86_64 - my $targetarch = targetarch_from_target($target); + my $targetarch = + XCAT::BuildUtils::targetarch_from_target( $target, $ARCH ); # xCAT genesis packages include the translated target arch in their file names. my $arch = is_in($pkg, @NATIVE_PACKAGES) ? $targetarch : "noarch";