Skip to content

Commit 85bbb84

Browse files
committed
wip cleanup
1 parent 6bd0de0 commit 85bbb84

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

python/private/config_settings.bzl

+21-10
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ def is_python_config_setting(name, *, python_version, match_any = None, **kwargs
7878
Args:
7979
name: name for the target that will be created to be used in select statements.
8080
python_version: The python_version to be passed in the `flag_values` in the `config_setting`.
81-
match_any: The labels that should be used for matching the extra versions instead of creating
82-
them on the fly. This will be passed to `config_setting_group.match_any`. This can be
83-
either None, which will create config settings necessary to match the `python_version` value,
84-
a list of 'config_setting' labels passed to bazel-skylib's `config_setting_group` `match_any`
85-
attribute.
81+
match_any: The labels that should be used for matching the extra
82+
versions, which get passed to `config_setting_group.match_any`. If
83+
empty or None, this macro will create config settings necessary to
84+
match the `python_version` value.
8685
**kwargs: extra kwargs passed to the `config_setting`.
8786
"""
8887
if python_version not in name:
@@ -96,24 +95,30 @@ def is_python_config_setting(name, *, python_version, match_any = None, **kwargs
9695
}
9796

9897
python_versions = VERSION_FLAG_VALUES[python_version]
99-
if len(python_versions) == 1:
98+
if len(python_versions) == 1 and not match_any:
10099
native.config_setting(
101100
name = name,
102101
flag_values = flag_values,
103102
**kwargs
104103
)
105104
return
106105

107-
if match_any:
108-
create_config_settings = {"_" + name: flag_values}
109-
else:
106+
if not match_any:
110107
create_config_settings = {
111108
"_{}".format(name).replace(python_version, version): {_PYTHON_VERSION_FLAG: version}
112109
for version in python_versions
113110
}
114111
match_any = list(create_config_settings.keys())
112+
else:
113+
setting_name = "_" + name if len(python_versions) > 1 else name
114+
create_config_settings = {setting_name: flag_values}
115+
if setting_name not in match_any:
116+
# Here we expect the user to supply us with a name of the label that
117+
# would be created by this function. This needs to be the case because
118+
# the VERSION_FLAG_VALUES values contain the all of the versions that
119+
# have to be matched.
120+
fail("'{}' must be present in 'match_any'".format(setting_name))
115121

116-
# Create all of the necessary config setting values for the config_setting_group
117122
for name_, flag_values_ in create_config_settings.items():
118123
native.config_setting(
119124
name = name_,
@@ -170,6 +175,12 @@ def construct_config_settings(name = None): # buildifier: disable=function-docs
170175
is_python_config_setting(
171176
name = "is_python_{}".format(version),
172177
python_version = version,
178+
# NOTE @aignas 2024-03-16: if we don't have this, then we may create duplicate
179+
# targets. I think this should be improved, but I haven't figured out how yet
180+
# and I ran out of time.
181+
#
182+
# The fact that this parameter is needed here, suggests that we may need to
183+
# think of a better abstraction here.
173184
match_any = match_any,
174185
visibility = ["//visibility:public"],
175186
)

0 commit comments

Comments
 (0)