Skip to content

Commit

Permalink
Fix incompatibility with RPM 4.20
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mizdebsk committed May 31, 2024
1 parent 20d5305 commit 4da078a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
12 changes: 6 additions & 6 deletions test/mvn_macros_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -392,29 +392,29 @@ 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',
args), args)

@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')
Expand Down
2 changes: 1 addition & 1 deletion test/pom_macros_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions test/test_rpmbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import subprocess
import shutil
import glob

from textwrap import dedent

Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -153,7 +158,6 @@ def __prepare_spec(self):
build_section = dedent("""\
%build
cd ./%{name}-%{version}
""")
build_section += self.__build

Expand Down

0 comments on commit 4da078a

Please sign in to comment.