File tree Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Original file line number Diff line number Diff line change 1111 "PrecompileSourceRetentionFlag" ,
1212 "VenvsSitePackages" ,
1313 "VenvsUseDeclareSymlinkFlag" ,
14+ rp_string_flag = "string_flag" ,
1415)
1516load (
1617 "//python/private/pypi:flags.bzl" ,
@@ -87,14 +88,27 @@ string_flag(
8788 visibility = ["//visibility:public" ],
8889)
8990
90- string_flag (
91+ rp_string_flag (
9192 name = "bootstrap_impl" ,
92- build_setting_default = BootstrapImplFlag .SYSTEM_PYTHON ,
93+ build_setting_default = BootstrapImplFlag .SCRIPT ,
94+ override = select ({
95+ # Windows doesn't yet support bootstrap=script, so force disable it
96+ ":_is_windows" : BootstrapImplFlag .SYSTEM_PYTHON ,
97+ "//conditions:default" : "" ,
98+ }),
9399 values = sorted (BootstrapImplFlag .__members__ .values ()),
94100 # NOTE: Only public because it's an implicit dependency
95101 visibility = ["//visibility:public" ],
96102)
97103
104+ # For some reason, @platforms//os:windows can't be directly used
105+ # in the select() for the flag. But it can be used when put behind
106+ # a config_setting().
107+ config_setting (
108+ name = "_is_windows" ,
109+ constraint_values = ["@platforms//os:windows" ],
110+ )
111+
98112# This is used for pip and hermetic toolchain resolution.
99113string_flag (
100114 name = "py_linux_libc" ,
Original file line number Diff line number Diff line change @@ -35,8 +35,38 @@ AddSrcsToRunfilesFlag = FlagEnum(
3535 is_enabled = _AddSrcsToRunfilesFlag_is_enabled ,
3636)
3737
38+ def _string_flag_impl (ctx ):
39+ if ctx .attr .override :
40+ value = ctx .attr .override
41+ else :
42+ value = ctx .build_setting_value
43+
44+ if value not in ctx .attr .values :
45+ fail ((
46+ "Invalid value for {name}: got {value}, must " +
47+ "be one of {allowed}"
48+ ).format (
49+ name = ctx .label ,
50+ value = value ,
51+ allowed = ctx .attr .values ,
52+ ))
53+
54+ return [
55+ BuildSettingInfo (value = value ),
56+ config_common .FeatureFlagInfo (value = value ),
57+ ]
58+
59+ string_flag = rule (
60+ implementation = _string_flag_impl ,
61+ build_setting = config .string (flag = True ),
62+ attrs = {
63+ "override" : attr .string (),
64+ "values" : attr .string_list (),
65+ },
66+ )
67+
3868def _bootstrap_impl_flag_get_value (ctx ):
39- return ctx .attr ._bootstrap_impl_flag [BuildSettingInfo ].value
69+ return ctx .attr ._bootstrap_impl_flag [config_common . FeatureFlagInfo ].value
4070
4171# buildifier: disable=name-conventions
4272BootstrapImplFlag = enum (
You can’t perform that action at this time.
0 commit comments