xref: /spdk/test/packaging/rpm/rpm.sh (revision 1078198e78653b2f39414c1566740018d76ee73d)
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/}/$(uname -m)/"*.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 dpdk_rpms=()
51
52	dpdk_rpms=(/var/spdk/dependencies/autotest/dpdk/dpdk?(-devel).rpm)
53	if ((${#dpdk_rpms[@]} == 2)); then # dpdk, dpdk-devel
54		echo "INFO: Installing DPDK from local package: $(rpm -q --queryformat="%{VERSION}" "${dpdk_rpms[0]}")" >&2
55		sudo rpm -i "${dpdk_rpms[@]}"
56	else
57		echo "WARNING: No local packages found, trying to install DPDK from the remote" >&2
58		sudo dnf install -y dpdk-devel
59	fi
60	build_rpm --with-shared --with-dpdk || es=$?
61
62	if ((es == 11)); then
63		echo "ERROR: Failed to resolve required build dependencies. Please review the build log." >&2
64	fi
65	return "$es"
66}
67
68build_rpm_from_gen_spec() {
69	local version=test_gen_spec
70	local sourcedir rpmdir
71
72	GEN_SPEC=yes \
73		USE_DEFAULT_DIRS=yes \
74		SPDK_VERSION="$version" \
75		"$rootdir/rpmbuild/rpm.sh" --with-shared > "$builddir/gen-spdk.spec"
76
77	# Default locations should be in use.
78	sourcedir=$(rpm --eval "%{_sourcedir}") rpmdir=$(rpm --eval "%{_rpmdir}")
79	mkdir -p "$sourcedir" "$rpmdir"
80
81	# Prepare the source at the default location - default %prep step requires
82	# extra dir inside the source package hence the dance with symlinking to
83	# the repo (after the extraction source should be under spdk-$version/) -
84	# make sure symlinking is done outside of the repo to avoid nasty loops.
85	ln -s "$rootdir" "/tmp/spdk-$version"
86	tar -czhf "$sourcedir/spdk-$version.tar.gz" -C /tmp "spdk-$version"
87
88	# See rpm.sh for details on the PYTHONPATH HACK
89	PYTHONPATH="$(python3 -c "import sys; print('%s' % ':'.join(sys.path)[1:])")" \
90		rpmbuild -ba "$builddir/gen-spdk.spec"
91	install_uninstall_rpms "$rpmdir"
92}
93
94build_shared_native_dpdk_rpm() {
95	[[ -e /tmp/spdk-ld-path ]] # autobuild dependency
96	source /tmp/spdk-ld-path
97	build_rpm --with-shared --with-dpdk="$SPDK_RUN_EXTERNAL_DPDK"
98}
99
100run_test "build_shared_rpm" build_shared_rpm
101run_test "build_rpm_from_gen_spec" build_rpm_from_gen_spec
102
103if ((RUN_NIGHTLY == 1)); then
104	run_test "build_shared_rpm_with_rpmed_dpdk" build_rpm_with_rpmed_dpdk
105fi
106
107if [[ -n $SPDK_TEST_NATIVE_DPDK ]]; then
108	run_test "build_shared_native_dpdk_rpm" build_shared_native_dpdk_rpm
109fi
110
111rm -rf "$builddir"
112