Skip to content

Commit 5add67f

Browse files
committed
Allow bulding RPMs with mock
To facilitate building with mock allow specifying the mock "root" to build in. Allow specifying the kernel version to build for. Signed-off-by: Brian J. Murrell <brian@interlinx.bc.ca>
1 parent 0726e10 commit 5add67f

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#
22
# Copyright(c) 2012-2022 Intel Corporation
33
# Copyright(c) 2024 Huawei Technologies
4+
# Copyright(c) 2025 Brian J. Murrell
45
# SPDX-License-Identifier: BSD-3-Clause
56
#
67

@@ -29,11 +30,22 @@ endif
2930
endif
3031
endif
3132

33+
ifneq ($(KERNEL_VERSION),)
34+
BUILD_ARGS=--kernel_version $(KERNEL_VERSION)
35+
endif
36+
37+
ifneq ($(MOCK_ROOT),)
38+
ifeq ($(KERNEL_VERSION),)
39+
$(error KERNEL_VERSION must be set when using MOCK_ROOT)
40+
endif
41+
BUILD_ARGS=--mock_root $(MOCK_ROOT) --kernel_version $(KERNEL_VERSION)
42+
endif
43+
3244
archives:
3345
@tools/pckgen.sh $(PWD) tar zip
3446

3547
rpm:
36-
@tools/pckgen.sh $(PWD) rpm --debug
48+
@tools/pckgen.sh $(PWD) rpm --debug $(BUILD_ARGS)
3749

3850
srpm:
3951
@tools/pckgen.sh $(PWD) srpm

tools/pckgen.d/rpm/CAS_NAME.spec

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
22
# Copyright(c) 2020-2022 Intel Corporation
3+
# Copyright(c) 2025 Brian J. Murrell
34
# SPDX-License-Identifier: BSD-3-Clause
45
#
56

@@ -12,8 +13,11 @@
1213

1314
%global __python %{__python3}
1415
<DEBUG_PACKAGE>
16+
%if 0%{!?kver:1}
1517
%define kver %(uname -r)
16-
%define kver_filename k%{expand:%(kname="%{kver}"; echo "${kname%.*}" | sed -r "y/-/_/;")}
18+
%endif
19+
%define kver_base %{expand:%(kname="%{kver}"; echo "${kname%.*}")}
20+
%define kver_filename k%{expand:%(echo "%kver_base" | sed -r "y/-/_/;")}
1721

1822

1923
Name: <CAS_NAME>
@@ -26,7 +30,16 @@ License: <CAS_LICENSE_NAME>
2630
URL: <CAS_HOMEPAGE>
2731
Source0: https://github.com/Open-CAS/<CAS_NAME>/releases/download/v%{version}/%{name}-%{version}.tar.gz
2832
Packager: <PACKAGE_MAINTAINER>
29-
BuildRequires: coreutils, gawk, gcc, kernel-devel, kernel-headers, make
33+
BuildRequires: coreutils
34+
BuildRequires: gawk
35+
BuildRequires: gcc
36+
BuildRequires: kernel-core = %{kver_base}
37+
BuildRequires: kernel-devel = %{kver_base}
38+
BuildRequires: kernel-headers
39+
BuildRequires: make
40+
BuildRequires: python3
41+
BuildRequires: elfutils-libelf-devel
42+
BuildRequires: procps-ng
3043
Requires: <CAS_NAME>-modules-%{version}, python3, sed, python3-PyYAML
3144
%description
3245
Open Cache Acceleration Software (Open CAS) is an open source project
@@ -52,16 +65,18 @@ This package contains only CAS kernel modules.
5265

5366
%prep
5467
%setup -q
68+
sed -i 's/@mandb -q/#@mandb -q/' {casadm,utils}/Makefile
5569

5670

5771
%build
72+
export KERNEL_DIR=/lib/modules/%{kver}/build/
5873
./configure
5974
<MAKE_BUILD>
6075

6176

6277
%install
6378
rm -rf $RPM_BUILD_ROOT
64-
/usr/bin/make install_files DESTDIR=$RPM_BUILD_ROOT
79+
/usr/bin/make install_files KERNEL_VERSION=%{kver} DESTDIR=$RPM_BUILD_ROOT
6580

6681

6782
%post
@@ -161,6 +176,10 @@ fi
161176

162177

163178
%changelog
179+
* Thu Aug 7 2025 Brian J. Murrell <brian@interlinx.bc.ca> - 25.03-1
180+
- Make more portable:
181+
- Allow external definition of kver
182+
- Add missing BRs kernel-core, python3, elfutils-libelf-devel, procps-ng
164183
* Mon Mar 21 2022 Rafal Stefanowski <rafal.stefanowski@intel.com> - 22.03-1
165184
- Update modules destination directory and permissions
166185
- Add license to modules package

tools/pckgen.sh

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
#
33
# Copyright(c) 2020-2022 Intel Corporation
4+
# Copyright(c) 2025 Brian J. Murrell
45
# SPDX-License-Identifier: BSD-3-Clause
56
#
67

@@ -402,13 +403,23 @@ generate_rpm() {
402403
mv -ft "$OUTPUT_DIR" "$RPM_SRPMS_DIR"/*
403404
fi
404405
if [ "$GENERATE_SRPM" ] && [ "$GENERATE_RPM" ]; then
405-
echo "--- Building source and binary RPM packages"
406-
(HOME="$TEMP_DIR"; rpmbuild -ba --target "$ARCH" "$RPM_SPECS_DIR/$CAS_NAME.spec")
407-
if [ $? -ne 0 ]; then
408-
error "couldn't create RPM packages"
406+
if [ -z "$MOCK_ROOT" ]; then
407+
echo "--- Building source and binary RPM packages"
408+
if ! (HOME="$TEMP_DIR"; rpmbuild -ba --target "$ARCH" "$RPM_SPECS_DIR/$CAS_NAME.spec"); then
409+
error "couldn't create RPM packages"
410+
fi
411+
mv -ft "$OUTPUT_DIR" "$RPM_SRPMS_DIR"/*
412+
mv -ft "$OUTPUT_DIR" "$RPM_RPMS_DIR/$ARCH"/*
413+
else
414+
echo "--- Building source and binary RPM packages using mock"
415+
# shellcheck disable=SC1083
416+
if ! mock --no-clean ${KVER:+--define="kver $KVER"} -r "$MOCK_ROOT" packages/"$CAS_NAME"-"$CAS_VERSION"-1"$(rpm --eval %{dist})".src.rpm; then
417+
error "couldn't create RPM packages"
418+
fi
419+
mv -ft "$OUTPUT_DIR" /var/lib/mock/"$MOCK_ROOT"/result/"$CAS_NAME"-"$CAS_VERSION"-1.*.src.rpm
420+
mv -ft "$OUTPUT_DIR" /var/lib/mock/"$MOCK_ROOT"/result/"$CAS_NAME"-"$CAS_VERSION"-1.*.x86_64.rpm
421+
mv -ft "$OUTPUT_DIR" /var/lib/mock/"$MOCK_ROOT"/result/"$CAS_NAME"-modules_k*-"$CAS_VERSION"-1.*.x86_64.rpm
409422
fi
410-
mv -ft "$OUTPUT_DIR" "$RPM_SRPMS_DIR"/*
411-
mv -ft "$OUTPUT_DIR" "$RPM_RPMS_DIR/$ARCH"/*
412423
fi
413424

414425
RPM_BUILT="rpm_built"
@@ -510,6 +521,15 @@ while (( $# )); do
510521
print_help
511522
exit 0
512523
;;
524+
--mock_root)
525+
MOCK_ROOT="$2"
526+
shift
527+
GENERATE_SRPM="generate_srpm"
528+
;;
529+
--kernel_version)
530+
KVER="$2"
531+
shift
532+
;;
513533
*)
514534
if [ -d "$1" ]; then
515535
SOURCES_DIR=$(realpath "$1")

0 commit comments

Comments
 (0)