Skip to content

Commit

Permalink
Copy --experimental_override_name_platform_in_output_dir to exec co…
Browse files Browse the repository at this point in the history
…nfig

PiperOrigin-RevId: 623570382
Change-Id: Ia0892125e1312ffe29f60f51a69d281636ccbbd3
  • Loading branch information
mai93 authored and Kila2 committed May 13, 2024
1 parent 883c676 commit afb0f0c
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
}
}

0 comments on commit afb0f0c

Please sign in to comment.