Skip to content

Commit 0e6c405

Browse files
committed
frontend, rpmbuild: skip only if all macros in ExclusiveArch and ExcludeArch evaluated
Fix #3244 It can happen that our builder doesn't understand some architecture macro, e.g. `%{zig_arches}`. In such a case when it is used in `ExclusiveArch`, we shouldn't skip all chroots like we do now. A better approach is to be safe and avoid any skipping. Builds will fail in some chroots that should have been skipped but that can be workarounded by the user by manually submitting the build only for a subset of chroots.
1 parent 208d68b commit 0e6c405

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

frontend/coprs_frontend/coprs/logic/builds_logic.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,15 +1132,19 @@ def finish(chroot, status):
11321132

11331133
exclusivearch = upd_dict["results"].get("exclusivearch")
11341134
if exclusivearch and arch not in exclusivearch:
1135-
chroot.status_reason = \
1136-
"This chroot was skipped because of ExclusiveArch"
1137-
finish(chroot, StatusEnum("skipped"))
1135+
# Skip only if all macros in ExclusiveArch evaluated
1136+
if not [x for x in exclusivearch if x.startswith("%")]:
1137+
chroot.status_reason = \
1138+
"This chroot was skipped because of ExclusiveArch"
1139+
finish(chroot, StatusEnum("skipped"))
11381140

11391141
excludearch = upd_dict["results"].get("excludearch")
11401142
if arch in excludearch:
1141-
chroot.status_reason = \
1142-
"This chroot was skipped because of ExcludeArch"
1143-
finish(chroot, StatusEnum("skipped"))
1143+
# Skip only if all macros in ExcludeArch evaluated
1144+
if not [x for x in excludearch if x.startswith("%")]:
1145+
chroot.status_reason = \
1146+
"This chroot was skipped because of ExcludeArch"
1147+
finish(chroot, StatusEnum("skipped"))
11441148

11451149
cls.process_update_callback(build)
11461150
db.session.add(build)

frontend/coprs_frontend/tests/test_logic/test_builds_logic.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,3 +655,43 @@ def save_field(_field, file_path):
655655
build = models.Build.query.get(1)
656656
assert build.source_state == "succeeded"
657657
assert not os.path.exists(storage)
658+
659+
@pytest.mark.parametrize(
660+
"exclusivearch,states", [
661+
(["x86_64", "i386"], ["waiting", "waiting"]),
662+
(["x86_64"], ["waiting", "skipped"]),
663+
(["x86_64", "%{zig_arches}"], ["waiting", "waiting"]),
664+
([], ["waiting", "waiting"]),
665+
]
666+
)
667+
def test_skipping_chroots(self, exclusivearch, states, f_users, f_coprs,
668+
f_builds, f_mock_chroots, f_db):
669+
build = BuildsLogic.add(self.u2, "foo", self.c2)
670+
self.db.session.commit()
671+
assert len(build.chroots) == 0
672+
data = {
673+
"builds": [{
674+
"id": 5,
675+
"task_id": 5,
676+
"srpm_url": "http://foo",
677+
"status": 1,
678+
"pkg_name": "foo",
679+
"pkg_version": 1,
680+
"chroot": "srpm-builds",
681+
"results": {
682+
"epoch": None,
683+
"excludearch": [],
684+
"exclusivearch": exclusivearch,
685+
"name": "biosdevname",
686+
"release": "17",
687+
"version": "0.7.3"
688+
},
689+
}]
690+
}
691+
response = self.tc.post(
692+
"/backend/update/",
693+
headers=self.auth_header,
694+
json=data,
695+
)
696+
assert response.status_code == 200
697+
assert [x.state for x in build.build_chroots] == states

rpmbuild/copr_rpmbuild/helpers.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,22 @@ def exclusivearch(self):
428428
"""
429429
Evaluated %{exclusivearch} as a list
430430
"""
431-
return self.safe_attr("exclusivearch").split()
431+
values = self.safe_attr("exclusivearch").split()
432+
for macro in values:
433+
if macro.startswith("%"):
434+
log.warning("Unknown macro in ExclusiveArch: %s", macro)
435+
return values
432436

433437
@property
434438
def excludearch(self):
435439
"""
436440
Evaluated %{excludearch} as a list
437441
"""
438-
return self.safe_attr("excludearch").split()
442+
values = self.safe_attr("excludearch").split()
443+
for macro in values:
444+
if macro.startswith("%"):
445+
log.warning("Unknown macro in ExcludeArch: %s", macro)
446+
return values
439447

440448
def safe_attr(self, name):
441449
"""

0 commit comments

Comments
 (0)