2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-04-11 19:31:31 +00:00

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>
This commit is contained in:
Daniel Hilst Selli
2025-12-01 15:57:57 -03:00
parent 460451cef2
commit e8b043f7c3
9 changed files with 180 additions and 4 deletions

170
buildrpms.sh Executable file
View File

@@ -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 <PACKAGE> <TARGET>
#
# 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
# <PKG>-<TARGET>, 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 <pkg>:<target> intead of two arguments <pkg> <target>
# 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 <pkg>:<target>
# Call each step required to build <pkg> for <target>
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 <PKG> <TARGET>"
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

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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