Skip to content

Commit

Permalink
Use constraints in global conditions instead of configuration flags.
Browse files Browse the repository at this point in the history
I changed configuration settings in //src/conditions to use constraints instead of flags and then fixed some places where this is used.

I fixed uses of darwin and darwin_x86_64, which using flags I believe is the same thing and using constraints actually becomes different.

Added config_setting for linux. Used it where it makes sense. It cannot be used in tools/jdk/..., because it somehow gets new @bazel_tools and old @bazel_tools/constraints.

This might break users of remote execution or cross compiling. The users working on a single platform should be safe.

Closes bazelbuild#12427.

PiperOrigin-RevId: 341408717
  • Loading branch information
comius authored and copybara-github committed Nov 9, 2020
1 parent 5137f36 commit 6d637f4
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 155 deletions.
5 changes: 0 additions & 5 deletions scripts/packages/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ filegroup(
":without-jdk/install.sh",
":generate-package-info",
],
"//src/conditions:darwin_x86_64": [
":with-jdk/install.sh",
":without-jdk/install.sh",
":generate-package-info",
],
"//conditions:default": [
":with-jdk/install.sh",
":without-jdk/install.sh",
Expand Down
19 changes: 2 additions & 17 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ md5_cmd = "set -e -o pipefail && %s $(SRCS) | %s | %s > $@"
outs = ["install_base_key" + suffix],
cmd = select({
"//src/conditions:darwin": md5_cmd % ("/sbin/md5", "/sbin/md5", "head -c 32"),
"//src/conditions:darwin_x86_64": md5_cmd % ("/sbin/md5", "/sbin/md5", "head -c 32"),
"//src/conditions:freebsd": md5_cmd % ("/sbin/md5", "/sbin/md5", "head -c 32"),
# We avoid using the `head` tool's `-c` option, since it does not exist
# on OpenBSD.
Expand Down Expand Up @@ -133,9 +132,6 @@ JAVA_TOOLS = [
"//src/conditions:darwin": [
":darwin_tools",
],
"//src/conditions:darwin_x86_64": [
":darwin_tools",
],
"//conditions:default": [
":dummy_darwin_tools",
],
Expand Down Expand Up @@ -173,9 +169,6 @@ filegroup(
"//src/conditions:darwin": [
"@openjdk_macos//file",
],
"//src/conditions:darwin_x86_64": [
"@openjdk_macos//file",
],
"//src/conditions:windows": [
"@openjdk_win//file",
],
Expand All @@ -195,9 +188,6 @@ filegroup(
"//src/conditions:darwin": [
"@openjdk_macos_minimal//file",
],
"//src/conditions:darwin_x86_64": [
"@openjdk_macos_minimal//file",
],
"//src/conditions:windows": [
"@openjdk_win_minimal//file",
],
Expand All @@ -217,9 +207,6 @@ filegroup(
"//src/conditions:darwin": [
"@openjdk_macos_vanilla//file",
],
"//src/conditions:darwin_x86_64": [
"@openjdk_macos_vanilla//file",
],
"//src/conditions:windows": [
"@openjdk_win_vanilla//file",
],
Expand Down Expand Up @@ -625,9 +612,8 @@ JAVA_VERSIONS = ("11",)
"--platform",
] + select({
"//src/conditions:darwin": ["darwin"],
"//src/conditions:darwin_x86_64": ["darwin_x86_64"],
"//src/conditions:windows": ["windows"],
"//src/conditions:linux_x86_64": ["linux"],
"//src/conditions:linux": ["linux"],
"//conditions:default": ["unknown"],
}),
data = [":java_tools_dist_java" + java_version],
Expand Down Expand Up @@ -716,9 +702,8 @@ JAVA_VERSIONS = ("11",)
"--platform",
] + select({
"//src/conditions:darwin": ["darwin"],
"//src/conditions:darwin_x86_64": ["darwin_x86_64"],
"//src/conditions:windows": ["windows"],
"//src/conditions:linux_x86_64": ["linux"],
"//src/conditions:linux": ["linux"],
"//conditions:default": ["unknown"],
}),
data = [":java_tools_java" + java_version + "_zip"],
Expand Down
62 changes: 46 additions & 16 deletions src/conditions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,96 @@ filegroup(
visibility = ["//src:__pkg__"],
)

# There is no config_setting for "linux".
# See https://github.com/bazelbuild/bazel/issues/11107
config_setting(
name = "linux",
constraint_values = ["@platforms//os:linux"],
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_aarch64",
values = {"cpu": "aarch64"},
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_arm",
values = {"cpu": "arm"},
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:arm",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_ppc",
values = {"cpu": "ppc"},
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:ppc",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_ppc64le",
values = {"cpu": "ppc"},
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:ppc",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_s390x",
values = {"cpu": "s390x"},
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:s390x",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_x86_64",
values = {"cpu": "k8"},
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "darwin",
values = {"cpu": "darwin"},
constraint_values = ["@platforms//os:macos"],
visibility = ["//visibility:public"],
)

config_setting(
name = "darwin_x86_64",
values = {"cpu": "darwin_x86_64"},
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "darwin_arm64",
values = {"cpu": "darwin_arm64"},
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:arm64",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "darwin_arm64e",
values = {"cpu": "darwin_arm64e"},
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:arm64e",
],
visibility = ["//visibility:public"],
)

Expand All @@ -84,25 +114,25 @@ config_setting(

config_setting(
name = "freebsd",
values = {"cpu": "freebsd"},
constraint_values = ["@platforms//os:freebsd"],
visibility = ["//visibility:public"],
)

config_setting(
name = "openbsd",
values = {"cpu": "openbsd"},
constraint_values = ["@platforms//os:openbsd"],
visibility = ["//visibility:public"],
)

config_setting(
name = "windows",
values = {"cpu": "x64_windows"},
constraint_values = ["@platforms//os:windows"],
visibility = ["//visibility:public"],
)

config_setting(
name = "arm",
values = {"cpu": "arm"},
constraint_values = ["@platforms//cpu:arm"],
visibility = ["//visibility:public"],
)

Expand Down
49 changes: 13 additions & 36 deletions src/conditions/BUILD.tools
Original file line number Diff line number Diff line change
@@ -1,105 +1,82 @@
config_setting(
name = "freebsd",
values = {"cpu": "freebsd"},
constraint_values = [ "@platforms//os:freebsd"],
visibility = ["//visibility:public"],
)

config_setting(
name = "openbsd",
values = {"cpu": "openbsd"},
constraint_values = [ "@platforms//os:openbsd"],
visibility = ["//visibility:public"],
)

config_setting(
name = "darwin",
values = {"cpu": "darwin"},
constraint_values = [ "@platforms//os:macos" ],
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_ppc",
values = {"cpu": "ppc"},
constraint_values = [ "@platforms//os:linux", "@platforms//cpu:ppc" ],
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_ppc64le",
values = {"cpu": "ppc"},
constraint_values = [ "@platforms//os:linux", "@platforms//cpu:ppc" ],
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_s390x",
values = {"cpu": "s390x"},
constraint_values = [ "@platforms//os:linux", "@platforms//cpu:s390x" ],
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_x86_64",
values = {"cpu": "k8"},
constraint_values = [ "@platforms//os:linux", "@platforms//cpu:x86_64" ],
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_aarch64",
values = {"cpu": "aarch64"},
constraint_values = [ "@platforms//os:linux", "@platforms//cpu:aarch64" ],
visibility = ["//visibility:public"],
)

config_setting(
name = "darwin_x86_64",
values = {"cpu": "darwin_x86_64"},
constraint_values = [ "@platforms//os:macos", "@platforms//cpu:x86_64" ],
visibility = ["//visibility:public"],
)

config_setting(
name = "darwin_arm64",
values = {"cpu": "darwin_arm64"},
constraint_values = [ "@platforms//os:macos", "@platforms//cpu:arm64" ],
visibility = ["//visibility:public"],
)

config_setting(
name = "darwin_arm64e",
values = {"cpu": "darwin_arm64e"},
constraint_values = [ "@platforms//os:macos", "@platforms//cpu:arm64e" ],
visibility = ["//visibility:public"],
)

config_setting(
name = "windows",
values = {"cpu": "x64_windows"},
visibility = ["//visibility:public"],
)

config_setting(
name = "windows_msvc",
values = {"cpu": "x64_windows_msvc"},
visibility = ["//visibility:public"],
)

config_setting(
name = "windows_msys",
values = {"cpu": "x64_windows_msys"},
constraint_values = [ "@platforms//os:windows"],
visibility = ["//visibility:public"],
)

# TODO: figure out how to base this selection on constraints
config_setting(
name = "host_windows",
values = {"host_cpu": "x64_windows"},
visibility = ["//visibility:public"],
)

config_setting(
name = "host_windows_msvc",
values = {"host_cpu": "x64_windows_msvc"},
visibility = ["//visibility:public"],
)

config_setting(
name = "host_windows_msys",
values = {"host_cpu": "x64_windows_msys"},
visibility = ["//visibility:public"],
)

config_setting(
name = "remote",
values = {"define": "EXECUTOR=remote"},
Expand Down
27 changes: 0 additions & 27 deletions src/main/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ cc_library(
"blaze_util_darwin.cc",
"blaze_util_posix.cc",
],
"//src/conditions:darwin_x86_64": [
"blaze_util_darwin.cc",
"blaze_util_posix.cc",
],
"//src/conditions:darwin_arm64": [
"blaze_util_darwin.cc",
"blaze_util_posix.cc",
],
"//src/conditions:darwin_arm64e": [
"blaze_util_darwin.cc",
"blaze_util_posix.cc",
],
"//src/conditions:freebsd": [
"blaze_util_bsd.cc",
"blaze_util_posix.cc",
Expand All @@ -60,15 +48,6 @@ cc_library(
"//src/conditions:darwin": [
"-framework CoreFoundation",
],
"//src/conditions:darwin_x86_64": [
"-framework CoreFoundation",
],
"//src/conditions:darwin_arm64": [
"-framework CoreFoundation",
],
"//src/conditions:darwin_arm64e": [
"-framework CoreFoundation",
],
"//src/conditions:freebsd": [
],
"//src/conditions:openbsd": [
Expand Down Expand Up @@ -128,12 +107,6 @@ cc_binary(
linkopts = select({
"//src/conditions:darwin": [
],
"//src/conditions:darwin_x86_64": [
],
"//src/conditions:darwin_arm64": [
],
"//src/conditions:darwin_arm64e": [
],
"//src/conditions:freebsd": [
"-lprocstat",
"-lm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ filegroup(
name = "qemu2_x86",
srcs = ["emulator/emulator"] + select({
"@bazel_tools//src/conditions:darwin": ["emulator/qemu/darwin-x86_64/qemu-system-i386"],
"@bazel_tools//src/conditions:darwin_x86_64": ["emulator/qemu/darwin-x86_64/qemu-system-i386"],
"//conditions:default": ["emulator/qemu/linux-x86_64/qemu-system-i386"],
}),
)
Expand Down
Loading

0 comments on commit 6d637f4

Please sign in to comment.