aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
authorGravatar John Cater <jcater@google.com>2018-06-14 02:24:57 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-14 02:26:18 -0700
commitd79e977c87ea46855c219cb7dcbde0e3fde4bcf9 (patch)
tree7b967abf32849eeb1a774f0bbbaf467907060c0a /src/test/shell
parent3a5780d020517342137ef48ca3fbad1df69e9f33 (diff)
Allow Skylark rules to specify whether targets can add execution platform constraints.
Closes #5341. Change-Id: Ib74e59fec48102469a5039e045e3f3d0e0d86d8c PiperOrigin-RevId: 200526448
Diffstat (limited to 'src/test/shell')
-rwxr-xr-xsrc/test/shell/bazel/toolchain_test.sh180
1 files changed, 180 insertions, 0 deletions
diff --git a/src/test/shell/bazel/toolchain_test.sh b/src/test/shell/bazel/toolchain_test.sh
index 748182c0bc..097e874641 100755
--- a/src/test/shell/bazel/toolchain_test.sh
+++ b/src/test/shell/bazel/toolchain_test.sh
@@ -734,4 +734,184 @@ EOF
}
+function test_rule_with_default_execution_constraints() {
+ write_test_toolchain
+ write_register_toolchain
+
+ # Add test platforms.
+ mkdir -p platforms
+ cat >> platforms/BUILD <<EOF
+constraint_setting(name = 'setting')
+constraint_value(name = 'value1', constraint_setting = ':setting')
+constraint_value(name = 'value2', constraint_setting = ':setting')
+
+platform(
+ name = 'platform1',
+ constraint_values = [':value1'],
+ visibility = ['//visibility:public'])
+platform(
+ name = 'platform2',
+ constraint_values = [':value2'],
+ visibility = ['//visibility:public'])
+EOF
+
+ # Add a rule with default execution constraints.
+ mkdir -p demo
+ cat >> demo/rule.bzl <<EOF
+def _impl(ctx):
+ return []
+
+sample_rule = rule(
+ implementation = _impl,
+ attrs = {},
+ exec_compatible_with = [
+ '//platforms:value2',
+ ],
+ toolchains = ['//toolchain:test_toolchain'],
+)
+EOF
+
+ # Use the new rule.
+ cat >> demo/BUILD <<EOF
+load(':rule.bzl', 'sample_rule')
+
+sample_rule(name = 'use')
+EOF
+
+ # Build the target, using debug messages to verify the correct platform was selected.
+ bazel build \
+ --extra_execution_platforms=//platforms:all \
+ --toolchain_resolution_debug \
+ //demo:use &> $TEST_log || fail "Build failed"
+ expect_log "Selected execution platform //platforms:platform2"
+}
+
+
+function test_target_with_execution_constraints() {
+ write_test_toolchain
+ write_register_toolchain
+
+ # Add test platforms.
+ mkdir -p platforms
+ cat >> platforms/BUILD <<EOF
+package(default_visibility = ['//visibility:public'])
+constraint_setting(name = 'setting')
+constraint_value(name = 'value1', constraint_setting = ':setting')
+constraint_value(name = 'value2', constraint_setting = ':setting')
+
+platform(
+ name = 'platform1',
+ constraint_values = [':value1'],
+ visibility = ['//visibility:public'])
+platform(
+ name = 'platform2',
+ constraint_values = [':value2'],
+ visibility = ['//visibility:public'])
+EOF
+
+ # Add a rule with default execution constraints.
+ mkdir -p demo
+ cat >> demo/rule.bzl <<EOF
+def _impl(ctx):
+ return []
+
+sample_rule = rule(
+ implementation = _impl,
+ attrs = {},
+ toolchains = ['//toolchain:test_toolchain'],
+ execution_platform_constraints_allowed = True,
+)
+EOF
+
+ # Use the new rule.
+ cat >> demo/BUILD <<EOF
+load(':rule.bzl', 'sample_rule')
+
+sample_rule(
+ name = 'use',
+ exec_compatible_with = [
+ '//platforms:value2',
+ ],
+)
+EOF
+
+ # Build the target, using debug messages to verify the correct platform was selected.
+ bazel build \
+ --extra_execution_platforms=//platforms:all \
+ --toolchain_resolution_debug \
+ //demo:use &> $TEST_log || fail "Build failed"
+ expect_log "Selected execution platform //platforms:platform2"
+}
+
+function test_rule_and_target_with_execution_constraints() {
+ write_test_toolchain
+ write_register_toolchain
+
+ # Add test platforms.
+ mkdir -p platforms
+ cat >> platforms/BUILD <<EOF
+package(default_visibility = ['//visibility:public'])
+constraint_setting(name = 'setting1')
+constraint_value(name = 'value1', constraint_setting = ':setting1')
+constraint_value(name = 'value2', constraint_setting = ':setting1')
+
+constraint_setting(name = 'setting2')
+constraint_value(name = 'value3', constraint_setting = ':setting2')
+constraint_value(name = 'value4', constraint_setting = ':setting2')
+
+platform(
+ name = 'platform1_3',
+ constraint_values = [':value1', ':value3'],
+ visibility = ['//visibility:public'])
+platform(
+ name = 'platform1_4',
+ constraint_values = [':value1', ':value4'],
+ visibility = ['//visibility:public'])
+platform(
+ name = 'platform2_3',
+ constraint_values = [':value2', ':value3'],
+ visibility = ['//visibility:public'])
+platform(
+ name = 'platform2_4',
+ constraint_values = [':value2', ':value4'],
+ visibility = ['//visibility:public'])
+EOF
+
+ # Add a rule with default execution constraints.
+ mkdir -p demo
+ cat >> demo/rule.bzl <<EOF
+def _impl(ctx):
+ return []
+
+sample_rule = rule(
+ implementation = _impl,
+ attrs = {},
+ exec_compatible_with = [
+ '//platforms:value2',
+ ],
+ toolchains = ['//toolchain:test_toolchain'],
+ execution_platform_constraints_allowed = True,
+)
+EOF
+
+ # Use the new rule.
+ cat >> demo/BUILD <<EOF
+load(':rule.bzl', 'sample_rule')
+
+sample_rule(
+ name = 'use',
+ exec_compatible_with = [
+ '//platforms:value4',
+ ],
+)
+EOF
+
+ # Build the target, using debug messages to verify the correct platform was selected.
+ bazel build \
+ --extra_execution_platforms=//platforms:all \
+ --toolchain_resolution_debug \
+ //demo:use &> $TEST_log || fail "Build failed"
+ expect_log "Selected execution platform //platforms:platform2_4"
+}
+
run_suite "toolchain tests"