From 750a0389780c9eff49e1ede7647e28949b1996b7 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 10 Apr 2024 12:19:56 -0700 Subject: [PATCH] Copy `--experimental_override_name_platform_in_output_dir` to exec config PiperOrigin-RevId: 623570382 Change-Id: Ia0892125e1312ffe29f60f51a69d281636ccbbd3 --- .../config/ExecutionTransitionFactory.java | 2 + .../BuildConfigurationFunctionTest.java | 59 +++++++++++++++++++ .../ExecutionTransitionFactoryTest.java | 44 +++++++++++++- 3 files changed, 103 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/ExecutionTransitionFactory.java b/src/main/java/com/google/devtools/build/lib/analysis/config/ExecutionTransitionFactory.java index 51f93be7e10625..0c44911c5f7930 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/ExecutionTransitionFactory.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/ExecutionTransitionFactory.java @@ -242,6 +242,8 @@ public BuildOptions patch(BuildOptionsView options, EventHandler eventHandler) options.underlying().get(CoreOptions.class).affectedByStarlarkTransition; coreOptions.executionInfoModifier = options.underlying().get(CoreOptions.class).executionInfoModifier; + coreOptions.overrideNamePlatformInOutputDirEntries = + options.underlying().get(CoreOptions.class).overrideNamePlatformInOutputDirEntries; return result; } } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationFunctionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationFunctionTest.java index c8be510ac88ce3..a078f1060aa8c7 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationFunctionTest.java @@ -534,4 +534,63 @@ def _basic_impl(ctx): .isEqualTo(CppConfiguration.DynamicMode.OFF); assertThat(getConfiguration(dep).getFragment(JavaConfiguration.class).getUseIjars()).isTrue(); } + + @Test + public void testPlatformExplicitInOutputDirAndDynamicBaseline_withExecConfigDep() + throws Exception { + writeAllowlistFile(); + scratch.file( + "test/rules.bzl", + """ + load("//myinfo:myinfo.bzl", "MyInfo") + + def _impl(ctx): + return MyInfo(dep = ctx.attr.dep) + + my_rule = rule( + implementation = _impl, + attrs = { + "dep": attr.label(cfg = 'exec'), + }, + ) + """); + scratch.file( + "test/BUILD", + """ + load("//test:rules.bzl", "my_rule") + + my_rule( + name = "test", + dep = ":dep", + ) + + my_rule( + name = "dep", + ) + """); + scratch.file( + "platforms/BUILD", + """ + platform(name = "alpha") + """); + + useConfiguration( + "--compilation_mode=fastbuild", + "--platforms=//platforms:alpha", + "--host_platform=//platforms:alpha", + "--experimental_platform_in_output_dir", + "--noexperimental_use_platforms_in_output_dir_legacy_heuristic", + "--experimental_override_name_platform_in_output_dir=//platforms:alpha=alpha-override", + "--experimental_output_directory_naming_scheme=diff_against_dynamic_baseline"); + ConfiguredTarget test = getConfiguredTarget("//test"); + + assertThat(getMnemonic(test)).contains("alpha-override-fastbuild"); + assertThat(getMnemonic(test)).doesNotContain("-ST-"); + + ConfiguredTarget dep = (ConfiguredTarget) getMyInfoFromTarget(test).getValue("dep"); + + // The platform name override is used in dep with exec config + assertThat(getMnemonic(dep)).contains("alpha-override-opt-exec"); + assertThat(getMnemonic(dep)).doesNotContain("-ST-"); + } } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/config/ExecutionTransitionFactoryTest.java b/src/test/java/com/google/devtools/build/lib/analysis/config/ExecutionTransitionFactoryTest.java index 4e80fef9119c90..c222a50753914d 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/config/ExecutionTransitionFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/config/ExecutionTransitionFactoryTest.java @@ -71,9 +71,9 @@ public void executionTransition() throws Exception { assertThat(result).isNotNull(); assertThat(result).isNotSameInstanceAs(options); - assertThat(result.contains(CoreOptions.class)).isNotNull(); + assertThat(result.contains(CoreOptions.class)).isTrue(); assertThat(result.get(CoreOptions.class).isExec).isTrue(); - assertThat(result.contains(PlatformOptions.class)).isNotNull(); + assertThat(result.contains(PlatformOptions.class)).isTrue(); assertThat(result.get(PlatformOptions.class).platforms).containsExactly(EXECUTION_PLATFORM); } @@ -280,4 +280,44 @@ public void incompatibleOptionsPreservedInExec() throws Exception { assertThat(missingMetadataTagOptions).isEmpty(); assertThat(unpreservedOptions.build()).isEmpty(); } + + @Test + public void platformInOutputPathWorksInExecMode() throws Exception { + scratch.file( + "platforms/BUILD", + """ + platform(name = "mock_platform") + """); + scratch.file( + "test/lib.bzl", + """ + my_rule = rule( + implementation = lambda ctx: [], + attrs = { + "exec_deps": attr.label_list(cfg = "exec"), + }, + ) + """); + scratch.file( + "test/BUILD", + """ + load(":lib.bzl", "my_rule") + my_rule( + name = "parent", + exec_deps = [":child"] + ) + my_rule(name = "child") + """); + + useConfiguration( + "--experimental_platform_in_output_dir", + "--extra_execution_platforms=//platforms:mock_platform", + "--experimental_override_name_platform_in_output_dir=//platforms:mock_platform=mock_platform_path_string"); + BuildConfigurationValue execConfig = + getConfiguration( + getDirectPrerequisite(getConfiguredTarget("//test:parent"), "//test:child")); + + assertThat(execConfig.isExecConfiguration()).isTrue(); + assertThat(execConfig.getOutputDirectoryName()).isEqualTo("mock_platform_path_string-opt-exec"); + } }