commit | 8404fb4c7b6cb698cdc95a2e360e19341fdc365e | [log] [tgz] |
---|---|---|
author | John Millikin <john@john-millikin.com> | Tue Nov 05 09:39:40 2019 -0800 |
committer | Copybara-Service <copybara-worker@google.com> | Tue Nov 05 09:40:51 2019 -0800 |
tree | 9e3582a637afa2b758eeb70c6f31d236aa8d4ae0 | |
parent | 1199813a2353629b5a7605ac4b6ac54319cfce1d [diff] |
Avoid breaking toolchain resolution if platform has defaulted constraint. ### Summary See https://github.com/bazelbuild/bazel/issues/8778 and https://github.com/bazelbuild/bazel/issues/8274 for context / motivation. In summary, the presence of a `constraint_setting` with `default_constraint_value` in a Platform's constraints will cause toolchain resolution to break for all toolchains that do not explicitly set that constraint value. This makes `default_constraint_value` dangerous because setting it can break other rulesets composed into the same top-level workspace. cc @jayconrod @m3rcuriel @katre ### Test Plan I updated the unit test `SingleToolchainResolutionFunction`, verified it failed, then altered the implementation to pass. I also built `//src:bazel` and ran it with a test workspace to verify the end result worked as expected. Test workspace: ``` $ cat WORKSPACE register_toolchains("//:my_toolchain") $ cat BUILD load(":rules.bzl", "my_toolchain_info", "my_rule") my_rule(name = "hello") toolchain_type(name = "my_toolchain_type") my_toolchain_info(name = "my_toolchain_info") toolchain( name = "my_toolchain", toolchain = "//:my_toolchain_info", toolchain_type = "//:my_toolchain_type", ) constraint_setting( name = "setting", default_constraint_value = ":value_a", ) constraint_value( name = "value_a", constraint_setting = ":setting", ) constraint_value( name = "value_b", constraint_setting = ":setting", ) platform( name = "platform_a", constraint_values = ["//:value_a"], ) platform( name = "platform_b", constraint_values = ["//:value_b"], ) $ cat rules.bzl def _my_toolchain_info(ctx): return platform_common.ToolchainInfo() my_toolchain_info = rule(_my_toolchain_info) def _my_rule(ctx): pass my_rule = rule(_my_rule, toolchains = ["//:my_toolchain_type"]) ``` Before: ``` $ bazel build --toolchain_resolution_debug --host_platform=//:platform_b //:hello [...] INFO: ToolchainResolution: Looking for toolchain of type //:my_toolchain_type... INFO: ToolchainResolution: Considering toolchain //:my_toolchain_info... INFO: ToolchainResolution: Toolchain constraint //:setting has value //:value_a, which does not match value //:value_b from the target platform //:platform_b INFO: ToolchainResolution: Rejected toolchain //:my_toolchain_info, because of target platform mismatch INFO: ToolchainResolution: No toolchains found ERROR: While resolving toolchains for target //:hello: no matching toolchains found for types //:my_toolchain_type ``` After: ``` $ bazel build --toolchain_resolution_debug --host_platform=//:platform_b //:hello [...] INFO: ToolchainResolution: Looking for toolchain of type //:my_toolchain_type... INFO: ToolchainResolution: Considering toolchain //:my_toolchain_info... INFO: ToolchainResolution: For toolchain type //:my_toolchain_type, possible execution platforms and toolchains: {//:platform_b -> //:my_toolchain_info} INFO: ToolchainResolution: Selected execution platform //:platform_b, type //:my_toolchain_type -> toolchain //:my_toolchain_info INFO: ToolchainResolution: Selected execution platform //:platform_b, INFO: Analyzed target //:hello (9 packages loaded, 27 targets configured). [...] ``` Closes #10102. PiperOrigin-RevId: 278645171
{Fast, Correct} - Choose two
Build and test software of any size, quickly and reliably.
Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.
One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.
Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.
Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.
Follow our tutorials:
See CONTRIBUTING.md