tests: Add rpmbuild tests

Created a virtual testcase for building any rpm with rust.
Added two specific cases: rpm-sequoia and ripgrep
This commit is contained in:
Jesus Checa Hidalgo 2024-04-22 09:37:57 +02:00 committed by jcheca
parent 8fff280b59
commit 51570d63ec
4 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,13 @@
summary: rpmbuild package with rust
description: 'Ensure that rust does not break rpmbuild'
contact:
- Jesus Checa Hidalgo <jcheca@redhat.com>
component:
- rust
test: ./runtest.sh
framework: beakerlib
require+:
- rust
- rpm-build
- yum-utils
duration: 1h

View File

@ -0,0 +1,11 @@
summary+: ": ripgrep"
require+:
- ripgrep
environment+:
PKG_TO_BUILD: "ripgrep"
duration: 15m
adjust+:
# ripgrep is not part of RHEL
- when: distro != fedora
enabled: false

View File

@ -0,0 +1,11 @@
summary+: ": rpm-sequoia"
require+:
- rpm-sequoia
environment+:
PKG_TO_BUILD: "rpm-sequoia"
duration: 20m
adjust+:
- when: distro < rhel-10, centos-stream-10
enabled: false
because: "rpm-sequoia is available only in RHEL >= 10"

View File

@ -0,0 +1,55 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="$(rpm -qf $(which rustc))"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE || rlDie "rustc not found. Aborting testcase..."
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
if [[ "x" == "x${PKG_TO_BUILD}" ]]; then
rlLogError "No package was configured to build."
rlDie "The package must be passed over PKG_TO_BUILD environment variable."
fi
rlPhaseEnd
rlPhaseStart FAIL ${PKG_TO_BUILD}FetchSrcAndInstallBuildDeps
if ! rlCheckRpm $PKG_TO_BUILD; then
rlRun "yum install -y $PKG_TO_BUILD ${YUM_SWITCHES}"
rlAssertRpm $PKG_TO_BUILD
fi
rlFetchSrcForInstalled $PKG_TO_BUILD
rlRun SRPM=$(ls -1 *.src.rpm)
rlRun "rpm -ivh $SRPM"
rlRun SPECDIR="$(rpm -E '%{_specdir}')"
# Note about the spec file name: When packaging rust crates, the package
# is named rust-<crate>, as well as the spec file, but the rpm package
# (the one we use in dnf to install and query) is named as the crate,
# (without the "rust-" prefix). We have to take that into account to
# find the spec:
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Rust/#_package_naming
rlRun "SPECNAME=$(rpm -ql $SRPM | grep .spec)"
# Packages built with rust usually contains dynamic dependencies.
# builddep needs to be run from the srpm, not the spec file, to be able
# to generate them:
# https://fedoraproject.org/wiki/Changes/DynamicBuildRequires#rpmbuild
rlRun "yum-builddep -y ${SRPM} ${YUM_SWITCHES}"
rlPhaseEnd
rlPhaseStartTest
set -o pipefail
rlRun "rpmbuild -bb ${SPECDIR}/${SPECNAME} |& tee ${SRPM}_rpmbuild.log"
rlFileSubmit "${SRPM}_rpmbuild.log"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd