Skip to content

Commit f27dd23

Browse files
committed
Add mechanism for specifying configure options per branch
1 parent 2733039 commit f27dd23

2 files changed

Lines changed: 84 additions & 2 deletions

File tree

master/custom/factories.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def setup(self, branch, worker, test_with_PTY=False, **kwargs):
119119
oot_kwargs = {}
120120
configure_cmd = [configure_cmd, "--prefix", "$(PWD)/target"]
121121
configure_cmd += self.configureFlags
122+
configure_cmd += worker.get_flags(branch, "configure")
122123
self.addStep(
123124
Configure(command=configure_cmd, **oot_kwargs)
124125
)
@@ -225,6 +226,7 @@ def setup(self, branch, worker, test_with_PTY=False, **kwargs):
225226
Configure(
226227
command=["./configure", "--prefix", "$(PWD)/target"]
227228
+ self.configureFlags
229+
+ worker.get_flags(branch, "configure")
228230
)
229231
)
230232

@@ -620,17 +622,23 @@ class BaseWindowsBuild(BaseBuild):
620622
factory_tags = ["win32"]
621623

622624
def setup(self, branch, worker, **kwargs):
623-
build_command = self.build_command + self.buildFlags
625+
build_command = (
626+
self.build_command
627+
+ self.buildFlags
628+
+ worker.get_flags(branch, "build")
629+
)
624630
test_command = [
625631
*self.test_command,
626632
*self.testFlags,
633+
*worker.get_flags(branch, "test"),
627634
*get_j_opts(worker, 2),
628635
]
629636
if not has_option("-R", self.testFlags):
630637
test_command.extend((r"--junit-xml", JUNIT_FILENAME))
631638
clean_command = [
632639
*self.clean_command,
633640
*self.cleanFlags,
641+
*worker.get_flags(branch, "clean"),
634642
*get_j_opts(worker),
635643
]
636644
self.addStep(Compile(command=build_command))
@@ -819,6 +827,7 @@ def setup(self, branch, worker, test_with_PTY=False, **kwargs):
819827
configure_cmd = list(self.host_configure_cmd)
820828
configure_cmd += ["--prefix", "$(PWD)/target/host"]
821829
configure_cmd += self.configureFlags + self.extra_configure_flags
830+
configure_cmd += worker.get_flags(branch, "configure")
822831
configure_cmd += [util.Interpolate("--build=%(prop:build_triple)s")]
823832
configure_cmd += [f"--host={self.host}"]
824833
configure_cmd += ["--with-build-python=../build/python"]
@@ -1142,6 +1151,7 @@ def py313_setup(self, branch, worker, test_with_PTY=False, **kwargs):
11421151
configure_cmd = list(self.host_configure_cmd)
11431152
configure_cmd += self.configureFlags
11441153
configure_cmd += self.extra_configure_flags
1154+
configure_cmd += worker.get_flags(branch, "configure")
11451155
configure_cmd += [
11461156
f"--with-openssl={support_path}/openssl",
11471157
f"--build={self.arch}-apple-darwin",
@@ -1361,7 +1371,11 @@ class ValgrindBuild(UnixBuild):
13611371
def setup(self, branch, worker, **kwargs):
13621372
self.addStep(
13631373
Configure(
1364-
command=["./configure", "--prefix", "$(PWD)/target"] + self.configureFlags
1374+
command=(
1375+
["./configure", "--prefix", "$(PWD)/target"]
1376+
+ self.configureFlags
1377+
+ worker.get_flags(branch, "configure")
1378+
)
13651379
)
13661380
)
13671381

master/custom/workers.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,64 @@
2222
KEEPALIVE = 60
2323

2424

25+
class BranchWorkerFlags:
26+
def __init__(
27+
self,
28+
*,
29+
branches=None,
30+
min_branch=None,
31+
max_branch=None,
32+
configure=(),
33+
build=(),
34+
test=(),
35+
clean=(),
36+
):
37+
if isinstance(branches, str):
38+
self.branches = (branches,)
39+
elif branches is not None:
40+
self.branches = tuple(branches)
41+
else:
42+
self.branches = None
43+
self.min_branch = min_branch
44+
self.max_branch = max_branch
45+
self.configure = self._as_tuple(configure)
46+
self.build = self._as_tuple(build)
47+
self.test = self._as_tuple(test)
48+
self.clean = self._as_tuple(clean)
49+
50+
@staticmethod
51+
def _as_tuple(flags):
52+
if isinstance(flags, str):
53+
return (flags,)
54+
return tuple(flags)
55+
56+
def applies_to(self, branch):
57+
if self.branches is not None and branch.name not in self.branches:
58+
return False
59+
60+
if self.min_branch is None and self.max_branch is None:
61+
return True
62+
63+
if branch.version_tuple is None:
64+
return False
65+
if self.min_branch is not None and branch.version_tuple < self.min_branch:
66+
return False
67+
if self.max_branch is not None and branch.version_tuple > self.max_branch:
68+
return False
69+
return True
70+
71+
def get(self, kind):
72+
if kind == "configure":
73+
return self.configure
74+
if kind == "build":
75+
return self.build
76+
if kind == "test":
77+
return self.test
78+
if kind == "clean":
79+
return self.clean
80+
raise ValueError(f"Unknown branch worker flag kind: {kind}")
81+
82+
2583
class CPythonWorker:
2684
def __init__(
2785
self,
@@ -30,6 +88,7 @@ def __init__(
3088
tags=None,
3189
branches=None,
3290
not_branches=None,
91+
branch_flags=(),
3392
parallel_builders=1,
3493
parallel_tests=None,
3594
timeout_factor=1,
@@ -40,6 +99,7 @@ def __init__(
4099
self.tags = tags or set()
41100
self.branches = branches
42101
self.not_branches = not_branches
102+
self.branch_flags = tuple(branch_flags)
43103
self.parallel_tests = parallel_tests
44104
self.timeout_factor = timeout_factor
45105
self.exclude_test_resources = exclude_test_resources or []
@@ -62,6 +122,14 @@ def __init__(
62122
max_builds=parallel_builders,
63123
)
64124

125+
def get_flags(self, branch, kind):
126+
flags = []
127+
for rule in self.branch_flags:
128+
if rule.applies_to(branch):
129+
flags.extend(rule.get(kind))
130+
return flags
131+
132+
65133
# Some of Itamar's workers are reprovisioned every Wednesday at 9am PT.
66134
# Builds scheduled between 8am - 10am PT on Wednesdays will be delayed to
67135
# 10am PT.

0 commit comments

Comments
 (0)