Skip to content

Commit

Permalink
Automated rollback of commit 332379a.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Broke Bazel downstream: https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/1039#72cf19a2-072a-4ca1-ace2-37c458ef8420

Fixes bazelbuild#8645.

*** Original change description ***

Add --incompatible_use_platforms_repo_for_constraints

This change adds an incompatible flag to disable constrains bundled with Bazel
in @bazel_tools.

Incompatible change issue:
bazelbuild#8622

Tracking issue:
bazelbuild#6516

RELNOTES: Incompatible change `--incompatible_use_platforms_repo_for_constraints` has been added. See bazelbuild#8622 f...

***

PiperOrigin-RevId: 253544711
  • Loading branch information
hlopko authored and irengrig committed Jun 18, 2019
1 parent e192491 commit 4485e63
Show file tree
Hide file tree
Showing 23 changed files with 223 additions and 416 deletions.
3 changes: 0 additions & 3 deletions scripts/bootstrap/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,6 @@ EOF
# Set up @bazel_tools//platforms properly
mkdir -p ${BAZEL_TOOLS_REPO}/platforms
cp tools/platforms/BUILD.tools ${BAZEL_TOOLS_REPO}/platforms/BUILD
link_file \
"${PWD}/tools/platforms/fail_with_incompatible_use_platforms_repo_for_constraints.bzl" \
"${BAZEL_TOOLS_REPO}/platforms/fail_with_incompatible_use_platforms_repo_for_constraints.bzl"

# Overwrite tools.WORKSPACE, this is only for the bootstrap binary
chmod u+w "${OUTPUT_DIR}/classes/com/google/devtools/build/lib/bazel/rules/tools.WORKSPACE"
Expand Down
29 changes: 14 additions & 15 deletions site/docs/platforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,36 +88,35 @@ glibc version of 2.25. (See below for more on Bazel's built-in constraints.)
platform(
name = "linux_x86",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
":glibc_2_25",
],
)
```

Note that it is an error for a platform to specify more than one value of the
same constraint setting, such as `@platforms//cpu:x86_64` and
`@platforms//cpu:arm` for `@platforms//cpu:cpu`.
same constraint setting, such as `@bazel_tools//platforms:x86_64` and
`@bazel_tools//platforms:arm` for `@bazel_tools//platforms:cpu`.

## Built-in constraints and platforms

Bazel ships with constraint definitions for the most popular CPU architectures
and operating systems. These are all located in the repository
`@platforms`. This repository is developed at
[github.com/bazelbuild/platforms](https://github.com/bazelbuild/platforms):
and operating systems. These are all located in the package
`@bazel_tools//platforms`:

* `//cpu:cpu` for the CPU architecture, with values `//cpu:x86_32`,
`//cpu:x86_64`, `//cpu:ppc`, `//cpu:arm`, `//cpu:s390x`
* `//os:os` for the operating system, with values `//os:android`,
`//os:freebsd`, `//os:ios`, `//os:linux`, `//os:osx`, `//os:windows`
* `:cpu` for the CPU architecture, with values `:x86_32`, `:x86_64`, `:ppc`,
`:arm`, `:s390x`
* `:os` for the operating system, with values `:android`, `:freebsd`, `:ios`,
`:linux`, `:osx`, `:windows`

There are also the following special platform definitions:

* `@bazel_tools//platforms:host_platform` - represents the CPU and operating
system for the host environment
* `:host_platform` - represents the CPU and operating system for the host
environment

* `@bazel_tools//platforms:target_platform` - represents the CPU and operating
system for the target environment
* `:target_platform` - represents the CPU and operating system for the target
environment

The CPU values used by these two platforms can be specified with the
`--host_cpu` and `--cpu` flags.
Expand Down
24 changes: 12 additions & 12 deletions site/docs/toolchains.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ We can improve on this solution by using `select` to choose the `compiler`
config_setting(
name = "on_linux",
constraint_values = [
"@platforms//os:linux",
"@bazel_tools//platforms:linux",
],
)

config_setting(
name = "on_windows",
constraint_values = [
"@platforms//os:windows",
"@bazel_tools//platforms:windows",
],
)

Expand Down Expand Up @@ -276,12 +276,12 @@ appropriate for a given platform.
toolchain(
name = "barc_linux_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
],
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
],
toolchain = ":barc_linux",
toolchain_type = ":toolchain_type",
Expand All @@ -290,12 +290,12 @@ toolchain(
toolchain(
name = "barc_windows_toolchain",
exec_compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
"@bazel_tools//platforms:windows",
"@bazel_tools//platforms:x86_64",
],
target_compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
"@bazel_tools//platforms:windows",
"@bazel_tools//platforms:x86_64",
],
toolchain = ":barc_windows",
toolchain_type = ":toolchain_type",
Expand Down Expand Up @@ -336,7 +336,7 @@ toolchain will be selected based on the target and execution platforms.
platform(
name = "my_target_platform",
constraint_values = [
"@platforms//os:linux",
"@bazel_tools//platforms:linux",
],
)

Expand All @@ -351,7 +351,7 @@ bazel build //my_pkg:my_bar_binary --platforms=//my_pkg:my_target_platform
```

Bazel will see that `//my_pkg:my_bar_binary` is being built with a platform that
has `@platforms//os:linux` and therefore resolve the
has `@bazel_tools//platforms:linux` and therefore resolve the
`//bar_tools:toolchain_type` reference to `//bar_tools:barc_linux_toolchain`.
This will end up building `//bar_tools:barc_linux` but not
`//barc_tools:barc_windows`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@ public class CoreOptions extends FragmentOptions implements Cloneable {
help = "If true, the genfiles directory is folded into the bin directory.")
public boolean mergeGenfilesDirectory;

@Option(
name = "incompatible_use_platforms_repo_for_constraints",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help = "If true, constraint settings from @bazel_tools are removed.")
public boolean usePlatformsRepoForConstraints;

@Option(
name = "define",
converter = Converters.AssignmentConverter.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ public RepositoryDirectoryValue.Builder fetch(
static String cpuToConstraint(CPU cpu) {
switch (cpu) {
case X86_32:
return "@platforms//cpu:x86_32";
return "@bazel_tools//platforms:x86_32";
case X86_64:
return "@platforms//cpu:x86_64";
return "@bazel_tools//platforms:x86_64";
case PPC:
return "@platforms//cpu:ppc";
return "@bazel_tools//platforms:ppc";
case ARM:
return "@platforms//cpu:arm";
return "@bazel_tools//platforms:arm";
case AARCH64:
return "@platforms//cpu:aarch64";
return "@bazel_tools//platforms:aarch64";
case S390X:
return "@platforms//cpu:s390x";
return "@bazel_tools//platforms:s390x";
default:
// Unknown, so skip it.
return null;
Expand All @@ -102,13 +102,13 @@ static String cpuToConstraint(CPU cpu) {
static String osToConstraint(OS os) {
switch (os) {
case DARWIN:
return "@platforms//os:osx";
return "@bazel_tools//platforms:osx";
case FREEBSD:
return "@platforms//os:freebsd";
return "@bazel_tools//platforms:freebsd";
case LINUX:
return "@platforms//os:linux";
return "@bazel_tools//platforms:linux";
case WINDOWS:
return "@platforms//os:windows";
return "@bazel_tools//platforms:windows";
default:
// Unknown, so skip it.
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Matches an expected configuration state (expressed as Bazel flags or platform co
config_setting(
name = "64bit_glibc_2_25",
constraint_values = [
"@platforms//cpu:x86_64",
"@bazel_tools//platforms:x86_64",
"//example:glibc_2_25",
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public RuleDefinition.Metadata getMetadata() {
<p>Each <code>constraint_setting</code> has an extensible set of associated
<code>constraint_value</code>s. Usually these are defined in the same package, but sometimes a
different package will introduce new values for an existing setting. For instance, the predefined
setting <code>@platforms//cpu:cpu</code> can be extended with a custom value in order to
setting <code>@bazel_tools//platforms:cpu</code> can be extended with a custom value in order to
define a platform targeting an obscure cpu architecture.
<!-- #END_BLAZE_RULE -->*/
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Metadata getMetadata() {
<pre class="code">
constraint_value(
name = "mips",
constraint_setting = "@platforms//cpu:cpu",
constraint_setting = "@bazel_tools//platforms:cpu",
)
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
<p>Each <code>constraint_value</code> in this list must be for a different
<code>constraint_setting</code>. For example, you cannot define a platform that requires the
cpu architecture to be both <code>@platforms//cpu:x86_64</code> and
cpu architecture to be both <code>@bazel_tools//platforms:x86_64</code> and
<code>@bazel_tools//platforms:arm</code>.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(
Expand Down Expand Up @@ -130,8 +130,8 @@ public Metadata getMetadata() {
platform(
name = "linux_arm",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:arm",
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:arm",
],
)
</pre>
Expand Down Expand Up @@ -177,8 +177,8 @@ public Metadata getMetadata() {
platform(
name = "parent",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:arm",
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:arm",
],
remote_execution_properties = """
parent properties
Expand All @@ -188,7 +188,7 @@ public Metadata getMetadata() {
name = "child_a",
parents = [":parent"],
constraint_values = [
"@platforms//cpu:x86_64",
"@bazel_tools//platforms:x86_64",
],
remote_execution_properties = """
child a properties
Expand All @@ -210,8 +210,8 @@ public Metadata getMetadata() {
<ul>
<li>
"child_a" has the constraint values "@platforms//os:linux" (inherited from the
parent) and "@platforms//cpu:x86_64" (set directly on the platform). It has the
"child_a" has the constraint values "@bazel_tools//platforms:linux" (inherited from the
parent) and "@bazel_tools//platforms:x86_64" (set directly on the platform). It has the
"remote_execution_properties" set to "child a properties"
</li>
<li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ private BazelAnalysisMock() {
@Override
public List<String> getWorkspaceContents(MockToolsConfig config) {
String bazelToolWorkspace = config.getPath("/bazel_tools_workspace").getPathString();
String bazelPlatformsWorkspace = config.getPath("/platforms").getPathString();
String localConfigPlatformWorkspace =
config.getPath("/local_config_platform_workspace").getPathString();

return new ArrayList<>(
ImmutableList.of(
"local_repository(name = 'bazel_tools', path = '" + bazelToolWorkspace + "')",
"local_repository(name = 'platforms', path = '" + bazelPlatformsWorkspace + "')",
"local_repository(name = 'local_config_xcode', path = '/local_config_xcode')",
"local_repository(name = 'com_google_protobuf', path = '/protobuf')",
"bind(name = 'android/sdk', actual='@bazel_tools//tools/android:sdk')",
Expand All @@ -101,25 +99,6 @@ public void setupMockClient(MockToolsConfig config, List<String> workspaceConten
config.create("/local_config_xcode/WORKSPACE");
config.create("/protobuf/WORKSPACE");
config.overwrite("WORKSPACE", workspaceContents.toArray(new String[workspaceContents.size()]));
config.create("/platforms/WORKSPACE", "workspace(name = 'platforms')");
config.create("/platforms/BUILD");
config.create(
"/platforms/cpu/BUILD",
"constraint_setting(name = 'cpu')",
"constraint_value(name = 'x86_32', constraint_setting = ':cpu')",
"constraint_value(name = 'x86_64', constraint_setting = ':cpu')",
"constraint_value(name = 'ppc', constraint_setting = ':cpu')",
"constraint_value(name = 'arm', constraint_setting = ':cpu')",
"constraint_value(name = 'aarch64', constraint_setting = ':cpu')",
"constraint_value(name = 's390x', constraint_setting = ':cpu')");

config.create(
"/platforms/os/BUILD",
"constraint_setting(name = 'os')",
"constraint_value(name = 'linux', constraint_setting = ':os')",
"constraint_value(name = 'osx', constraint_setting = ':os')",
"constraint_value(name = 'freebsd', constraint_setting = ':os')",
"constraint_value(name = 'windows', constraint_setting = ':os')");
config.create("/bazel_tools_workspace/WORKSPACE", "workspace(name = 'bazel_tools')");
Runfiles runfiles = Runfiles.create();
for (String filename :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public static class CpuConstraintTest {
public static Collection createInputValues() {
return ImmutableList.of(
// CPU value tests.
new Object[] {CPU.X86_64, "@platforms//cpu:x86_64"},
new Object[] {CPU.X86_32, "@platforms//cpu:x86_32"},
new Object[] {CPU.PPC, "@platforms//cpu:ppc"},
new Object[] {CPU.ARM, "@platforms//cpu:arm"},
new Object[] {CPU.AARCH64, "@platforms//cpu:aarch64"},
new Object[] {CPU.S390X, "@platforms//cpu:s390x"});
new Object[] {CPU.X86_64, "@bazel_tools//platforms:x86_64"},
new Object[] {CPU.X86_32, "@bazel_tools//platforms:x86_32"},
new Object[] {CPU.PPC, "@bazel_tools//platforms:ppc"},
new Object[] {CPU.ARM, "@bazel_tools//platforms:arm"},
new Object[] {CPU.AARCH64, "@bazel_tools//platforms:aarch64"},
new Object[] {CPU.S390X, "@bazel_tools//platforms:s390x"});
}

private final CPU testCpu;
Expand Down Expand Up @@ -81,10 +81,10 @@ public static class OsConstraintTest {
public static Collection createInputValues() {
return ImmutableList.of(
// OS value tests.
new Object[] {OS.LINUX, "@platforms//os:linux"},
new Object[] {OS.DARWIN, "@platforms//os:osx"},
new Object[] {OS.FREEBSD, "@platforms//os:freebsd"},
new Object[] {OS.WINDOWS, "@platforms//os:windows"});
new Object[] {OS.LINUX, "@bazel_tools//platforms:linux"},
new Object[] {OS.DARWIN, "@bazel_tools//platforms:osx"},
new Object[] {OS.FREEBSD, "@bazel_tools//platforms:freebsd"},
new Object[] {OS.WINDOWS, "@bazel_tools//platforms:windows"});
}

private final OS testOs;
Expand Down Expand Up @@ -112,9 +112,9 @@ public void unknownOsConstraint() {
@RunWith(JUnit4.class)
public static class FunctionTest extends BuildViewTestCase {
private static final ConstraintSettingInfo CPU_CONSTRAINT =
ConstraintSettingInfo.create(Label.parseAbsoluteUnchecked("@platforms//cpu:cpu"));
ConstraintSettingInfo.create(Label.parseAbsoluteUnchecked("@bazel_tools//platforms:cpu"));
private static final ConstraintSettingInfo OS_CONSTRAINT =
ConstraintSettingInfo.create(Label.parseAbsoluteUnchecked("@platforms//os:os"));
ConstraintSettingInfo.create(Label.parseAbsoluteUnchecked("@bazel_tools//platforms:os"));

@Test
public void generateConfigRepository() throws Exception {
Expand Down
7 changes: 0 additions & 7 deletions src/test/shell/bazel/platforms_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,5 @@ EOF
fail "Bazel failed to build @platforms"
}

function test_incompatible_use_platforms_repo_for_constraints() {
# We test that a built-in @platforms repository is buildable.
bazel build --incompatible_use_platforms_repo_for_constraints @bazel_tools//platforms:all &> \
$TEST_log && fail "Build passed when we expected an error."
expect_log "Constraints from @bazel_tools//platforms have been removed."
}

run_suite "platform mapping test"

2 changes: 1 addition & 1 deletion src/test/shell/integration/discard_graph_edges_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function test_packages_cleared() {
package_count="$(extract_histogram_count "$histo_file" \
'devtools\.build\.lib\..*\.Package$')"
# A few packages aren't cleared.
[[ "$package_count" -le 18 ]] \
[[ "$package_count" -le 17 ]] \
|| fail "package count $package_count too high"
glob_count="$(extract_histogram_count "$histo_file" "GlobValue$")"
[[ "$glob_count" -le 1 ]] \
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/testenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ toolchain(
name = "py_toolchain",
toolchain = ":py_runtime_pair",
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
target_compatible_with = ["@platforms//os:windows"],
target_compatible_with = ["@bazel_tools//platforms:windows"],
)
EOF
}
Expand Down
Loading

0 comments on commit 4485e63

Please sign in to comment.