Skip to content

Commit

Permalink
Enable Bzlmod in Java integration tests
Browse files Browse the repository at this point in the history
Working towards: #18958

Closes #19785

PiperOrigin-RevId: 573178132
Change-Id: I1be73f1da7f77fd51d73fd07ba51da0ec2851c05
  • Loading branch information
meteorcloudy authored and copybara-github committed Oct 13, 2023
1 parent d51144c commit 8d04711
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ java_library(
srcs = [
"RunfilesUtil.java",
],
data = [
"//src/test/tools/bzlmod:MODULE.bazel.lock",
],
exports = [
"//src/test/java/com/google/devtools/build/lib/blackbox:base_deps",
"//src/test/java/com/google/devtools/build/lib/blackbox/framework",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.devtools.build.lib.blackbox.framework.BlackBoxTestEnvironment;
import com.google.devtools.build.lib.blackbox.framework.PathUtils;
import com.google.devtools.build.lib.blackbox.framework.ToolsSetup;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
Expand All @@ -41,6 +42,8 @@ public BlackBoxTestContext prepareEnvironment(
testName, "bazel", binaryPath, Collections.emptyMap(), executorService);
// Any Bazel command requires that workspace is already set up.
testContext.write("WORKSPACE", "workspace(name = 'main')", getWorkspaceWithDefaultRepos());
Path defaultLockfile = RunfilesUtil.find("io_bazel/src/test/tools/bzlmod/MODULE.bazel.lock");
Files.copy(defaultLockfile, testContext.getWorkDir().resolve("MODULE.bazel.lock"));

List<ToolsSetup> allTools = Lists.newArrayList(new DefaultToolsSetup());
allTools.addAll(tools);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public void setup(BlackBoxTestContext context) throws IOException {
}
}

lines.add("common --enable_bzlmod");

context.write(".bazelrc", lines);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public void setUp() throws Exception {
prepareEnvironment(getAdditionalTools());
}

public void disableBzlmod() throws Exception {
PathUtils.append(context.getWorkDir().resolve(".bazelrc"), "common --noenable_bzlmod");
}

@After
public void tearDown() throws Exception {
if (context != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public void testWorkspaceFileIsSymlink() throws Exception {
// Do not test file symlinks on Windows.
return;
}
disableBzlmod();
Path repo = context().getTmpDir().resolve(testName.getMethodName());
new RepoWithRuleWritingTextGenerator(repo).withOutputText("hi").setupRepository();

Expand Down

0 comments on commit 8d04711

Please sign in to comment.