Skip to content

Commit f40b02d

Browse files
authored
Merge pull request #83 from rabbitmq/simpilified-constraints
Simply the erlang version constraints into a single setting
2 parents 63d9994 + 83c451a commit f40b02d

File tree

3 files changed

+44
-53
lines changed

3 files changed

+44
-53
lines changed

repositories/BUILD_external.tpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ toolchain(
2626
exec_compatible_with = [
2727
"//:erlang_external",
2828
],
29-
target_compatible_with = [%{TARGET_COMPATIBLE_WITH}
29+
target_compatible_with = [
30+
"%{TARGET_COMPATIBLE_WITH}",
3031
],
3132
toolchain = ":erlang",
3233
toolchain_type = "%{RULES_ERLANG_WORKSPACE}//tools:toolchain_type",

repositories/BUILD_internal.tpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ toolchain(
2828
exec_compatible_with = [
2929
"//:erlang_internal",
3030
],
31-
target_compatible_with = [%{TARGET_COMPATIBLE_WITH}
31+
target_compatible_with = [
32+
"%{TARGET_COMPATIBLE_WITH}",
3233
],
3334
toolchain = ":erlang",
3435
toolchain_type = "%{RULES_ERLANG_WORKSPACE}//tools:toolchain_type",

repositories/erlang_config.bzl

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,10 @@ def _impl(repository_ctx):
4242
)
4343

4444
for (name, props) in erlang_installations.items():
45-
target_compatible_with = ["//:erlang_{}".format(props.major)]
4645
if props.minor != None:
47-
target_compatible_with.append(
48-
"//:erlang_{}_{}".format(props.major, props.minor),
49-
)
50-
target_compatible_with = "".join([
51-
"\n \"%s\"," % c
52-
for c in target_compatible_with
53-
])
46+
target_compatible_with = "//:erlang_{}_{}".format(props.major, props.minor)
47+
else:
48+
target_compatible_with = "//:erlang_{}".format(props.major)
5449

5550
if props.type == INSTALLATION_TYPE_EXTERNAL:
5651
repository_ctx.template(
@@ -199,6 +194,14 @@ def _default_erlang_dict(repository_ctx):
199194
def _build_file_content(erlang_installations):
200195
default_installation = erlang_installations[_DEFAULT_EXTERNAL_ERLANG_PACKAGE_NAME]
201196

197+
if default_installation.minor != None:
198+
default_identifier = "{}_{}".format(
199+
default_installation.major,
200+
default_installation.minor,
201+
)
202+
else:
203+
default_identifier = default_installation.major
204+
202205
build_file_content = """\
203206
load("@bazel_skylib//lib:selects.bzl", "selects")
204207
@@ -212,13 +215,8 @@ constraint_setting(
212215
)
213216
214217
constraint_setting(
215-
name = "erlang_major_version",
216-
default_constraint_value = ":erlang_{default_major}",
217-
)
218-
219-
constraint_setting(
220-
name = "erlang_major_minor_version",
221-
default_constraint_value = ":erlang_{default_major}_{default_minor}",
218+
name = "erlang_version",
219+
default_constraint_value = ":erlang_{default_identifier}",
222220
)
223221
224222
constraint_value(
@@ -227,8 +225,7 @@ constraint_value(
227225
)
228226
229227
""".format(
230-
default_major = default_installation.major,
231-
default_minor = default_installation.minor,
228+
default_identifier = default_identifier,
232229
)
233230

234231
external_installations = {
@@ -253,68 +250,60 @@ constraint_value(
253250
major_by_minors[props.major] = minors
254251

255252
for (major, minors) in major_by_minors.items():
256-
build_file_content += """\
253+
if len(minors) == 0:
254+
build_file_content += """\
257255
constraint_value(
258256
name = "erlang_{major}",
259-
constraint_setting = ":erlang_major_version",
260-
)
261-
262-
""".format(
263-
major = major,
264-
)
265-
if len(minors) > 0:
266-
constraints = [
267-
":erlang_{}_{}".format(major, minor)
268-
for minor in minors
269-
]
270-
271-
build_file_content += """\
272-
selects.config_setting_group(
273-
name = "erlang_{major}_any_minor",
274-
match_any = {constraints},
257+
constraint_setting = ":erlang_version",
275258
)
276259
277260
platform(
278261
name = "erlang_{major}_platform",
279262
constraint_values = [
280263
":erlang_{major}",
281-
":erlang_{major}_any_minor",
282264
],
283265
)
284266
285267
""".format(
286268
major = major,
287-
constraints = constraints,
288269
)
289270
else:
290-
build_file_content += """\
271+
constraints = []
272+
for minor in minors:
273+
constraints.append(
274+
":erlang_{}_{}".format(major, minor),
275+
)
276+
build_file_content += """\
277+
constraint_value(
278+
name = "erlang_{major}_{minor}",
279+
constraint_setting = ":erlang_version",
280+
)
281+
291282
platform(
292-
name = "erlang_{major}_platform",
283+
name = "erlang_{major}_{minor}_platform",
293284
constraint_values = [
294-
":erlang_{major}",
285+
":erlang_{major}_{minor}",
295286
],
296287
)
297288
298-
""".format(
299-
major = major,
300-
)
289+
""".format(major = major, minor = minor)
301290

302-
for minor in minors:
303-
if minor != None:
304-
build_file_content += """\
305-
constraint_value(
306-
name = "erlang_{major}_{minor}",
307-
constraint_setting = ":erlang_major_minor_version",
291+
build_file_content += """\
292+
selects.config_setting_group(
293+
name = "erlang_{major}",
294+
match_any = {constraints},
308295
)
309296
310297
platform(
311-
name = "erlang_{major}_{minor}_platform",
298+
name = "erlang_{major}_platform",
312299
constraint_values = [
313300
":erlang_{major}",
314-
":erlang_{major}_{minor}",
315301
],
316302
)
317303
318-
""".format(major = major, minor = minor)
304+
""".format(
305+
major = major,
306+
constraints = constraints,
307+
)
319308

320309
return build_file_content

0 commit comments

Comments
 (0)