diff --git a/xCAT-genesis-builder/debuild-xcat-genesis-base b/xCAT-genesis-builder/debuild-xcat-genesis-base index 39ed5d4e8..665d10f70 100755 --- a/xCAT-genesis-builder/debuild-xcat-genesis-base +++ b/xCAT-genesis-builder/debuild-xcat-genesis-base @@ -30,17 +30,28 @@ alien -d -g -c -k "${RPM_PACKAGE}" || exit 1 PACKAGE_ARCH="${EXTRACT_DIR%-*}" PACKAGE_ARCH="${PACKAGE_ARCH##*-}" -if [[ ${EXTRACT_DIR} =~ -x86_64- ]] -then - rm -rf "${EXTRACT_DIR//x86_64/amd64}" - mv "${EXTRACT_DIR}" "${EXTRACT_DIR//x86_64/amd64}" - EXTRACT_DIR="${EXTRACT_DIR//x86_64/amd64}" +# The rpm carries the Genesis target architecture, the deb must carry the Debian architecture. +# alien copies the rpm name into the deb and writes "_" as "-", so x86_64 arrives as x86-64. +case "${PACKAGE_ARCH}" in +x86_64) + ALIEN_ARCH="x86-64" ; DEB_ARCH="amd64" ;; +ppc64|ppc64le) + ALIEN_ARCH="${PACKAGE_ARCH}" ; DEB_ARCH="ppc64el" ;; +*) + ALIEN_ARCH="${PACKAGE_ARCH}" ; DEB_ARCH="${PACKAGE_ARCH}" ;; +esac - sed -i -e 's/x86-64/amd64/g' "${EXTRACT_DIR}/debian/control" - sed -i -e 's/x86-64/amd64/g' "${EXTRACT_DIR}/debian/changelog" +if [[ "${DEB_ARCH}" != "${PACKAGE_ARCH}" ]] +then + rm -rf "${EXTRACT_DIR//${PACKAGE_ARCH}/${DEB_ARCH}}" + mv "${EXTRACT_DIR}" "${EXTRACT_DIR//${PACKAGE_ARCH}/${DEB_ARCH}}" + EXTRACT_DIR="${EXTRACT_DIR//${PACKAGE_ARCH}/${DEB_ARCH}}" + + sed -i -e "s/${ALIEN_ARCH}/${DEB_ARCH}/g" "${EXTRACT_DIR}/debian/control" + sed -i -e "s/${ALIEN_ARCH}/${DEB_ARCH}/g" "${EXTRACT_DIR}/debian/changelog" fi -sed -i -e "/^Description:/i Breaks: xcat-genesis-scripts-${PACKAGE_ARCH//x86_64/amd64} (<< 2.13.10)" "${EXTRACT_DIR}/debian/control" +sed -i -e "/^Description:/i Breaks: xcat-genesis-scripts-${DEB_ARCH} (<< 2.13.10)" "${EXTRACT_DIR}/debian/control" cat >"${EXTRACT_DIR}/debian/preinst" < 1); +my $driver = "$tmpdir/driver.sh"; +open(my $driver_fh, '>', $driver) or die "open $driver: $!"; +print {$driver_fh} <<'DRIVER'; +#!/bin/bash + +# alien names the deb after the rpm: lower case, and "_" written as "-". +alien() { + local rpm="${!#}" + local name="${rpm##*/}" + name="${name%.rpm}" + local dir="${name%%-snap*}" + local package="${dir%-*}" + package="${package,,}" + package="${package//_/-}" + + mkdir -p "${dir}/debian" + cat >"${dir}/debian/control" < + +Package: ${package} +Architecture: all +Description: xCAT genesis base +CONTROL + printf '%s (%s) unstable; urgency=low\n' "${package}" "1.0" \ + >"${dir}/debian/changelog" + printf '#!/usr/bin/make -f\nbinary:\n\t@true\n' >"${dir}/debian/rules" + chmod 0755 "${dir}/debian/rules" +} + +cd "${WORK_DIR}" || exit 1 +: >"${RPM_NAME}" +source "${SCRIPT}" "${RPM_NAME}" >/dev/null 2>&1 +DRIVER +close($driver_fh) or die "close $driver: $!"; + +# Convert one rpm name and return the produced source directory and its control file. +sub convert { + my ($name, $rpm) = @_; + my $work = "$tmpdir/$name"; + mkdir $work or die "mkdir $work: $!"; + local %ENV = (%ENV, SCRIPT => $script, WORK_DIR => $work, RPM_NAME => $rpm); + system('bash', $driver) == 0 or return (undef, ''); + my ($dir) = grep { -d $_ } glob("$work/*"); + return (undef, '') unless defined $dir && -f "$dir/debian/control"; + open(my $fh, '<', "$dir/debian/control") or die "read $dir/debian/control: $!"; + local $/; my $control = <$fh>; close $fh; + $dir =~ s{^\Q$work\E/}{}; + return ($dir, $control); +} + +my %expected = ( + 'xCAT-genesis-base-x86_64-2.13.10-snap202601010000.noarch.rpm' => 'amd64', + 'xCAT-genesis-base-ppc64-2.13.10-snap202601010000.noarch.rpm' => 'ppc64el', +); + +for my $rpm (sort keys %expected) { + my $arch = $expected{$rpm}; + my ($dir, $control) = convert($arch, $rpm); + BAIL_OUT("debuild-xcat-genesis-base produced no source tree for $rpm") + unless defined $dir; + + like($dir, qr/\Q-$arch-\E/, "$rpm builds in a $arch source tree"); + like($control, qr/^Package:\s*xcat-genesis-base-\Q$arch\E$/m, + "$rpm builds the package xcat-genesis-base-$arch"); + like($control, qr/^Breaks:\s*xcat-genesis-scripts-\Q$arch\E\b/m, + "xcat-genesis-base-$arch breaks the genesis scripts of its own architecture"); +} + +done_testing();