numam-spdk/rpmbuild/rpm.sh
Michal Berger 6317642ce6 rpmbuild: Handle bare --with-dpdk argument
This is done in order to detect if user wants to build spdk RPMs
against DPDK RPMs that might have been installed on the system.

This boils down to the following:

 - if --with-dpdk, with no argument, is detected don't build
   separate RPM holding DPDK libs since user in this case is
   most likely interested only in packaging the SPDK so it
   can coexist with separate DPDK packaging workflow
 - define install and build requirements for the SPDK RPMs
   to depend on dpdk-devel RPM

Signed-off-by: Michal Berger <michalx.berger@intel.com>
Change-Id: I4dd587009da282a114524c74d833fd35ebc5b985
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8349
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2021-07-12 14:05:20 +00:00

137 lines
4.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
specdir=$(readlink -f "$(dirname "$0")")
rootdir=$(readlink -f "$specdir/../")
[[ -e /etc/os-release ]]
source /etc/os-release
if [[ $ID != fedora && $ID != centos && $ID != rhel ]]; then
printf '%s not supported\n' "$ID" >&2
exit 1
fi
get_config() {
# Intercept part of the ./configure's cmdline we are interested in
configure_opts=($(getopt -l "$1::" -o "" -- $configure 2> /dev/null))
# Drop "--"
configure_opts=("${configure_opts[@]::${#configure_opts[@]}-1}")
((${#configure_opts[@]} > 0)) || return 1
if [[ $2 == has-arg ]]; then
[[ -n ${configure_opts[1]} && ${configure_opts[1]} != "''" ]]
elif [[ $2 == print ]]; then
echo "${configure_opts[1]//\'/}"
fi
}
fedora_python_sys_path_workaround() {
[[ -z $NO_WORKAROUND ]] || return 0
# Fedora builds its python version with a patch which attempts to remove all
# "/usr/local" paths from sys.path in case it's run under RPM environment,
# i.e., when RPM_BUILD_ROOT variable is detected. This particular variable
# is set by the rpmbuild when it executes its sh wrappers built out of the
# .spec file.
# This is problematic in case meson and ninja were installed via rooted pip
# which had its working directory set to /usr/local. As a result, when the
# SPDK executes meson to build DPDK, from rpmbuild env, it fails as
# it's not able to find its mesonbuild module.
# To workaround this little hiccup we fetch the entire sys.path list and
# then export it via PYTHONPATH so when rpmbuild kicks in, python will be
# able to find all the modules regardless if the RPM_BUILD_ROOT is set or
# not.
# FIXME: The alternative is to unset RPM_BUILD_ROOT directly in the spec?
# It does work but it feels wrong.
PYTHONPATH="$(python3 -c "import sys; print('%s' % ':'.join(sys.path)[1:])")"
export PYTHONPATH
}
get_version() {
local version
version=$(git -C "$rootdir" describe --tags --abbrev=0)
echo "${version%%-*}"
}
build_rpm() (
local macros=() dir
macros+=(-D "configure $configure")
macros+=(-D "make $make")
macros+=(-D "release $release")
macros+=(-D "version $version")
# 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")
done
if get_config with-shared; then
macros+=(-D "shared 1")
macros+=(-D "dpdk 1")
fi
if get_config with-dpdk; then
if ! get_config with-dpdk has-arg; then
# spdk is requested to build against installed dpdk (i.e. provided by the dist).
# Don't build dpdk rpm rather define proper requirements for the spdk.
macros+=(-D "dpdk 0")
macros+=(-D "shared 1")
requirements=${requirements:+$requirements, }"dpdk-devel >= 19.11"
build_requirements=${build_requirements:+$build_requirements, }"dpdk-devel >= 19.11"
else
dpdk_build_path=$(get_config with-dpdk print)
dpdk_path=$(dirname "$dpdk_build_path")
macros+=(-D "dpdk_build_path $dpdk_build_path")
macros+=(-D "dpdk_path $dpdk_path")
fi
fi
if [[ $deps == no ]]; then
macros+=(-D "deps 0")
fi
if [[ -n $requirements ]]; then
macros+=(-D "requirements 1")
macros+=(-D "requirements_list $requirements")
fi
if [[ -n $build_requirements ]]; then
macros+=(-D "build_requirements 1")
macros+=(-D "build_requirements_list $build_requirements")
fi
cd "$rootdir"
fedora_python_sys_path_workaround
# Despite building in-place, rpmbuild still looks under source dir 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"
printf '* Starting rpmbuild...\n'
rpmbuild --clean --nodebuginfo "${macros[@]}" --build-in-place -ba "$spec"
)
# .spec defaults
configure=${*:-"%{nil}"}
deps=${DEPS:-yes}
make="${MAKEFLAGS:--j $(nproc)}"
release=${RPM_RELEASE:-1}
requirements=${REQUIREMENTS:-}
build_requirements=${BUILD_REQUIREMENTS:-}
version=${SPDK_VERSION:-$(get_version)}
rpmbuild_dir=${BUILDDIR:-"$HOME/rpmbuild"}
spec=$specdir/spdk.spec
build_rpm