Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions command_line_option/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ alias(
actual = "//python:none",
)

alias(
name = "extra_toolchains",
actual = "//python:none",
)

filegroup(
name = "distribution",
srcs = glob(["**"]),
Expand Down
23 changes: 23 additions & 0 deletions docs/api/rules_python/command_line_option/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,26 @@ See the [Bazel documentation for --enable_runfiles](https://bazel.build/referenc

The special value `INHERIT` can be specified to use the existing flag value.
:::

## extra_toolchains

:::{bzl:target} extra_toolchains

Special target for the Bazel-builtin `//command_line_option:extra_toolchains`
flag.

See the [Bazel documentation for --extra_toolchains](https://bazel.build/reference/command-line-reference#flag--extra_toolchains).

The special value `INHERIT` can be specified to use the existing flag value.

:::{note}
Unlike the normal Bazel built-in flag, which accepts a list of labels, this
pseudo-flag must be specified as a single, comma-separated string when set
using the `config_settings` attribute. For example:

```python
"//command_line_option:extra_toolchains": "//my/tc1,//my/tc2"
```
:::
:::

1 change: 1 addition & 0 deletions python/features.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def _features_typedef():
_TARGETS = {
"//command_line_option:build_runfile_links": True,
"//command_line_option:enable_runfiles": True,
"//command_line_option:extra_toolchains": True,
"//python/cc:current_py_cc_headers_abi3": True,
}

Expand Down
9 changes: 7 additions & 2 deletions python/private/attributes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,15 @@ def apply_config_settings_attr(settings, attr):
if key.package == "command_line_option":
if value == "INHERIT":
continue
else:
str_key = "//command_line_option:" + key.name
str_key = "//command_line_option:" + key.name
if key.name == "extra_toolchains":
if value == "":
value = []
else:
value = [v.strip() for v in value.split(",") if v.strip()]
else:
str_key = str(key)

settings[str_key] = value
return settings

Expand Down
1 change: 1 addition & 0 deletions python/private/common_labels.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ labels = struct(
# NOTE: Special target; see definition for details.
ENABLE_RUNFILES = str(Label("//command_line_option:enable_runfiles")),
EXEC_TOOLS_TOOLCHAIN = str(Label("//python/config_settings:exec_tools_toolchain")),
EXTRA_TOOLCHAINS = str(Label("//command_line_option:extra_toolchains")),
NONE = str(Label("//python:none")),
PIP_ENV_MARKER_CONFIG = str(Label("//python/config_settings:pip_env_marker_config")),
PIP_WHL_OSX_VERSION = str(Label("//python/config_settings:pip_whl_osx_version")),
Expand Down
1 change: 1 addition & 0 deletions python/private/transition_labels.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ _BASE_TRANSITION_LABELS = [
labels.BOOTSTRAP_IMPL,
labels.DEBUGGER,
labels.EXEC_TOOLS_TOOLCHAIN,
"//command_line_option:extra_toolchains",
Comment thread
rickeylev marked this conversation as resolved.
labels.PIP_ENV_MARKER_CONFIG,
labels.PIP_WHL_OSX_VERSION,
labels.PRECOMPILE,
Expand Down
23 changes: 23 additions & 0 deletions tests/base_rules/py_executable_base_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ def _test_basic_zip_impl(env, target):

_tests.append(_test_basic_zip)

def _test_config_settings_extra_toolchains(name, config):
rt_util.helper_target(
config.rule,
name = name + "_subject",
srcs = ["main.py"],
main = "main.py",
config_settings = {
"//command_line_option:extra_toolchains": "{tc},{tc}".format(tc = CC_TOOLCHAIN),
},
)
analysis_test(
name = name,
impl = _test_config_settings_extra_toolchains_impl,
target = name + "_subject",
)

def _test_config_settings_extra_toolchains_impl(env, target):
# If we got here, it means analysis succeeded, which implies the transition
# successfully parsed the CSV string into a list.
env.expect.that_target(target).has_provider(PyInfo)

_tests.append(_test_config_settings_extra_toolchains)

def _test_cross_compile_to_unix(name, config):
rt_util.helper_target(
config.rule,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/bzlmod_lockfile/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.