Skip to content

Commit

Permalink
Fix parsing of %prep macros
Browse files Browse the repository at this point in the history
Parsing of %prep macros was incorrect. For instance %patches macro
when used in %prep section was wrongly parsed as %patch macro.
This commit fixes that.

Signed-off-by: Nikola Forró <[email protected]>
  • Loading branch information
nforro committed Mar 19, 2024
1 parent 7ec87a9 commit 0e65e1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions specfile/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ def parse(cls, section: Section) -> "Prep":
m.group("d"),
m.group("o"),
)
if delimiter == "" and option_string != "":
# delimiter can't be empty unless the match is just base macro with no options
buffer.append(line)
continue
prefix += line[: m.start("m")]
suffix = line[m.end("o") :] + suffix
klass = next(
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/test_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ def test_prep_parse():
"prep",
data=[
"%setup -q",
"# a comment",
"# list all patches",
"echo %patches",
"%patch0 -p1",
"%{!?skip_patch2:%patch2 -p2}",
"",
],
)
)
assert len(prep.macros) == 3
assert prep.macros[0].name == "%setup"
assert prep.macros[0].options.q
assert prep.macros[1].name == "%patch0"
Expand Down Expand Up @@ -147,7 +149,7 @@ def test_prep_get_raw_section_data():
PatchMacro.DEFAULTS,
),
" ",
preceding_lines=["# a comment"],
preceding_lines=["# list all patches", "echo %patches"],
),
PatchMacro(
PatchMacro.CANONICAL_NAME + "2",
Expand All @@ -166,7 +168,8 @@ def test_prep_get_raw_section_data():
)
assert prep.get_raw_section_data() == [
"%setup -q",
"# a comment",
"# list all patches",
"echo %patches",
"%patch0 -p1",
"%{!?skip_patch2:%patch2 -p2}",
"",
Expand Down

0 comments on commit 0e65e1d

Please sign in to comment.