Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable WORKSPACE in java integration tests #23086

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public BlackBoxTestContext prepareEnvironment(
new BlackBoxTestContext(
testName, "bazel", binaryPath, Collections.emptyMap(), executorService);
// Any Bazel command requires that workspace is already set up.
testContext.write("WORKSPACE", "workspace(name = 'main')", getWorkspaceWithDefaultRepos());
testContext.write("MODULE.bazel");
Path defaultLockfile = RunfilesUtil.find("io_bazel/src/test/tools/bzlmod/MODULE.bazel.lock");
Files.copy(defaultLockfile, testContext.getWorkDir().resolve("MODULE.bazel.lock"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,11 @@
/** Setup for Bazel default tools */
public class DefaultToolsSetup implements ToolsSetup {

private static ImmutableList<String> repos =
ImmutableList.<String>builder()
.add("bazel_skylib")
.add("rules_cc")
.add("rules_proto")
.add("rules_java")
.add("rules_java_builtin_for_testing")
.add("rules_python")
.build();

private ImmutableList<String> getRepositoryOverrides() {
String sharedRepoHome = System.getenv("TEST_REPOSITORY_HOME");
if (sharedRepoHome == null) {
return ImmutableList.of();
}

Path sharedRepoHomePath = Paths.get(sharedRepoHome);
if (!Files.exists(sharedRepoHomePath)) {
return ImmutableList.of();
}

ImmutableList.Builder<String> lines = ImmutableList.builder();
for (String repo : repos) {
Path sharedRepoPath = sharedRepoHomePath.resolve(repo);
String suffix = "_for_testing";
repo = repo.endsWith(suffix) ? repo.substring(0, repo.length() - suffix.length()) : repo;
lines.add(
"common --override_repository="
+ repo
+ "="
+ sharedRepoPath.toString().replace('\\', '/'));
}

return lines.build();
}

@Override
public void setup(BlackBoxTestContext context) throws IOException {
Path outputRoot = Files.createTempDirectory(context.getTmpDir(), "root").toAbsolutePath();
ArrayList<String> lines = new ArrayList<>();
lines.add("startup --output_user_root=" + outputRoot.toString().replace('\\', '/'));
lines.addAll(getRepositoryOverrides());

String sharedInstallBase = System.getenv("TEST_INSTALL_BASE");
if (sharedInstallBase != null) {
Expand All @@ -93,6 +56,8 @@ public void setup(BlackBoxTestContext context) throws IOException {
lines.add("build --jvmopt=-Djava.net.preferIPv6Addresses");
}

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

context.write(".bazelrc", lines);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,4 @@ public final void dispose() {
MoreExecutors.shutdownAndAwaitTermination(executorService, 1, TimeUnit.SECONDS);
executorService = null;
}

public static String getWorkspaceWithDefaultRepos() throws IOException {
return ResourceFileLoader.loadResource(BlackBoxTestEnvironment.class, "blackbox.WORKSPACE");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public abstract class AbstractBlackBoxTest {
new JavaToolsSetup(),
new CxxToolsSetup(),
new CrossToolsSetup());
protected static final String WORKSPACE = "WORKSPACE";
protected static final String MODULE_DOT_BAZEL = "MODULE.bazel";

@Rule public TestName testName = new TestName();

Expand Down Expand Up @@ -81,6 +81,7 @@ public void setUp() throws Exception {

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

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public void testCompileAndRunHelloWorldStub() throws Exception {
}

private void writeHelloWorldFiles() throws IOException {
context().write("WORKSPACE", BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos());
context().write("python/hello/BUILD", "py_binary(name = 'hello', srcs = ['hello.py'])");
context().write("python/hello/hello.py", String.format("print ('%s')", HELLO));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class BazelEmbeddedStarlarkBlackBoxTest extends AbstractBlackBoxTest {

@Test
public void testPkgTar() throws Exception {
context().write("main/WORKSPACE", BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos());
context().write("main/foo.txt", "Hello World");
context().write("main/bar.txt", "Hello World, again");
context()
Expand Down Expand Up @@ -89,11 +88,12 @@ public void testHttpArchive() throws Exception {

context()
.write(
"WORKSPACE",
BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos(),
"MODULE.bazel",
"local_repository = use_repo_rule('@bazel_tools//tools/build_defs/repo:local.bzl', 'local_repository')",
String.format(
"local_repository(name=\"ext_local\", path=\"%s\",)",
PathUtils.pathForStarlarkFile(repo)),
"http_archive = use_repo_rule('@bazel_tools//tools/build_defs/repo:http.bzl', 'http_archive')",
String.format(
"http_archive(name=\"ext\", urls=[\"%s\"],)", PathUtils.pathToFileURI(zipFile)));

Expand All @@ -109,13 +109,13 @@ public void testHttpArchive() throws Exception {
String tarTarget = generator.getPkgTarTarget();
bazel.build("@ext_local//:" + tarTarget);
Path packedFile =
context().resolveBinPath(bazel, String.format("external/ext_local/%s.tar", tarTarget));
context().resolveBinPath(bazel, String.format("external/_main~_repo_rules~ext_local/%s.tar", tarTarget));
Files.copy(packedFile, zipFile);

// now build the target from http_archive
bazel.build("@ext//:" + RepoWithRuleWritingTextGenerator.TARGET);

Path xPath = context().resolveBinPath(bazel, "external/ext/out");
Path xPath = context().resolveBinPath(bazel, "external/_main~_repo_rules~ext/out");
WorkspaceTestUtils.assertLinesExactly(xPath, HELLO_FROM_EXTERNAL_REPOSITORY);

// and use the rule from http_archive in the main repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public void testCloneAtTag() throws Exception {
loadRule(""), callRule("call_write_text", "out.txt", HELLO_FROM_EXTERNAL_REPOSITORY));
context()
.write(
"WORKSPACE",
"load(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"new_git_repository\")",
"MODULE.bazel",
"new_git_repository = use_repo_rule(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"new_git_repository\")",
"new_git_repository(",
" name='ext',",
String.format(" remote='%s',", PathUtils.pathToFileURI(repo.resolve(".git"))),
Expand All @@ -83,7 +83,7 @@ public void testCloneAtTag() throws Exception {
// This creates Bazel without MSYS, see implementation for details.
BuilderRunner bazel = WorkspaceTestUtils.bazel(context());
bazel.build("@ext//:call_write_text");
Path outPath = context().resolveBinPath(bazel, "external/ext/out.txt");
Path outPath = context().resolveBinPath(bazel, "external/_main~_repo_rules~ext/out.txt");
WorkspaceTestUtils.assertLinesExactly(outPath, HELLO_FROM_EXTERNAL_REPOSITORY);
}

Expand All @@ -102,8 +102,8 @@ public void testCloneAtCommit() throws Exception {
loadRule(""), callRule("call_write_text", "out.txt", HELLO_FROM_EXTERNAL_REPOSITORY));
context()
.write(
"WORKSPACE",
"load(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"new_git_repository\")",
"MODULE.bazel",
"new_git_repository = use_repo_rule(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"new_git_repository\")",
"new_git_repository(",
" name='ext',",
String.format(" remote='%s',", PathUtils.pathToFileURI(repo.resolve(".git"))),
Expand All @@ -114,7 +114,7 @@ public void testCloneAtCommit() throws Exception {
// This creates Bazel without MSYS, see implementation for details.
BuilderRunner bazel = WorkspaceTestUtils.bazel(context());
bazel.build("@ext//:call_write_text");
Path outPath = context().resolveBinPath(bazel, "external/ext/out.txt");
Path outPath = context().resolveBinPath(bazel, "external/_main~_repo_rules~ext/out.txt");
WorkspaceTestUtils.assertLinesExactly(outPath, HELLO_FROM_EXTERNAL_REPOSITORY);
}

Expand All @@ -133,8 +133,8 @@ public void testCloneAtMain() throws Exception {
loadRule(""), callRule("call_write_text", "out.txt", HELLO_FROM_EXTERNAL_REPOSITORY));
context()
.write(
"WORKSPACE",
"load(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"new_git_repository\")",
"MODULE.bazel",
"new_git_repository = use_repo_rule(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"new_git_repository\")",
"new_git_repository(",
" name='ext',",
String.format(" remote='%s',", PathUtils.pathToFileURI(repo.resolve(".git"))),
Expand All @@ -145,7 +145,7 @@ public void testCloneAtMain() throws Exception {
// This creates Bazel without MSYS, see implementation for details.
BuilderRunner bazel = WorkspaceTestUtils.bazel(context());
bazel.build("@ext//:call_write_text");
Path outPath = context().resolveBinPath(bazel, "external/ext/out.txt");
Path outPath = context().resolveBinPath(bazel, "external/_main~_repo_rules~ext/out.txt");
WorkspaceTestUtils.assertLinesExactly(outPath, HELLO_FROM_EXTERNAL_REPOSITORY);
}

Expand Down Expand Up @@ -178,8 +178,8 @@ public void testCheckoutOfCommitFromBranch() throws Exception {

context()
.write(
"WORKSPACE",
"load(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")",
"MODULE.bazel",
"git_repository = use_repo_rule(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")",
"git_repository(",
" name='ext',",
String.format(" remote='%s',", PathUtils.pathToFileURI(repo.resolve(".git"))),
Expand All @@ -189,7 +189,7 @@ public void testCheckoutOfCommitFromBranch() throws Exception {
// This creates Bazel without MSYS, see implementation for details.
BuilderRunner bazel = WorkspaceTestUtils.bazel(context());
bazel.build("@ext//:write_text");
Path outPath = context().resolveBinPath(bazel, "external/ext/out");
Path outPath = context().resolveBinPath(bazel, "external/_main~_repo_rules~ext/out");
WorkspaceTestUtils.assertLinesExactly(outPath, HELLO_FROM_BRANCH);
}

Expand Down Expand Up @@ -228,8 +228,8 @@ public void testCheckoutOfCommitFromTag() throws Exception {

context()
.write(
"WORKSPACE",
"load(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")",
"MODULE.bazel",
"git_repository = use_repo_rule(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")",
"git_repository(",
" name='ext',",
String.format(" remote='%s',", PathUtils.pathToFileURI(repo.resolve(".git"))),
Expand All @@ -239,7 +239,7 @@ public void testCheckoutOfCommitFromTag() throws Exception {
// This creates Bazel without MSYS, see implementation for details.
BuilderRunner bazel = WorkspaceTestUtils.bazel(context());
bazel.build("@ext//:write_text");
Path outPath = context().resolveBinPath(bazel, "external/ext/out");
Path outPath = context().resolveBinPath(bazel, "external/_main~_repo_rules~ext/out");
WorkspaceTestUtils.assertLinesExactly(outPath, HELLO_FROM_BRANCH);
}

Expand All @@ -248,8 +248,8 @@ public void testCheckoutOfCommitFromTag() throws Exception {
public void testGitRepositoryErrorMessage() throws Exception {
context()
.write(
"WORKSPACE",
"load(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")",
"MODULE.bazel",
"git_repository = use_repo_rule(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")",
"git_repository(",
" name='ext',",
" remote='file:///some_path',",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def _patched_repo_implementation(ctx):
""");
context()
.write(
WORKSPACE,
"load(\":patched_repo.bzl\", \"patched_repo\")",
MODULE_DOT_BAZEL,
"patched_repo = use_repo_rule(\"//:patched_repo.bzl\", \"patched_repo\")",
"",
"patched_repo(",
" name = \"test\",",
Expand Down Expand Up @@ -157,7 +157,7 @@ public void testFallBackToPatchToolDueToPatchArgs() throws Exception {
} else {
assertFooIsPatched(bazel);
// foo.sh.orig should be generated due to "-b" argument.
Path fooOrig = context().resolveExecRootPath(bazel, "external/test/foo.sh.orig");
Path fooOrig = context().resolveExecRootPath(bazel, "external/_main~_repo_rules~test/foo.sh.orig");
assertThat(fooOrig.toFile().exists()).isTrue();
}
}
Expand Down Expand Up @@ -200,7 +200,7 @@ public void testFallBackToPatchCmdsWhenPatchCmdsWinNotSpecified() throws Excepti
}

private void assertFooIsPatched(BuilderRunner bazel) throws Exception {
Path foo = context().resolveExecRootPath(bazel, "external/test/foo.sh");
Path foo = context().resolveExecRootPath(bazel, "external/_main~_repo_rules~test/foo.sh");
assertThat(foo.toFile().exists()).isTrue();
ImmutableList<String> patchedFoo =
ImmutableList.of(
Expand Down
Loading
Loading