Skip to content

Commit

Permalink
Ensure that tests set up execution platforms for test rules
Browse files Browse the repository at this point in the history
In preparation for changes to the resolution of exec platforms for tests, have analysis tests register exec platforms that are compatible with their tests' target platforms.

In `target_compatible_with_test`, replace a usage of `sh_test` with `sh_binary` to retain the setup as closely as possible by avoiding changes to constraints and platforms.

Also remove the remaining shell analysis tests now that shell rules have been moved out of the Bazel repo. Keeping them would require extensive mocking, at which point they would lose their purpose.

Closes #25142.

PiperOrigin-RevId: 727835756
Change-Id: I4b176d0beebdc66aab0b18521be0e538da31eeb3
  • Loading branch information
fmeum authored and copybara-github committed Feb 17, 2025
1 parent eb0f20b commit bc6e8d8
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ public static void injectShellExecutableFinder(
shellExecutables = osToShellMap;
}

/**
* Injects a map for locating the correct sh executable given a set of target constraints. Assumes
* no options-based default shell.
*/
public static void injectShellExecutableFinder(Map<OS, PathFragment> osToShellMap) {
optionsBasedDefault = (options) -> null;
shellExecutables = osToShellMap;
}

private final PathFragment defaultShellExecutableFromOptions;

public ShellConfiguration(BuildOptions buildOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ filegroup(
"//src/test/java/com/google/devtools/build/lib/bazel/rules/genrule:srcs",
"//src/test/java/com/google/devtools/build/lib/bazel/rules/java:srcs",
"//src/test/java/com/google/devtools/build/lib/bazel/rules/python:srcs",
"//src/test/java/com/google/devtools/build/lib/bazel/rules/sh:srcs",
],
visibility = ["//src:__subpackages__"],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ protected void useConfiguration(String... args) throws Exception {
targetCpu);
super.useConfiguration(
ObjectArrays.concat(
args, "--platforms=//" + PLATFORMS_PACKAGE_PATH + ":" + targetPlatform));
args,
new String[] {
"--platforms=//" + PLATFORMS_PACKAGE_PATH + ":" + targetPlatform,
"--extra_execution_platforms=//" + PLATFORMS_PACKAGE_PATH + ":" + targetPlatform
},
String.class));
}

@Test
Expand Down
43 changes: 0 additions & 43 deletions src/test/java/com/google/devtools/build/lib/bazel/rules/sh/BUILD

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/java/com/google/devtools/build/lib/buildtool/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,6 @@ build_test(
# Disabled in Google.
"//src/test/java/com/google/devtools/build/lib/bazel/rules/python:PythonTests",
# Disabled in Google.
"//src/test/java/com/google/devtools/build/lib/bazel/rules/sh:ShTests",
# Disabled in Google.
"//src/test/java/com/google/devtools/build/lib/packages:BazelDocumentationTests",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public void macRequiresDarwinForExecution() throws Exception {
" '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "cpu:x86_64',",
" ],",
")");
useConfiguration("--platforms=//platforms:darwin_x86_64");
useConfiguration(
"--platforms=//platforms:darwin_x86_64",
"--extra_execution_platforms=//platforms:darwin_x86_64");
scratch.file(
"pkg/BUILD", //
getPyLoad("py_test"),
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/integration/target_compatible_with_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ function test_cquery_with_glob() {
function test_cquery_incompatible_target() {
mkdir -p target_skipping
cat >> target_skipping/BUILD <<'EOF'
sh_test(
sh_binary(
name = "depender",
srcs = ["depender.sh"],
data = [":never_compatible"],
Expand Down

0 comments on commit bc6e8d8

Please sign in to comment.