From 24daf1e4f7e93de06a1a7ff867cddd0345b25f5e Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Wed, 16 Jun 2021 12:33:31 +0200 Subject: [PATCH] rpmbuild: Allow to use default RPM build directories USE_DEFAULT_DIRS can be used together with GEN_SPEC to not hardcode our custom paths into the .spec and instead use default set of dirs - this should allow users to not define custom dir macros for their own rpmbuild instances and simply run the build against the .spec: $ GEN_SPEC=yes USE_DEFAULT_DIRS=yes ./rpmbuild/rpm.sh > foo.spec # .. prepare source ... $ rpmbuild -ba foo.spec Signed-off-by: Michal Berger Change-Id: Ia50ac303dfe9090fbd424e63e9eee7d939415ac2 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8390 Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Konrad Sztyber Reviewed-by: Jim Harris --- rpmbuild/rpm.sh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/rpmbuild/rpm.sh b/rpmbuild/rpm.sh index 31e923fba..5ab6285d6 100755 --- a/rpmbuild/rpm.sh +++ b/rpmbuild/rpm.sh @@ -67,7 +67,7 @@ get_version() { build_macros() { local -g macros=() - local dir + local dir _dir macros+=(-D "configure ${configure:-"%{nil}"}") macros+=(-D "make $make") @@ -76,8 +76,12 @@ build_macros() { # Adjust dir macros to update the final location of the RPMS for dir in build buildroot rpm source spec srcrpm; do - mkdir -p "$rpmbuild_dir/$dir" - macros+=(-D "_${dir}dir $rpmbuild_dir/$dir") + _dir=$(rpm --eval "%{_${dir}dir}") + if [[ -z $USE_DEFAULT_DIRS ]]; then + macros+=(-D "_${dir}dir $rpmbuild_dir/$dir") + _dir=$rpmbuild_dir/$dir + fi + local -g "_${dir}dir=$_dir" done if get_config with-shared; then @@ -123,10 +127,18 @@ gen_spec() { build_rpm() ( fedora_python_sys_path_workaround - # Despite building in-place, rpmbuild still looks under source dir as defined + mkdir -p \ + "$_builddir" \ + "$_buildrootdir" \ + "$_rpmdir" \ + "$_sourcedir" \ + "$_specdir" \ + "$_srcrpmdir" + + # Despite building in-place, rpmbuild still looks under %{_sourcedir} as defined # in Source:. Create a dummy file to fulfil its needs and to keep Source in # the .spec. - : > "$rpmbuild_dir/source/spdk-$version.tar.gz" + : > "$_sourcedir/spdk-$version.tar.gz" printf '* Starting rpmbuild...\n' rpmbuild --clean --nodebuginfo "${macros[@]}" --build-in-place -ba "$spec"