File fix.patch of Package build
From b801c174d64b32ee7ff8870565990b35c45e4e58 Mon Sep 17 00:00:00 2001
From: Michael Schroeder <mls@suse.de>
Date: Fri, 7 Mar 2025 16:18:23 +0100
Subject: [PATCH] Allow to transport jobs/smp_mflags over the RPM_BUILD_NCPUS
envvar
This is needed for reproducible builds, as rpm >= 4.20 stores the
expanded spec file in the src rpm.
We do this by setting RPM_BUILD_NCPUS to the jobs parameter before
calling rpmbuild. Also, we only overwrite the jobs/cmp_mflags
macros if they do not use the RPM_BUILD_NCPUS env var.
---
build-recipe | 8 ++++----
build-recipe-spec | 7 ++++++-
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/build-recipe b/build-recipe
index 12bae642..ff20e0d9 100644
--- a/build-recipe
+++ b/build-recipe
@@ -262,10 +262,10 @@ recipe_setup_macros() {
fi
if test -n "$BUILD_JOBS" ; then
- cat >> $BUILD_ROOT/root/$rawcfgmacros <<-EOF
- %jobs $BUILD_JOBS
- %_smp_mflags -j$BUILD_JOBS
- EOF
+ local jobsmacro=$(queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" eval '%{?jobs}')
+ test "$jobsmacro" != '${RPM_BUILD_NCPUS}' && echo "%jobs $BUILD_JOBS" >> $BUILD_ROOT/root/$rawcfgmacros
+ local smpmflagsmacro=$(chroot rpm --eval '%_smp_mflags' 2>/dev/null)
+ if test "$smpmflags" != '-j${RPM_BUILD_NCPUS}' && echo "_smp_mflags -j$BUILD_JOBS" >> $BUILD_ROOT/root/$rawcfgmacros
fi
test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/$rawcfgmacros $BUILD_ROOT/home/abuild/$rawcfgmacros
}
diff --git a/build-recipe-spec b/build-recipe-spec
index f8564c6a..c5cfb2dc 100644
--- a/build-recipe-spec
+++ b/build-recipe-spec
@@ -279,12 +279,17 @@ recipe_build_spec() {
for rpmstage in "${rpmstages[@]}" ; do
# su involves a shell which would require even more
# complicated quoting to bypass than this
+ echo "#!/bin/sh" > $BUILD_ROOT/.build.command
+ if test -n "$BUILD_JOBS" ; then
+ echo "export RPM_BUILD_NCPUS=$BUILD_JOBS" >> $BUILD_ROOT/.build.command
+ fi
+ echo "set -x" >> $BUILD_ROOT/.build.command
toshellscript $rpmbuild \
"${definesnstuff[@]}" \
$rpmstage \
"${rpmbopts[@]}" \
"$TOPDIR/SOURCES/$RECIPEFILE" \
- > $BUILD_ROOT/.build.command
+ >> $BUILD_ROOT/.build.command
chmod 755 $BUILD_ROOT/.build.command
check_exit
local build_command="/.build.command"