From 0f89dcc26d61d8d23a1001b00aaaa4aeb1d8f956 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 28 Oct 2024 14:06:48 -0700 Subject: [PATCH] Convert calls to `rewriteModuleDotBazel` to use Java text blocks. PiperOrigin-RevId: 690743742 Change-Id: Ic6182c9ee0551f3d4a6eca07fbcb1afba6896b75 --- .../lib/rules/platform/ToolchainTestCase.java | 4 +- ...isteredExecutionPlatformsFunctionTest.java | 40 ++++-- .../RegisteredToolchainsFunctionTest.java | 52 +++++-- ...SingleToolchainResolutionFunctionTest.java | 16 ++- .../ToolchainResolutionFunctionTest.java | 134 +++++++++++++----- .../starlark/StarlarkOptionsParsingTest.java | 16 ++- 6 files changed, 191 insertions(+), 71 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java index 0ecff450782e1c..adca68c0e2e2d5 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java @@ -239,7 +239,9 @@ public void addOptionalToolchain( @Before public void createToolchains() throws Exception { rewriteModuleDotBazel( - "register_toolchains('//toolchain:toolchain_1', '//toolchain:toolchain_2')"); + """ + register_toolchains("//toolchain:toolchain_1", "//toolchain:toolchain_2") + """); scratch.file( "toolchain/toolchain_def.bzl", diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredExecutionPlatformsFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredExecutionPlatformsFunctionTest.java index ba1e1b566d6aa3..e6900b50616fb2 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredExecutionPlatformsFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredExecutionPlatformsFunctionTest.java @@ -106,7 +106,10 @@ public void testRegisteredExecutionPlatforms_flagOverride() throws Exception { platform(name = "execution_platform_2") """); - rewriteModuleDotBazel("register_execution_platforms('//extra:execution_platform_2')"); + rewriteModuleDotBazel( + """ + register_execution_platforms("//extra:execution_platform_2") + """); useConfiguration("--extra_execution_platforms=//extra:execution_platform_1"); SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey); @@ -164,7 +167,10 @@ public void testRegisteredExecutionPlatforms_targetPattern_workspace() throws Ex platform(name = "execution_platform_2") """); - rewriteModuleDotBazel("register_execution_platforms('//extra/...')"); + rewriteModuleDotBazel( + """ + register_execution_platforms("//extra/...") + """); SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey); EvaluationResult result = @@ -198,7 +204,10 @@ public void testRegisteredExecutionPlatforms_aliased() throws Exception { alias(name = "alias_platform_2", actual = "//extra:execution_platform_2"); """); - rewriteModuleDotBazel("register_execution_platforms('//alias/...')"); + rewriteModuleDotBazel( + """ + register_execution_platforms("//alias/...") + """); SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey); EvaluationResult result = @@ -259,7 +268,10 @@ public void testRegisteredExecutionPlatforms_targetPattern_mixed() throws Except filegroup(name = "not_an_execution_platform") """); - rewriteModuleDotBazel("register_execution_platforms('//extra:all')"); + rewriteModuleDotBazel( + """ + register_execution_platforms("//extra:all") + """); SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey); EvaluationResult result = @@ -308,7 +320,9 @@ public void testRegisteredExecutionPlatforms_targetPattern_flagOverride() throws @Test public void testRegisteredExecutionPlatforms_notExecutionPlatform() throws Exception { rewriteModuleDotBazel( - "register_execution_platforms(", " '//error:not_an_execution_platform')"); + """ + register_execution_platforms("//error:not_an_execution_platform") + """); // Have to use a rule that doesn't require a target platform, or else there will be a cycle. scratch.file("error/BUILD", "toolchain_type(name = 'not_an_execution_platform')"); @@ -338,7 +352,10 @@ public void testRegisteredExecutionPlatforms_reload() throws Exception { platform(name = "execution_platform_2") """); - rewriteModuleDotBazel("register_execution_platforms('//platform:execution_platform_1')"); + rewriteModuleDotBazel( + """ + register_execution_platforms("//platform:execution_platform_1") + """); SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey); EvaluationResult result = @@ -347,8 +364,10 @@ public void testRegisteredExecutionPlatforms_reload() throws Exception { assertExecutionPlatformLabels(result.get(executionPlatformsKey)) .contains(Label.parseCanonicalUnchecked("//platform:execution_platform_1")); - // Re-write the WORKSPACE. - rewriteModuleDotBazel("register_execution_platforms('//platform:execution_platform_2')"); + rewriteModuleDotBazel( + """ + register_execution_platforms("//platform:execution_platform_2") + """); executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey); result = requestExecutionPlatformsFromSkyframe(executionPlatformsKey); @@ -470,7 +489,10 @@ public void testRegisteredExecutionPlatformsValue_equalsAndHashCode() */ @Test public void testInvalidExecutionPlatformLabelDoesntCrash() throws Exception { - rewriteModuleDotBazel("register_execution_platforms('//test:bad_exec_platform_label')"); + rewriteModuleDotBazel( + """ + register_execution_platforms("//test:bad_exec_platform_label") + """); scratch.file( "test/BUILD", "genrule(name = 'g', srcs = [], outs = ['g.out'], cmd = 'echo hi > $@')"); reporter.removeHandler(failFastHandler); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredToolchainsFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredToolchainsFunctionTest.java index c62662179b5f3e..14e227429dfd17 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredToolchainsFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredToolchainsFunctionTest.java @@ -119,7 +119,10 @@ public void testRegisteredToolchains_flagOverride() throws Exception { ) """); - rewriteModuleDotBazel("register_toolchains('//toolchain:toolchain_1')"); + rewriteModuleDotBazel( + """ + register_toolchains('//toolchain:toolchain_1') + """); useConfiguration("--extra_toolchains=//extra:extra_toolchain"); SkyKey toolchainsKey = RegisteredToolchainsValue.key(targetConfigKey, /* debug= */ false); @@ -191,7 +194,10 @@ public void testRegisteredToolchains_flagOverride_multiple() throws Exception { @Test public void testRegisteredToolchains_notToolchain() throws Exception { - rewriteModuleDotBazel("register_toolchains('//error:not_a_toolchain')"); + rewriteModuleDotBazel( + """ + register_toolchains("//error:not_a_toolchain") + """); scratch.file("error/BUILD", "filegroup(name = 'not_a_toolchain')"); // Request the toolchains. @@ -211,7 +217,10 @@ public void testRegisteredToolchains_notToolchain() throws Exception { // don't provide the DeclaredToolchainInfo provider. @Test public void testRegisteredToolchains_fakeToolchain() throws Exception { - rewriteModuleDotBazel("register_toolchains('//error:not_a_toolchain')"); + rewriteModuleDotBazel( + """ + register_toolchains("//error:not_a_toolchain") + """); scratch.file( "error/fake_toolchain.bzl", """ @@ -245,7 +254,10 @@ def _fake_impl(ctx): // RegisteredToolchainsFunction will fail. @Test public void testRegisteredToolchains_wildcard_fakeToolchain() throws Exception { - rewriteModuleDotBazel("register_toolchains('//error:all')"); + rewriteModuleDotBazel( + """ + register_toolchains("//error:all") + """); scratch.file( "error/fake_toolchain.bzl", """ @@ -295,7 +307,10 @@ public void testRegisteredToolchains_targetPattern_workspace() throws Exception ImmutableList.of("//constraints:mac"), ImmutableList.of("//constraints:linux"), "baz"); - rewriteModuleDotBazel("register_toolchains('//extra/...')"); + rewriteModuleDotBazel( + """ + register_toolchains("//extra/...") + """); SkyKey toolchainsKey = RegisteredToolchainsValue.key(targetConfigKey, /* debug= */ false); EvaluationResult result = @@ -378,7 +393,10 @@ public void testRegisteredToolchains_targetPattern_order() throws Exception { addSimpleToolchain("extra/xxx/zzz", "bbb"); addSimpleToolchain("extra/xxx/zzz", "ccc"); addSimpleToolchain("extra/xxx/zzz", "aaa"); - rewriteModuleDotBazel("register_toolchains('//extra/...')"); + rewriteModuleDotBazel( + """ + register_toolchains("//extra/...") + """); SkyKey toolchainsKey = RegisteredToolchainsValue.key(targetConfigKey, /* debug= */ false); EvaluationResult result = @@ -421,7 +439,10 @@ public void testRegisteredToolchains_targetPattern_order() throws Exception { @Test public void testRegisteredToolchains_reload() throws Exception { - rewriteModuleDotBazel("register_toolchains('//toolchain:toolchain_1')"); + rewriteModuleDotBazel( + """ + register_toolchains("//toolchain:toolchain_1") + """); SkyKey toolchainsKey = RegisteredToolchainsValue.key(targetConfigKey, /* debug= */ false); EvaluationResult result = @@ -431,7 +452,10 @@ public void testRegisteredToolchains_reload() throws Exception { .contains(Label.parseCanonicalUnchecked("//toolchain:toolchain_1_impl")); // Re-write the MODULE.bazel. - rewriteModuleDotBazel("register_toolchains('//toolchain:toolchain_2')"); + rewriteModuleDotBazel( + """ + register_toolchains("//toolchain:toolchain_2") + """); toolchainsKey = RegisteredToolchainsValue.key(targetConfigKey, /* debug= */ false); result = requestToolchainsFromSkyframe(toolchainsKey); @@ -602,7 +626,9 @@ public void testRegisteredToolchains_targetSetting() throws Exception { """); rewriteModuleDotBazel( - "register_toolchains('//toolchain:toolchain_1', '//extra:extra_toolchain')"); + """ + register_toolchains("//toolchain:toolchain_1", "//extra:extra_toolchain") + """); SkyKey toolchainsKey = RegisteredToolchainsValue.key(targetConfigKey, /* debug= */ false); EvaluationResult result = @@ -652,7 +678,9 @@ public void testRegisteredToolchains_targetSetting_debug() throws Exception { """); rewriteModuleDotBazel( - "register_toolchains('//toolchain:toolchain_1', '//extra:extra_toolchain')"); + """ + register_toolchains("//toolchain:toolchain_1", "//extra:extra_toolchain") + """); SkyKey toolchainsKey = RegisteredToolchainsValue.key(targetConfigKey, /* debug= */ true); EvaluationResult result = @@ -711,7 +739,9 @@ public void testRegisteredToolchains_targetSetting_error() throws Exception { """); rewriteModuleDotBazel( - "register_toolchains('//toolchain:toolchain_1', '//extra:extra_toolchain')"); + """ + register_toolchains("//toolchain:toolchain_1", "//extra:extra_toolchain") + """); // Need this so the feature flag is actually gone from the configuration. useConfiguration("--enforce_transitive_configs_for_config_feature_flag"); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/SingleToolchainResolutionFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/SingleToolchainResolutionFunctionTest.java index e4b1564b075988..82ce73b2567211 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/SingleToolchainResolutionFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/SingleToolchainResolutionFunctionTest.java @@ -92,10 +92,13 @@ public void testResolution_multipleExecutionPlatforms() throws Exception { ImmutableList.of("//constraints:linux"), "baz"); rewriteModuleDotBazel( - "register_toolchains(", - "'//toolchain:toolchain_1',", - "'//toolchain:toolchain_2',", - "'//extra:extra_toolchain')"); + """ + register_toolchains( + "//toolchain:toolchain_1", + "//toolchain:toolchain_2", + "//extra:extra_toolchain", + ) + """); SkyKey key = SingleToolchainResolutionValue.key( @@ -170,7 +173,10 @@ public void testResolution_checkPlatformAllowedToolchains() throws Exception { // Define the toolchains themselves. addToolchain("extra", "extra_toolchain", ImmutableList.of(), ImmutableList.of(), "baz"); - rewriteModuleDotBazel("register_toolchains('//extra:extra_toolchain')"); + rewriteModuleDotBazel( + """ + register_toolchains("//extra:extra_toolchain") + """); // Resolve toolchains. SkyKey key = diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/ToolchainResolutionFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/ToolchainResolutionFunctionTest.java index e6eceeace443d8..c4ea4d73bd737f 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/ToolchainResolutionFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/toolchains/ToolchainResolutionFunctionTest.java @@ -66,8 +66,10 @@ public void resolve() throws Exception { ImmutableList.of("//constraints:linux"), "baz"); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_linux', '//extra:extra_toolchain_mac')", - "register_execution_platforms('//platforms:mac', '//platforms:linux')"); + """ + register_toolchains("//extra:extra_toolchain_linux", "//extra:extra_toolchain_mac") + register_execution_platforms("//platforms:mac", "//platforms:linux") + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -103,7 +105,9 @@ public void resolve_hostPlatform() throws Exception { ImmutableList.of("//constraints:linux"), "baz"); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_linux', '//extra:extra_toolchain_mac')"); + """ + register_toolchains("//extra:extra_toolchain_linux", "//extra:extra_toolchain_mac") + """); useConfiguration("--platforms=//platforms:linux", "--host_platform=//platforms:linux"); ToolchainContextKey key = @@ -146,7 +150,9 @@ public void resolve_hostPlatform_alias() throws Exception { alias(name = 'linux', actual = '//platforms:linux') """); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_linux', '//extra:extra_toolchain_mac')"); + """ + register_toolchains("//extra:extra_toolchain_linux", "//extra:extra_toolchain_mac") + """); useConfiguration("--platforms=//platforms:linux", "--host_platform=//alias:linux"); ToolchainContextKey key = @@ -186,8 +192,10 @@ public void resolve_optional() throws Exception { ImmutableList.of("//constraints:linux"), "baz"); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_linux', '//extra:extra_toolchain_mac')", - "register_execution_platforms('//platforms:mac', '//platforms:linux')"); + """ + register_toolchains("//extra:extra_toolchain_linux", "//extra:extra_toolchain_mac") + register_execution_platforms("//platforms:mac", "//platforms:linux") + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -218,8 +226,10 @@ public void resolve_optional_on_first_platform() throws Exception { ImmutableList.of("//constraints:linux"), "baz"); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_mac')", - "register_execution_platforms('//platforms:mac', '//platforms:linux')"); + """ + register_toolchains("//extra:extra_toolchain_mac") + register_execution_platforms("//platforms:mac", "//platforms:linux") + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -250,8 +260,10 @@ public void resolve_optional_on_second_platform() throws Exception { ImmutableList.of("//constraints:linux"), "baz"); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_mac')", - "register_execution_platforms('//platforms:linux', '//platforms:mac')"); + """ + register_toolchains("//extra:extra_toolchain_mac") + register_execution_platforms("//platforms:linux", "//platforms:mac") + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -288,8 +300,10 @@ public void resolve_max_optional_on_second_platform() throws Exception { ToolchainTypeRequirement extraOptionalToolchainType = ToolchainTypeRequirement.builder(extraOptionalToolchainTypeLabel).mandatory(false).build(); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_mac')", - "register_execution_platforms('//platforms:linux', '//platforms:mac')"); + """ + register_toolchains("//extra:extra_toolchain_mac") + register_execution_platforms('//platforms:linux', '//platforms:mac') + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -331,7 +345,10 @@ public void resolve_multiple() throws Exception { ImmutableList.of("//constraints:linux"), "baz"); rewriteModuleDotBazel( - "register_toolchains('//main:all',)", "register_execution_platforms('//platforms:linux')"); + """ + register_toolchains("//main:all") + register_execution_platforms("//platforms:linux") + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -394,7 +411,10 @@ public void resolve_multiple_optional() throws Exception { ImmutableList.of("//constraints:linux"), "baz"); rewriteModuleDotBazel( - "register_toolchains('//main:all',)", "register_execution_platforms('//platforms:linux')"); + """ + register_toolchains("//main:all") + register_execution_platforms("//platforms:linux") + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -431,7 +451,10 @@ public void resolve_multiple_optional_missing() throws Exception { ImmutableList.of("//constraints:linux"), "baz"); rewriteModuleDotBazel( - "register_toolchains('//main:all',)", "register_execution_platforms('//platforms:linux')"); + """ + register_toolchains("//main:all") + register_execution_platforms("//platforms:linux") + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -465,8 +488,10 @@ public void resolve_toolchainTypeAlias() throws Exception { ImmutableList.of("//constraints:linux"), "baz"); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_linux')", - "register_execution_platforms('//platforms:linux')"); + """ + register_toolchains("//extra:extra_toolchain_linux") + register_execution_platforms("//platforms:linux") + """); // Set up an alias for the toolchain type. Label aliasedToolchainTypeLabel = Label.parseCanonicalUnchecked("//alias:toolchain_type"); @@ -495,7 +520,10 @@ public void resolve_toolchainTypeAlias() throws Exception { @Test public void resolve_noToolchainType() throws Exception { scratch.file("host/BUILD", "platform(name = 'host')"); - rewriteModuleDotBazel("register_execution_platforms('//platforms:mac', '//platforms:linux')"); + rewriteModuleDotBazel( + """ + register_execution_platforms("//platforms:mac", "//platforms:linux") + """); useConfiguration("--host_platform=//host:host", "--platforms=//platforms:linux"); ToolchainContextKey key = ToolchainContextKey.key().configurationKey(targetConfigKey).build(); @@ -531,7 +559,9 @@ public void resolve_noToolchainType_checkPlatformAllowedToolchains() throws Exce ) """); rewriteModuleDotBazel( - "register_execution_platforms('//allowed:fails_match', '//allowed:allows_all')"); + """ + register_execution_platforms("//allowed:fails_match", "//allowed:allows_all") + """); useConfiguration("--host_platform=//allowed:fails_match"); ToolchainContextKey key = ToolchainContextKey.key().configurationKey(targetConfigKey).build(); @@ -576,8 +606,14 @@ public void resolve_noToolchainType_hostNotAvailable() throws Exception { ) """); rewriteModuleDotBazel( - "register_execution_platforms('//platforms:mac', '//platforms:linux',", - " '//sample:sample_a', '//sample:sample_b')"); + """ + register_execution_platforms( + "//platforms:mac", + "//platforms:linux", + "//sample:sample_a", + "//sample:sample_b", + ) + """); useConfiguration("--host_platform=//host:host", "--platforms=//platforms:linux"); ToolchainContextKey key = @@ -810,8 +846,10 @@ public void resolve_executionPlatform_alias() throws Exception { alias(name = 'linux', actual = '//platforms:linux') """); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_linux', '//extra:extra_toolchain_mac')", - "register_execution_platforms('//alias:mac', '//alias:linux')"); + """ + register_toolchains("//extra:extra_toolchain_linux", "//extra:extra_toolchain_mac") + register_execution_platforms('//alias:mac', '//alias:linux') + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -905,8 +943,10 @@ public void resolve_execConstraints() throws Exception { /* targetConstraints= */ ImmutableList.of("//constraints:linux"), /* data= */ "baz"); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_linux', '//extra:extra_toolchain_mac')", - "register_execution_platforms('//platforms:mac', '//platforms:linux')"); + """ + register_toolchains("//extra:extra_toolchain_linux", "//extra:extra_toolchain_mac") + register_execution_platforms("//platforms:mac", "//platforms:linux") + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -989,8 +1029,10 @@ public void resolve_noMatchingPlatform() throws Exception { """); rewriteModuleDotBazel( - "register_toolchains('//a:toolchain', '//b:toolchain')", - "register_execution_platforms('//platforms:mac', '//platforms:linux')"); + """ + register_toolchains("//a:toolchain", "//b:toolchain") + register_execution_platforms("//platforms:mac", "//platforms:linux") + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -1026,8 +1068,10 @@ public void resolve_forceExecutionPlatform() throws Exception { /* targetConstraints= */ ImmutableList.of("//constraints:linux"), /* data= */ "baz"); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_linux', '//extra:extra_toolchain_mac')", - "register_execution_platforms('//platforms:mac', '//platforms:linux')"); + """ + register_toolchains("//extra:extra_toolchain_linux", "//extra:extra_toolchain_mac") + register_execution_platforms("//platforms:mac", "//platforms:linux") + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -1073,8 +1117,10 @@ public void resolve_forceExecutionPlatform_alias() throws Exception { alias(name = 'linux', actual = '//platforms:linux') """); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_linux', '//extra:extra_toolchain_mac')", - "register_execution_platforms('//alias:mac', '//alias:linux')"); + """ + register_toolchains("//extra:extra_toolchain_linux", "//extra:extra_toolchain_mac") + register_execution_platforms("//alias:mac", "//alias:linux") + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -1113,7 +1159,9 @@ public void resolve_forceExecutionPlatform_host() throws Exception { /* targetConstraints= */ ImmutableList.of("//constraints:linux"), /* data= */ "baz"); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_linux', '//extra:extra_toolchain_mac')"); + """ + register_toolchains("//extra:extra_toolchain_linux", "//extra:extra_toolchain_mac") + """); useConfiguration("--platforms=//platforms:linux", "--host_platform=//platforms:linux"); ToolchainContextKey key = @@ -1162,10 +1210,13 @@ public void resolve_forceExecutionPlatform_host_alias() throws Exception { alias(name = 'linux', actual = '//platforms:linux') """); rewriteModuleDotBazel( - "register_toolchains('//extra:extra_toolchain_linux', '//extra:extra_toolchain_mac')", - // This test requires an execution platform that isn't the forced platform in order to - // trigger. - "register_execution_platforms('//alias:mac')"); + """ + register_toolchains("//extra:extra_toolchain_linux", "//extra:extra_toolchain_mac") + + # This test requires an execution platform that isn't the forced platform in order to + # trigger. + register_execution_platforms("//alias:mac") + """); useConfiguration("--platforms=//platforms:linux", "--host_platform=//alias:linux"); ToolchainContextKey key = @@ -1193,7 +1244,10 @@ public void resolve_forceExecutionPlatform_host_alias() throws Exception { public void resolve_forceExecutionPlatform_noRequiredToolchains() throws Exception { // This should select execution platform linux, due to the forced execution platform, even // though execution platform mac is registered first. - rewriteModuleDotBazel("register_execution_platforms('//platforms:mac', '//platforms:linux')"); + rewriteModuleDotBazel( + """ + register_execution_platforms("//platforms:mac", "//platforms:linux") + """); useConfiguration("--platforms=//platforms:linux"); ToolchainContextKey key = @@ -1217,8 +1271,10 @@ public void errorProperlyReportedWhenInvalidConfigurationConfiguration() throws // It would be absolutely insane for a user to have a toolchain w/ a config_setting that reads a // config_feature_flag; however, should still test the InvalidConfigurationException codepath. rewriteModuleDotBazel( - "register_toolchains('//strange:strange_toolchain')", - "register_execution_platforms('//platforms:mac', '//platforms:linux')"); + """ + register_toolchains("//strange:strange_toolchain") + register_execution_platforms("//platforms:mac", "//platforms:linux") + """); scratch.file( "strange/BUILD", """ diff --git a/src/test/java/com/google/devtools/build/lib/starlark/StarlarkOptionsParsingTest.java b/src/test/java/com/google/devtools/build/lib/starlark/StarlarkOptionsParsingTest.java index 774452d74acc51..ffcd4c762807ed 100644 --- a/src/test/java/com/google/devtools/build/lib/starlark/StarlarkOptionsParsingTest.java +++ b/src/test/java/com/google/devtools/build/lib/starlark/StarlarkOptionsParsingTest.java @@ -104,12 +104,16 @@ def _impl(ctx): """); rewriteModuleDotBazel( - "module(name='starlark_options_test')", - "bazel_dep(name='repo2')", - "local_path_override(", - " module_name = 'repo2',", - " path = 'test/repo2',", - ")"); + """ + module(name = "starlark_options_test") + + bazel_dep(name = "repo2") + + local_path_override( + module_name = "repo2", + path = "test/repo2", + ) + """); OptionsParsingResult result = parseStarlarkOptions(