From 4da078a2fe4738648a0a2c07e79cd81250f8b657 Mon Sep 17 00:00:00 2001 From: Mikolaj Izdebski Date: Thu, 30 May 2024 10:30:28 +0200 Subject: [PATCH] Fix incompatibility with RPM 4.20 RPM 4.20 creates a different BUILD directory structure than RPM 4.19 and earlier. To avoid reliance on any particular BUILD directory strucure, create build subdir with %setup and then search BUILD directory to find the actual location of build subdir. --- test/mvn_macros_test.py | 12 ++++++------ test/pom_macros_test.py | 2 +- test/test_rpmbuild.py | 12 ++++++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/test/mvn_macros_test.py b/test/mvn_macros_test.py index 6b111961..ca555dd2 100644 --- a/test/mvn_macros_test.py +++ b/test/mvn_macros_test.py @@ -379,7 +379,7 @@ def test_mvn_install(self, pack): _, stderr, return_value = pack.run_install() self.assertEqual(return_value, 0, stderr) - argspath = os.path.join('rpmbuild', 'BUILD', '.xmvn', 'install-out') + argspath = os.path.join(pack.buildpath, '.xmvn', 'install-out') with open(argspath, 'r') as argsfile: args = argsfile.read() self.assertTrue(re.match(r'-R \.xmvn-reactor -n \S+ -d \S+\n', @@ -392,7 +392,7 @@ def test_mvn_install_debug(self, pack): _, stderr, return_value = pack.run_install() self.assertEqual(return_value, 0, stderr) - argspath = os.path.join('rpmbuild', 'BUILD', '.xmvn', 'install-out') + argspath = os.path.join(pack.buildpath, '.xmvn', 'install-out') with open(argspath, 'r') as argsfile: args = argsfile.read() self.assertTrue(re.match(r'-X -R \.xmvn-reactor -n \S+ -d \S+\n', @@ -400,21 +400,21 @@ def test_mvn_install_debug(self, pack): @rpm_test() def test_mvn_install_directory(self, pack): - pack.append_to_build('mkdir ../doc') - pack.append_to_build('touch ../doc/file') + pack.append_to_build('mkdir doc') + pack.append_to_build('touch doc/file') pack.append_to_install('%mvn_install -J doc') pack.append_to_install('%files -f .mfiles-javadoc') _, stderr, return_value = pack.run_install() self.assertEqual(return_value, 0, stderr) - argspath = os.path.join('rpmbuild', 'BUILD', '.xmvn', 'install-out') + argspath = os.path.join(pack.buildpath, '.xmvn', 'install-out') with open(argspath, 'r') as argsfile: args = argsfile.read() self.assertTrue(re.match(r'-R \.xmvn-reactor -n \S+ -d \S+\n', args), args) - mfilespath = os.path.join('rpmbuild', 'BUILD', '.mfiles-javadoc') + mfilespath = os.path.join(pack.buildpath, '.mfiles-javadoc') with open(mfilespath, 'r') as mfiles: self.assertEqual(mfiles.read(), '/usr/share/javadoc/test_mvn_install_directory\n') diff --git a/test/pom_macros_test.py b/test/pom_macros_test.py index 824e8a2c..a7d13e85 100644 --- a/test/pom_macros_test.py +++ b/test/pom_macros_test.py @@ -22,10 +22,10 @@ def test_decorated(self, *args, **kwargs): pomname = os.path.basename(pom) package = Package(function.__name__) package.add_source(pompath) - pomsourcepath = os.path.join(package.buildpath, pomname) package.append_to_prep('%{command} {pom} {tail}'.format(command=command, pom=pomname, tail=tail)) stdin, stderr, return_value = package.run_prep() + pomsourcepath = os.path.join(package.buildpath, pomname) function(self, stdin, stderr, return_value, pomsourcepath) return test_decorated diff --git a/test/test_rpmbuild.py b/test/test_rpmbuild.py index 680809c6..d64e40d2 100644 --- a/test/test_rpmbuild.py +++ b/test/test_rpmbuild.py @@ -4,6 +4,7 @@ import sys import subprocess import shutil +import glob from textwrap import dedent @@ -27,7 +28,8 @@ def __init__(self, name): self.__prep = '' self.__build = '' self.__install = '' - self.buildpath = os.path.join('rpmbuild', 'BUILD', name + '-1') + # buildpath is set after running prep, it is not known in advance + self.buildpath = None self.__env = dict(os.environ) self.__env['HOME'] = os.getcwd() self.__env['PATH'] = '{mock}:{path}'.format(mock=DIRPATH, @@ -97,6 +99,10 @@ def __invoke_rpmbuild(self, args): err = errfile.read() os.remove('tmpout') os.remove('tmperr') + # RPM 4.19 and 4.20 use different BUILD directory structure, thus we search the filesystem + # to find the actual location of build subdir without reliance on particular structure + self.buildpath = glob.glob('rpmbuild/BUILD/**/{name}-subdir'.format(name=self.__name), + recursive=True)[0] return (out, err, ret) def set_env(self, name, value): @@ -139,8 +145,7 @@ def __prepare_spec(self): prep_section = dedent("""\ %prep - mkdir %{name}-%{version} - cd ./%{name}-%{version} + %setup -cTn %{name}-subdir """) for index, (_, filename) in enumerate(self.__sources): directory = os.path.dirname(filename) @@ -153,7 +158,6 @@ def __prepare_spec(self): build_section = dedent("""\ %build - cd ./%{name}-%{version} """) build_section += self.__build