From 6a568d704601eb271685db3d4789657686252bc4 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Jun 09 2021 19:33:42 +0000 Subject: Skip NVR check if the %autorelease macro is used If a spec file sets the release field to the %autorelease macro, don't even attempt to check if the build exists already, as using the macro ensures that a new release number is used. Fixes: https://pagure.io/fedora-infra/rpmautospec/issue/109 Signed-off-by: Nils Philippsen --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 3622e7a..8f10957 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -67,6 +67,11 @@ else: # The SafeConfigParser class has been renamed to ConfigParser in Python 3.2. ConfigParser = configparser.ConfigParser +try: + from rpmautospec import specfile_uses_rpmautospec +except ImportError: + specfile_uses_rpmautospec = None + class NullHandler(logging.Handler): """Null logger to avoid spurious messages, add a handler in app code""" @@ -156,6 +161,8 @@ class Commands(object): self._nvr = None # The rpm release of the cloned package self._rel = None + # Whether the spec file uses %autorelease + self._uses_autorelease = None # The cloned repo object self._repo = None # The rpm defines used when calling rpm @@ -672,20 +679,36 @@ class Commands(object): @property def rel(self): """This property ensures the rel attribute""" - if not self._rel: + if self._rel is None: self.load_nameverrel() return(self._rel) + @property + def uses_autorelease(self): + if self._uses_autorelease is None: + self.load_nameverrel() + return self._uses_autorelease + def load_nameverrel(self): """Set the release of a package.""" + specfile_path = os.path.join(self.path, self.spec) + + if specfile_uses_rpmautospec: + self._uses_autorelease = specfile_uses_rpmautospec( + specfile_path, check_autorelease=True, check_autochangelog=False + ) + else: + # Set to 0 so it evaluates false-ish but differs from (unset) None. + self._uses_autorelease = 0 + cmd = ['rpm'] cmd.extend(self.rpmdefines) # We make sure there is a space at the end of our query so that # we can split it later. When there are subpackages, we get a # listing for each subpackage. We only care about the first. cmd.extend(['-q', '--qf', '"??%{NAME} %{EPOCH} %{VERSION} %{RELEASE}??"', - '--specfile', '"%s"' % os.path.join(self.path, self.spec)]) + '--specfile', '"%s"' % specfile_path]) joined_cmd = ' '.join(cmd) try: proc = subprocess.Popen(joined_cmd, shell=True, @@ -2273,9 +2296,9 @@ class Commands(object): ' in following messages.') build_reference = self.repo_name - # see if this build has been done. Does not check builds within - # a chain - if nvr_check and not scratch and not url.endswith('.src.rpm'): + # See if this build has been done. Does not check builds within + # a chain, or if the %autorelease macro is used. + if (nvr_check or self.uses_autorelease) and not scratch and not url.endswith('.src.rpm'): build = self.kojisession.getBuild(self.nvr) if build: if build['state'] == 1: diff --git a/tests/test_cli.py b/tests/test_cli.py index 0fda4f1..66144f7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -3617,9 +3617,12 @@ class TestBuildPackage(FakeKojiCreds, CliTestCase): commithash.return_value = '45678' nvr.return_value = 'docpkg-0.1-1.fc28' - Popen.return_value.communicate.side_effect = [ + proc = Popen.return_value + proc.communicate.side_effect = [ ('12345', ''), + ('??docpkg (none) 1.2 2.el7??', ''), ] + proc.returncode = 0 self.assert_build( 'chain-build',