Skip to content

Commit

Permalink
Convert calls to rewriteModuleDotBazel to use Java text blocks.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 690743742
Change-Id: Ic6182c9ee0551f3d4a6eca07fbcb1afba6896b75
  • Loading branch information
katre authored and copybara-github committed Oct 28, 2024
1 parent dde9cc8 commit 0f89dcc
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<RegisteredExecutionPlatformsValue> result =
Expand Down Expand Up @@ -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<RegisteredExecutionPlatformsValue> result =
Expand Down Expand Up @@ -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<RegisteredExecutionPlatformsValue> result =
Expand Down Expand Up @@ -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')");

Expand Down Expand Up @@ -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<RegisteredExecutionPlatformsValue> result =
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand All @@ -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",
"""
Expand Down Expand Up @@ -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",
"""
Expand Down Expand Up @@ -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<RegisteredToolchainsValue> result =
Expand Down Expand Up @@ -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<RegisteredToolchainsValue> result =
Expand Down Expand Up @@ -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<RegisteredToolchainsValue> result =
Expand All @@ -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);
Expand Down Expand Up @@ -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<RegisteredToolchainsValue> result =
Expand Down Expand Up @@ -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<RegisteredToolchainsValue> result =
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 =
Expand Down
Loading

0 comments on commit 0f89dcc

Please sign in to comment.