#678 Use release's rpmdefines in unused sources check
Merged a year ago by onosek. Opened a year ago by oturpe.

file modified
+15 -6
@@ -2261,13 +2261,22 @@ 

          sourcesf = SourcesFile(self.sources_filename, self.source_entry_type)

  

          try:

-             specf = SpecFile(os.path.join(self.layout.specdir, self.spec),

-                              self.layout.sourcedir)

-             spec_parsed = True

-         except Exception:

-             self.log.warning("Parsing specfile for used sources failed. "

-                              "Falling back to downloading all sources.")

+             # Try resolving rpmdefines separately. This produces a clear error

+             # message in the common failure case of custom branch name.

+             self.rpmdefines

+         except Exception as err:

+             self.log.warning("Parsing specfile for used sources failed: %s" % err)

+             self.log.warning("Falling back to downloading all sources.")

              spec_parsed = False

+         else:

+             try:

+                 specf = SpecFile(os.path.join(self.layout.specdir, self.spec),

+                                  self.rpmdefines)

+                 spec_parsed = True

+             except Exception:

+                 self.log.warning("Parsing specfile for used sources failed. "

+                                  "Falling back to downloading all sources.")

+                 spec_parsed = False

  

          args = dict()

          if self.lookaside_request_params:

file modified
+7 -5
@@ -18,16 +18,16 @@ 

          r'^((source[0-9]*|patch[0-9]*)\s*:\s*(?P<val>.*))\s*$',

          re.IGNORECASE)

  

-     def __init__(self, spec, sourcedir):

+     def __init__(self, spec, rpmdefines):

          self.spec = spec

-         self.sourcedir = sourcedir

+         self.rpmdefines = rpmdefines

          self.sources = []

  

          self.parse()

  

      def parse(self):

          """Call rpmspec and find source tags from the result."""

-         stdout = run(self.spec, self.sourcedir)

+         stdout = run(self.spec, self.rpmdefines)

          for line in stdout.splitlines():

              m = self.sourcefile_expression.match(line)

              if not m:
@@ -38,8 +38,10 @@ 

              self.sources.append(val)

  

  

- def run(spec, sourcedir):

-     cmdline = ['rpmspec', '--define', "_sourcedir %s" % sourcedir, '-P', spec]

+ def run(spec, rpmdefines):

+     cmdline = ['rpmspec']

+     cmdline.extend(rpmdefines)

+     cmdline.extend(['-P', spec])

      try:

          process = subprocess.Popen(cmdline,

                                     stdout=subprocess.PIPE,

Conditional Source: tags are problematic and, in fact, forbidden in at
least Fedora. However, there are packages that conditionalize packages
based on macros such as %{rhel} or %{fedora}. 'x-pkg sources' did not
handle such packages correctly, because when the specfile was parsed
to check for unused sources, values for those macros were not set. This
was different from other commands which set such macros based on the
value of --release parameter or Git branch name.

Improve support for conditional Source: tags by using the standard set
of rpmdefines when the specfile is parsed in 'fedpkg sources'.

Fixes #671

Signed-off-by: Otto Liljalaakso otto.liljalaakso@iki.fi

I would still like to test this more, and perhaps add some automatic tests.
But if you think this is correct and fixes the issue, I will not object to merge.

I'll check it out this week.

Suggestion:

self.log.warning("Could not determine distribution macros from branch and/or --release.")

Possibly emmit the err message to the debug log.

rebased onto 4c0e1fb0576f66f5d12f7e561072ece51468d287

a year ago

rebased onto 95fb02d

a year ago

Commit 8667d53 fixes this pull-request

Pull-Request has been merged by onosek

a year ago

Thanks. I added one test case and repaired SpecFile tests.

Thank you for merging, and especially for fixing the tests —
that was on my TODO list, but unfortunately I could not find the time to get there.

You're welcome. But what did I miss? The message? I just thought you are standing your ground :-).

I am not sure what you are referring to, perhaps to comments the fixed issue #671?

I do not think you missed anything.
From my perspective, everything is fine here,
A bug has been fixed and error messages are being improved, good progress.

Metadata