From 898d7b6138af73f03daf35b767d252560087de70 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 6 May 2019 02:11:37 -0700 Subject: [PATCH] Add test for repository overrides, conflicting with managed directories being added when Bazel server is already started. PiperOrigin-RevId: 246790372 --- .../ManagedDirectoriesBlackBoxTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/manageddirs/ManagedDirectoriesBlackBoxTest.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/manageddirs/ManagedDirectoriesBlackBoxTest.java index 28fa0c770f74df..56a004d42c0b49 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/manageddirs/ManagedDirectoriesBlackBoxTest.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/manageddirs/ManagedDirectoriesBlackBoxTest.java @@ -309,6 +309,37 @@ public void testRepositoryOverrideWithManagedDirectories() throws Exception { + " have managed directories: @generated_node_modules"); } + @Test + public void testRepositoryOverrideChangeToConflictWithManagedDirectories() throws Exception { + generateProject(); + buildExpectRepositoryRuleCalled(); + checkProjectFiles(); + + Path override = context().getTmpDir().resolve("override"); + PathUtils.writeFile(override.resolve(WORKSPACE)); + // Just define some similar target. + PathUtils.writeFile( + override.resolve("BUILD"), + "genrule(", + " name = \"example-module\",", + " srcs = [],", + " cmd = \"touch $(location package.json)\",", + " outs = [\"package.json\"],", + " visibility = ['//visibility:public'],", + ")"); + + // Now the overrides change. + BuilderRunner bazel = + bazel().withFlags("--override_repository=generated_node_modules=" + override.toString()); + ProcessResult result = bazel.shouldFail().build("@generated_node_modules//:example-module"); + assertThat(result.errString()) + .contains( + "ERROR: Overriding repositories is not allowed" + + " for the repositories with managed directories." + + "\nThe following overridden external repositories" + + " have managed directories: @generated_node_modules"); + } + private void generateProject() throws IOException { for (String fileName : FILES) { String text = ResourceFileLoader.loadResource(ManagedDirectoriesBlackBoxTest.class, fileName);