From 43e65a934252be7d7be28adde3d4f5fb31650452 Mon Sep 17 00:00:00 2001 From: Ondřej Nosek Date: Sep 01 2021 11:06:02 +0000 Subject: Patch: Pass sourcedir to rpmspec when specfile is parsed Signed-off-by: Ondřej Nosek --- diff --git a/0003-Pass-sourcedir-to-rpmspec-when-specfile-is-parsed.patch b/0003-Pass-sourcedir-to-rpmspec-when-specfile-is-parsed.patch new file mode 100644 index 0000000..7ae93e8 --- /dev/null +++ b/0003-Pass-sourcedir-to-rpmspec-when-specfile-is-parsed.patch @@ -0,0 +1,109 @@ +From e0bf13817fc4e9d2ec56f2780bf88d9cfd5a1f27 Mon Sep 17 00:00:00 2001 +From: Otto Urpelainen +Date: Wed, 1 Sep 2021 07:44:22 +0300 +Subject: [PATCH] Pass sourcedir to rpmspec when specfile is parsed + +In many cases, specfile parsing in class SpecFile failed when +the specfile contained local sources like 'Source2: local.txt'. +This happened because rpm sourcedir configuration was not passed +to utility rpmspec used for parsing, leading it to default +to '~/rpmbuild/SOURCES', which is not correct for many layouts +supported by rpkg. +Fixed by passing sourcedir correctly. + +Fixes: #559 +Relates: https://pagure.io/rpkg/pull-request/564 +Merges: https://pagure.io/rpkg/pull-request/574 + +Signed-off-by: Otto Urpelainen +--- + pyrpkg/__init__.py | 3 ++- + pyrpkg/spec.py | 9 +++++---- + tests/test_spec.py | 16 ++++++++++++---- + 3 files changed, 19 insertions(+), 9 deletions(-) + +diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py +index 5e4831a..23bca5b 100644 +--- a/pyrpkg/__init__.py ++++ b/pyrpkg/__init__.py +@@ -2042,7 +2042,8 @@ class Commands(object): + outdir = self.path + + sourcesf = SourcesFile(self.sources_filename, self.source_entry_type) +- specf = SpecFile(os.path.join(self.layout.specdir, self.spec)) ++ specf = SpecFile(os.path.join(self.layout.specdir, self.spec), ++ self.layout.sourcedir) + + args = dict() + if self.lookaside_request_params: +diff --git a/pyrpkg/spec.py b/pyrpkg/spec.py +index 1aa2500..6341fcd 100644 +--- a/pyrpkg/spec.py ++++ b/pyrpkg/spec.py +@@ -17,15 +17,16 @@ class SpecFile(object): + + sourcefile_expression = re.compile(r'^source[0-9]*:\s*(?P.*)\s*$', re.IGNORECASE) + +- def __init__(self, spec): ++ def __init__(self, spec, sourcedir): + self.spec = spec ++ self.sourcedir = sourcedir + self.sources = [] + + self.parse() + + def parse(self): + """Call rpmspec and find source tags from the result.""" +- stdout = run(self.spec) ++ stdout = run(self.spec, self.sourcedir) + for line in stdout.splitlines(): + m = self.sourcefile_expression.match(line) + if not m: +@@ -36,8 +37,8 @@ class SpecFile(object): + self.sources.append(val) + + +-def run(spec): +- cmdline = ['rpmspec', '-P', spec] ++def run(spec, sourcedir): ++ cmdline = ['rpmspec', '--define', "_sourcedir %s" % sourcedir, '-P', spec] + try: + process = subprocess.Popen(cmdline, + stdout=subprocess.PIPE, +diff --git a/tests/test_spec.py b/tests/test_spec.py +index 15e3730..196b470 100644 +--- a/tests/test_spec.py ++++ b/tests/test_spec.py +@@ -36,12 +36,17 @@ class SpecFileTestCase(unittest.TestCase): + spec_fd.write( + "Source0: https://example.com/tarball.tar.gz\n" + "Source1: https://example.com/subdir/LICENSE.txt\n" +- "Source2: https://another.domain.com/source.tar.gz\n") ++ "Source2: https://another.domain.com/source.tar.gz\n" ++ "Source3: local.txt\n") + spec_fd.close() + +- s = spec.SpecFile(self.specfile) ++ s = spec.SpecFile(self.specfile, self.workdir) + actual = s.sources +- expected = ["tarball.tar.gz", "LICENSE.txt", "source.tar.gz"] ++ expected = [ ++ "tarball.tar.gz", ++ "LICENSE.txt", ++ "source.tar.gz", ++ "local.txt"] + self.assertEqual(len(actual), len(expected)) + self.assertTrue(all([a == b for a, b in zip(actual, expected)])) + +@@ -52,4 +57,7 @@ class SpecFileTestCase(unittest.TestCase): + spec_fd.write("Foo: Bar\n") + spec_fd.close() + +- self.assertRaises(rpkgError, spec.SpecFile, [self.specfile]) ++ self.assertRaises(rpkgError, ++ spec.SpecFile, ++ self.specfile, ++ self.workdir) +-- +2.31.1 + diff --git a/rpkg.spec b/rpkg.spec index 6e68f2a..40dc68d 100644 --- a/rpkg.spec +++ b/rpkg.spec @@ -1,6 +1,6 @@ Name: rpkg Version: 1.63 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Python library for interacting with rpm+git License: GPLv2+ and LGPLv2 @@ -19,6 +19,7 @@ Source0: https://pagure.io/releases/rpkg/%{name}-%{version}.tar.gz Patch0: remove-koji-and-rpm-py-installer-from-requires.patch Patch1: 0001-Do-not-use-pytest-related-dependencies-temporarily.patch Patch2: 0002-Use-six-library-in-tests.patch +Patch3: 0003-Pass-sourcedir-to-rpmspec-when-specfile-is-parsed.patch # RHEL7 is currently the only release that is built for Python 2. %if 0%{?fedora} || 0%{?rhel} > 7 @@ -238,6 +239,9 @@ example_cli_dir=$RPM_BUILD_ROOT%{_datadir}/%{name}/examples/cli %changelog +* Wed Sep 01 2021 Ondřej Nosek - 1.63-2 +- Patch: Pass sourcedir to rpmspec when specfile is parsed + * Tue Aug 24 2021 Dominik Rumian - 1.63-1 - Do not download unused sources during command 'sources' - #559 (oturpe) - Added 'x-pkg verrel' for containers - #547 (jkunstle)