xref: /spdk/test/packaging/rpm/rpm.sh (revision c680e3a05b1a903c18bf3f75b732765607126f45)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2022 Intel Corporation
4#  All rights reserved.
5#
6
7testdir=$(readlink -f "$(dirname "$0")")
8rootdir=$(readlink -f "$testdir/../../../")
9source "$rootdir/test/common/autotest_common.sh"
10
11builddir=$SPDK_TEST_STORAGE/test-rpm
12
13# Make sure linker will not attempt to look under DPDK's repo dir to get the libs
14unset -v LD_LIBRARY_PATH
15
16# Export some common settings
17MAKEFLAGS="-j $(nproc)"
18BUILDDIR=$builddir
19DEPS=no
20
21export MAKEFLAGS BUILDDIR DEPS
22
23install_uninstall_rpms() {
24	local rpms
25
26	rpms=("${1:-$builddir/rpm/}/x86_64/"*.rpm)
27
28	sudo rpm -i "${rpms[@]}"
29	# Check if we can find one of the apps in the PATH now and verify if it doesn't miss
30	# any libs.
31	LIST_LIBS=yes "$rootdir/rpmbuild/rpm-deps.sh" "${SPDK_APP[@]##*/}"
32	rm "${rpms[@]}"
33	rpms=("${rpms[@]##*/}") rpms=("${rpms[@]%.rpm}")
34	sudo rpm -e "${rpms[@]}"
35}
36
37build_rpm() {
38	# Separate run to see the final .spec in use
39	GEN_SPEC=yes "$rootdir/rpmbuild/rpm.sh" "$@"
40	# Actual build
41	"$rootdir/rpmbuild/rpm.sh" "$@" || return $?
42	install_uninstall_rpms
43}
44
45build_shared_rpm() {
46	build_rpm --with-shared
47}
48
49build_rpm_with_rpmed_dpdk() {
50	local es=0
51
52	sudo dnf install -y dpdk-devel
53	build_rpm --with-shared --with-dpdk || es=$?
54
55	if ((es == 11)); then
56		echo "ERROR: Failed to resolve required build dependencies. Please review the build log." >&2
57	fi
58	return "$es"
59}
60
61build_rpm_from_gen_spec() {
62	local version=test_gen_spec
63	local sourcedir rpmdir
64
65	GEN_SPEC=yes \
66		USE_DEFAULT_DIRS=yes \
67		SPDK_VERSION="$version" \
68		"$rootdir/rpmbuild/rpm.sh" --with-shared > "$builddir/gen-spdk.spec"
69
70	# Default locations should be in use.
71	sourcedir=$(rpm --eval "%{_sourcedir}") rpmdir=$(rpm --eval "%{_rpmdir}")
72	mkdir -p "$sourcedir" "$rpmdir"
73
74	# Prepare the source at the default location - default %prep step requires
75	# extra dir inside the source package hence the dance with symlinking to
76	# the repo (after the extraction source should be under spdk-$version/) -
77	# make sure symlinking is done outside of the repo to avoid nasty loops.
78	ln -s "$rootdir" "/tmp/spdk-$version"
79	tar -czhf "$sourcedir/spdk-$version.tar.gz" -C /tmp "spdk-$version"
80
81	# See rpm.sh for details on the PYTHONPATH HACK
82	PYTHONPATH="$(python3 -c "import sys; print('%s' % ':'.join(sys.path)[1:])")" \
83		rpmbuild -ba "$builddir/gen-spdk.spec"
84	install_uninstall_rpms "$rpmdir"
85}
86
87build_shared_native_dpdk_rpm() {
88	build_rpm --with-shared --with-dpdk="$SPDK_RUN_EXTERNAL_DPDK"
89}
90
91run_test "build_shared_rpm" build_shared_rpm
92if ((RUN_NIGHTLY == 1)); then
93	run_test "build_shared_rpm_with_rpmed_dpdk" build_rpm_with_rpmed_dpdk
94	run_test "build_rpm_from_gen_spec" build_rpm_from_gen_spec
95	if [[ -n $SPDK_TEST_NATIVE_DPDK ]]; then
96		run_test "build_shared_native_dpdk_rpm" build_shared_native_dpdk_rpm
97	fi
98fi
99
100rm -rf "$builddir"
101