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 <michalx.berger@intel.com>
Change-Id: Ia50ac303dfe9090fbd424e63e9eee7d939415ac2
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8390
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Michal Berger 2021-06-16 12:33:31 +02:00 committed by Tomasz Zawadzki
parent 47ee30d3e3
commit 2b565885f3

View File

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