Skip to content

Commit

Permalink
Add --incompatible_use_platforms_repo_for_constraints
Browse files Browse the repository at this point in the history
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 for details.
  • Loading branch information
hlopko committed Jun 13, 2019
1 parent 324dc44 commit 8e27297
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ 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
7 changes: 7 additions & 0 deletions src/test/shell/bazel/platforms_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,12 @@ 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"

153 changes: 104 additions & 49 deletions tools/platforms/BUILD
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Standard constraint_setting and constraint_values to be used in platforms.
load(":fail_with_incompatible_use_platforms_repo_for_constraints.bzl", "fail_with_incompatible_use_platforms_repo_for_constraints")

package(
default_visibility = ["//visibility:public"],
)

fail_with_incompatible_use_platforms_repo_for_constraints(
name = "fail_with_incompatible_use_platforms_repo_for_constraints",
)

filegroup(
name = "package-srcs",
srcs = [
Expand All @@ -16,70 +20,121 @@ filegroup(
srcs = glob(["**"]),
)

# These match values in //src/main/java/com/google/devtools/build/lib/util:CPU.java
constraint_setting(name = "cpu")
config_setting(
name = "using_platforms_not_bazel_tools",
values = {"incompatible_use_platforms_repo_for_constraints": "true"},
)

alias(
name = "cpu",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//cpu:cpu",
}),
)

constraint_value(
alias(
name = "x86_32",
constraint_setting = ":cpu",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//cpu:x86_32",
}),
)

constraint_value(
alias(
name = "x86_64",
constraint_setting = ":cpu",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//cpu:x86_64",
}),
)

constraint_value(
alias(
name = "ppc",
constraint_setting = ":cpu",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//cpu:ppc",
}),
)

constraint_value(
alias(
name = "arm",
constraint_setting = ":cpu",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//cpu:arm",
}),
)

constraint_value(
alias(
name = "aarch64",
constraint_setting = ":cpu",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//cpu:aarch64",
}),
)

constraint_value(
alias(
name = "s390x",
constraint_setting = ":cpu",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//cpu:s390x",
}),
)

# These match values in //src/main/java/com/google/devtools/build/lib/util:OS.java
constraint_setting(name = "os")
alias(
name = "os",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//os:os",
}),
)

constraint_value(
alias(
name = "osx",
constraint_setting = ":os",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//os:osx",
}),
)

constraint_value(
alias(
name = "ios",
constraint_setting = ":os",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//os:ios",
}),
)

constraint_value(
alias(
name = "freebsd",
constraint_setting = ":os",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//os:freebsd",
}),
)

constraint_value(
alias(
name = "android",
constraint_setting = ":os",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//os:android",
}),
)

constraint_value(
alias(
name = "linux",
constraint_setting = ":os",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//os:linux",
}),
)

constraint_value(
alias(
name = "windows",
constraint_setting = ":os",
actual = select({
":using_platforms_not_bazel_tools": ":fail_with_incompatible_use_platforms_repo_for_constraints",
"//conditions:default": "@platforms//os:windows",
}),
)

# A default platform with nothing defined.
Expand All @@ -92,19 +147,19 @@ platform(
constraint_values = [
],
cpu_constraints = [
":x86_32",
":x86_64",
":ppc",
":arm",
":aarch64",
":s390x",
"@platforms//cpu:x86_32",
"@platforms//cpu:x86_64",
"@platforms//cpu:ppc",
"@platforms//cpu:arm",
"@platforms//cpu:aarch64",
"@platforms//cpu:s390x",
],
host_platform = True,
os_constraints = [
":osx",
":freebsd",
":linux",
":windows",
"@platforms//os:osx",
"@platforms//os:freebsd",
"@platforms//os:linux",
"@platforms//os:windows",
],
)

Expand All @@ -113,18 +168,18 @@ platform(
constraint_values = [
],
cpu_constraints = [
":x86_32",
":x86_64",
":ppc",
":arm",
":aarch64",
":s390x",
"@platforms//cpu:x86_32",
"@platforms//cpu:x86_64",
"@platforms//cpu:ppc",
"@platforms//cpu:arm",
"@platforms//cpu:aarch64",
"@platforms//cpu:s390x",
],
os_constraints = [
":osx",
":freebsd",
":linux",
":windows",
"@platforms//os:osx",
"@platforms//os:freebsd",
"@platforms//os:linux",
"@platforms//os:windows",
],
target_platform = True,
)
Loading

0 comments on commit 8e27297

Please sign in to comment.