Skip to content

Commit 52d2b28

Browse files
committed
Ignore, but process, conditional macro expansions when updating Release
Flattening the nodes of parsed release string removes conditional macro expansions, so it's not possible to reconstruct them. Process them instead, but treat them as simple string literals, we don't need to process their bodies anyway. Signed-off-by: Nikola Forró <nforro@redhat.com>
1 parent 91a3951 commit 52d2b28

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

agents/tests/unit/test_tools.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,22 @@ async def run_and_check(spec, expected_release, error=False):
267267
await run_and_check(minimal_spec, "1%{?dist}" if rebase else "3%{?dist}")
268268
await run_and_check(autorelease_spec, "%autorelease")
269269

270+
with specfile.Specfile(minimal_spec) as spec:
271+
spec.raw_release = "5%{?alphatag:.%{alphatag}}%{?dist}.8"
272+
273+
if not dist_git_branch.startswith("rhel-"):
274+
await run_and_check(
275+
minimal_spec,
276+
(
277+
"1%{?alphatag:.%{alphatag}}%{?dist}"
278+
if rebase
279+
else "6%{?alphatag:.%{alphatag}}%{?dist}"
280+
),
281+
)
282+
else:
283+
await run_and_check(minimal_spec, "0%{?dist}.1" if rebase else "5%{?alphatag:.%{alphatag}}%{?dist}.9")
284+
await run_and_check(minimal_spec, "0%{?dist}.1" if rebase else "5%{?alphatag:.%{alphatag}}%{?dist}.10")
285+
270286

271287
@pytest.mark.asyncio
272288
async def test_get_cwd(tmp_path):

agents/tools/specfile.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ async def _get_latest_higher_stream_build(package: str, candidate_tag: str) -> E
164164
[build] = builds
165165
return EVR(epoch=build["epoch"] or 0, version=build["version"], release=build["release"])
166166

167-
@staticmethod
168-
def _parse_release(release: str) -> list[Node]:
169-
return list(ValueParser.flatten(ValueParser.parse(release)))
170-
171167
@staticmethod
172168
def _find_macro(name: str, nodes: list[Node]) -> int | None:
173169
for index, node in reversed(list(enumerate(nodes))):
@@ -182,7 +178,7 @@ def _find_macro(name: str, nodes: list[Node]) -> int | None:
182178
async def _bump_or_reset_release(cls, spec_path: Path, rebase: bool) -> None:
183179
with Specfile(spec_path) as spec:
184180
current_release = spec.raw_release
185-
nodes = cls._parse_release(current_release)
181+
nodes = ValueParser.parse(current_release)
186182

187183
autorelease_index = cls._find_macro("autorelease", nodes)
188184
dist_index = cls._find_macro("dist", nodes)
@@ -220,7 +216,7 @@ async def _set_zstream_release(
220216
higher_stream_base_release, _ = latest_higher_stream_build.release.rsplit(".el", maxsplit=1)
221217
with Specfile(spec_path) as spec:
222218
current_release = spec.raw_release
223-
nodes = cls._parse_release(current_release)
219+
nodes = ValueParser.parse(current_release)
224220

225221
autorelease_index = cls._find_macro("autorelease", nodes)
226222
dist_index = cls._find_macro("dist", nodes)

0 commit comments

Comments
 (0)