packit / specfile

A library for parsing and manipulating RPM spec files
MIT License
24 stars 15 forks source link

Cannot parse linux-system-roles.spec #234

Open xsuchy opened 1 year ago

xsuchy commented 1 year ago

What happened? What is the problem?

During parsing linux-system-roles.spec I get:

Created dummy sources for nonexistent files:                             
/tmp/rpm-specs/extrasources.inc
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/specfile/spec_parser.py", line 201, in get_rpm_spec
    return rpm.spec(tmp.name, flags)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: can't parse specfile

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/specfile/spec_parser.py", line 269, in _do_parse
    spec = get_rpm_spec(content, rpm.RPMSPEC_ANYARCH | rpm.RPMSPEC_FORCE)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/specfile/spec_parser.py", line 203, in get_rpm_spec
    raise RPMException(stderr=stderr) from e
specfile.exceptions.RPMException: Unable to open /tmp/rpm-specs/extrasources.inc: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/specfile/spec_parser.py", line 201, in get_rpm_spec
    return rpm.spec(tmp.name, flags)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: can't parse specfile

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/msuchy/projects/specfile/tests/test-parsing/./parse.py", line 8, in <module>
    specfile = Specfile(filename, force_parse=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/specfile/specfile.py", line 71, in __init__
    self._parser.parse(str(self))
  File "/usr/lib/python3.11/site-packages/specfile/spec_parser.py", line 353, in parse
    self.spec, self.tainted = self._do_parse(content, extra_macros)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/specfile/spec_parser.py", line 294, in _do_parse
    spec = get_rpm_spec(
           ^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/specfile/spec_parser.py", line 203, in get_rpm_spec
    raise RPMException(stderr=stderr) from e
specfile.exceptions.RPMException: Unable to open /tmp/rpm-specs/ansible-packaging.inc: No such file or directory
Error parsing linux-system-roles.spec

This seems to be because of:



  | # Includes with definitions/tags that differ between RHEL and Fedora
-- | --
  | Source1001: extrasources.inc
  |  
  | %include %{SOURCE1001}
  |  
  | # Includes with ansible_collection_build/_install that differ between RHEL versions
  | Source1002: ansible-packaging.inc
  |  
  | %include %{SOURCE1002}

The source1001 is created by 1002 not.

What did you expect to happen?

No response

Example URL(s)

No response

Steps to reproduce

1.
2.
3.

Workaround

Participation

nforro commented 1 year ago

Thanks, I can confirm this is a bug, it looks like macro context will have to be repopulated on each occurence of %include.

mfocko commented 4 months ago

Still relevant, not an easy fix.