From e8b043f7c33f5e8d097540461b8ae78c6466d02f Mon Sep 17 00:00:00 2001 From: Daniel Hilst Selli <392820+dhilst@users.noreply.github.com> Date: Mon, 1 Dec 2025 15:57:57 -0300 Subject: [PATCH] build: Add buildrpms.sh to build RPMs for multiple EL targets Fix warning in xCAT/xCAT.spec about macro inside comments Fix missing build dependencies in .spec files Enable passsing gitinfo as command line argument in perl-xCAT.spec Signed-off-by: Daniel Hilst Selli <392820+dhilst@users.noreply.github.com> --- buildrpms.sh | 170 ++++++++++++++++++ perl-xCAT/perl-xCAT.spec | 5 +- .../xCAT-OpenStack-baremetal.spec | 1 + xCAT-SoftLayer/xCAT-SoftLayer.spec | 1 + xCAT-client/xCAT-client.spec | 2 + xCAT-confluent/xCAT-confluent.spec | 1 + xCAT-test/xCAT-test.spec | 1 + xCAT-vlan/xCAT-vlan.spec | 1 + xCAT/xCAT.spec | 2 - 9 files changed, 180 insertions(+), 4 deletions(-) create mode 100755 buildrpms.sh diff --git a/buildrpms.sh b/buildrpms.sh new file mode 100755 index 000000000..8d5cc198b --- /dev/null +++ b/buildrpms.sh @@ -0,0 +1,170 @@ +#!/bin/bash -e + +# Build xCAT rpms for multiple targets using mock for +# chroot encapsulation. There are multiple packages and +# multiple targets. A package is a xCAT package, like +# xCAT-server, a target is a mock chroot, like rhel+epel-9-x86_64. +# +# This script has two modes: +# ./buildrpms.sh all +# ./buildrpms.sh single +# +# In 'all' mode it builds ALL packages for ALL targets, this +# is, a cartesian product PKGS x TARGETS, a RPM is a pair +# (PKG, TARGET). +# +# In 'single' mode a single RPM is built. It is intented for +# reproducing failing builds and for debugging. +# +# In order to make 'all' mode faster the builds are parallelized. Since mock +# lock chroots a distinct chroot is created for each RPM with name +# -, then multiple mock processes are spawn, each with its own +# chroot. +# +# The output is generated at dist/ folder, both .src.rpm and .rpm files are +# in this folder. +# +# Notes: +# - `xargs` requires shell functions and variables to be exported +# - Because `buildall` is executed by xargs, I updated it to accept a single +# argument : intead of two arguments + +# pkgs built by default +PACKAGES=(xCAT-{server,client,probe,openbmc-py,rmc,test,vlan,confluent} perl-xCAT xCAT) + +# All targets +TARGETS=(rhel+epel-{8,9,10}-x86_64) + +SOURCES=${SOURCES:-/root/rpmbuild/SOURCES/} +VERSION=$(cat Version) +RELEASE=$(cat Release) +GITINFO=$(cat Gitinfo) + +NPROC=${NPROC:-$(nproc --all)} + +export SOURCES VERSION RELEASE GITINFO + +# Holds all RPMS to be built +declare -a RPMS=() +for target in ${TARGETS[@]}; do + for pkg in ${PACKAGES[@]}; do + RPMS+=("$pkg:$target") + done +done + +# Create the mock chroot configurations for each $pkg $target +function createmockchroot() { + local pkg=$1 + local target=$2 + local chroot="$pkg-$target" + if [ ! -f "/etc/mock/$chroot.cfg" ]; then + cp "/etc/mock/$target.cfg" "/etc/mock/$chroot.cfg" + sed -e "s/config_opts\['root'\]\s\+=.*/config_opts['root'] = \"$chroot\"/" \ + -i "/etc/mock/$chroot.cfg" + fi +} +export -f createmockchroot + +# Create a tarball of the source code into $SOURCES/. These tarballs +# are then read by the .spec files +function buildsources() { + local pkg=$1 + + case $1 in + xCAT) + # shipping bmcsetup and getipmi scripts as part of postscripts + files=("bmcsetup" "getipmi") + for f in "${files[@]}"; do + cp "xCAT-genesis-scripts/usr/bin/"$f ${pkg}/postscripts/$f + sed -i "s/xcat.genesis.$f/$f/g" ${pkg}/postscripts/$f + done + cd xCAT + tar --exclude upflag -czf $SOURCES/postscripts.tar.gz postscripts LICENSE.html + tar -czf $SOURCES/prescripts.tar.gz prescripts + tar -czf $SOURCES/templates.tar.gz templates + tar -czf $SOURCES/winpostscripts.tar.gz winpostscripts + tar -czf $SOURCES/etc.tar.gz etc + cp xcat.conf $SOURCES + cp xcat.conf.apach24 $SOURCES + cp xCATMN $SOURCES + cd .. + ;; + *) + tar -czf "$SOURCES/$pkg-$VERSION.tar" $pkg + ;; + esac +} +export -f buildsources + +# Build the .src.rpm files +function buildspkgs() { + local pkg=$1 + local target=$2 + local chroot="$pkg-$target" + mock -r $chroot \ + -N \ + --quiet \ + --define "version $VERSION" \ + --define "release $RELEASE" \ + --define "gitinfo $GITINFO" \ + --buildspkg \ + --spec $pkg/$pkg.spec \ + --sources $SOURCES \ + --resultdir "dist/$target/$pkg/" +} +export -f buildspkgs + +# Build the .noarch.rpm files +function buildpkgs() { + local pkg=$1 + local target=$2 + local chroot="$pkg-$target" + mock -r $chroot \ + -N \ + --quiet \ + --define "version $VERSION" \ + --define "release $RELEASE" \ + --define "gitinfo $GITINFO" \ + --resultdir "dist/$target/$pkg/" \ + dist/$target/$pkg/$pkg-${VERSION}-${RELEASE}.src.rpm +} +export -f buildpkgs + +# Receive a single argument with the format : +# Call each step required to build for +function buildall() { + IFS=: read -r pkg target <<< "$1" + createmockchroot $pkg $target + buildsources $pkg $target + buildspkgs $pkg $target + buildpkgs $pkg $target +} +export -f buildall + +function usage() { + echo "usage:. $0 single " + echo "usage:. $0 all" + echo " where:" + echo " PKG = one of xCAT-server,xCAT-client,.." + echo ' TARGET = one of `mock --list-chroots`' + echo ' all = build all combinations' + exit -1 +} + +test -d dist/ || mkdir dist/ + +if [ $# -ne 1 ] && [ $# -ne 3 ]; then + usage +fi + +case $1 in + 'single') + buildall "$2:$3" + ;; + 'all') + echo -n ${RPMS[@]} | xargs -d ' ' -I% -P $NPROC -t bash -euc "buildall %" + ;; + *) + usage + ;; +esac diff --git a/perl-xCAT/perl-xCAT.spec b/perl-xCAT/perl-xCAT.spec index 43ae21992..ee00e56c0 100644 --- a/perl-xCAT/perl-xCAT.spec +++ b/perl-xCAT/perl-xCAT.spec @@ -13,6 +13,7 @@ Prefix: /opt/xcat BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root %ifos linux BuildArch: noarch +BuildRequires: perl perl-DBI perl-JSON # Do not need the SOAP rpm require, because rpm will generate it automatically if hpoa.pm is included #Requires: perl-SOAP-Lite %endif @@ -21,7 +22,7 @@ BuildArch: noarch Provides perl xCAT libraries for core functionality. Required for all xCAT installations. Includes xCAT::Table, xCAT::NodeRange, among others. -%define gitinfo %(git log -n 1 | head -n 1 | cut -f 2 -d ' ') +%define _gitinfo %{?gitinfo}%{!?gitinfo:%(git log -n 1 | head -n 1 | cut -f 2 -d ' ')} %define zvm %(if [ "$zvm" = "1" ];then echo 1; else echo 0; fi) %define fsm %(if [ "$fsm" = "1" ];then echo 1; else echo 0; fi) @@ -37,7 +38,7 @@ Includes xCAT::Table, xCAT::NodeRange, among others. %if %fsm %else # Modify the Version() function in xCAT/Utils.pm to automatically have the correct version -./modifyUtils %{version} %{gitinfo} +./modifyUtils %{version} %{_gitinfo} # Build the pod version of the man pages for each DB table. It puts them in the man5 and man7 subdirs. # Then convert the pods to man pages and html pages. diff --git a/xCAT-OpenStack-baremetal/xCAT-OpenStack-baremetal.spec b/xCAT-OpenStack-baremetal/xCAT-OpenStack-baremetal.spec index ff45e5bd6..0a38609de 100644 --- a/xCAT-OpenStack-baremetal/xCAT-OpenStack-baremetal.spec +++ b/xCAT-OpenStack-baremetal/xCAT-OpenStack-baremetal.spec @@ -20,6 +20,7 @@ BuildArch: noarch Provides: xCAT-OpenStack-baremetal = %{epoch}:%{version} Requires: xCAT-client +BuildRequires: perl-Pod-Html %description xCAT-OpenStack-baremetal provides the baremetal driver for OpenStack. diff --git a/xCAT-SoftLayer/xCAT-SoftLayer.spec b/xCAT-SoftLayer/xCAT-SoftLayer.spec index 32d336108..0991a419c 100644 --- a/xCAT-SoftLayer/xCAT-SoftLayer.spec +++ b/xCAT-SoftLayer/xCAT-SoftLayer.spec @@ -15,6 +15,7 @@ BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root BuildArch: noarch %endif Requires: xCAT-server +BuildRequires: perl-Pod-Html # perl-ExtUtils-MakeMaker, perl-CPAN, perl-Test-Harness are only available in rhel. # When this rpm supports being installed in sles, need to add these to xcat-dep. diff --git a/xCAT-client/xCAT-client.spec b/xCAT-client/xCAT-client.spec index e216c20c7..c555e2360 100644 --- a/xCAT-client/xCAT-client.spec +++ b/xCAT-client/xCAT-client.spec @@ -19,6 +19,8 @@ BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root %define s390x %(if [ "$s390x" = "1" ];then echo 1; else echo 0; fi) %define nots390x %(if [ "$s390x" = "1" ];then echo 0; else echo 1; fi) +BuildRequires: perl-Pod-Html + # AIX will build with an arch of "ppc" %ifos linux BuildArch: noarch diff --git a/xCAT-confluent/xCAT-confluent.spec b/xCAT-confluent/xCAT-confluent.spec index 8b3dc9e1f..b0bf55e48 100644 --- a/xCAT-confluent/xCAT-confluent.spec +++ b/xCAT-confluent/xCAT-confluent.spec @@ -17,6 +17,7 @@ BuildArch: noarch Requires: confluent_server Provides: xCAT-confluent = %{epoch}:%{version} +BuildRequires: perl-Pod-Html %description xCAT confluent provides the necessary integration pieces to utilize the confluent diff --git a/xCAT-test/xCAT-test.spec b/xCAT-test/xCAT-test.spec index e5f3d0fb5..7b74bdeeb 100644 --- a/xCAT-test/xCAT-test.spec +++ b/xCAT-test/xCAT-test.spec @@ -11,6 +11,7 @@ Vendor: IBM Corp. Distribution: %{?_distribution:%{_distribution}}%{!?_distribution:%{_vendor}} Prefix: /opt/xcat BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root +BuildRequires: perl-Pod-Html # AIX will build with an arch of "ppc" %ifos linux diff --git a/xCAT-vlan/xCAT-vlan.spec b/xCAT-vlan/xCAT-vlan.spec index 0e1b9b772..69e3c5cbe 100644 --- a/xCAT-vlan/xCAT-vlan.spec +++ b/xCAT-vlan/xCAT-vlan.spec @@ -11,6 +11,7 @@ Vendor: IBM Corp. Distribution: %{?_distribution:%{_distribution}}%{!?_distribution:%{_vendor}} Prefix: /opt/xcat BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root +BuildRequires: perl-Pod-Html %ifos linux BuildArch: noarch diff --git a/xCAT/xCAT.spec b/xCAT/xCAT.spec index 1a779e55c..3a891bc1e 100644 --- a/xCAT/xCAT.spec +++ b/xCAT/xCAT.spec @@ -40,8 +40,6 @@ Requires: xCAT-server = 4:%{version}-%{release} %if %nots390x Requires: xCAT-probe = 4:%{version}-%{release} -# Requires: xCAT-genesis-scripts-x86_64 = 1:%{version}-%{release} -# Requires: xCAT-genesis-scripts-ppc64 = 1:%{version}-%{release} %endif Requires: rsync