diff options
author | 2016-04-25 17:45:55 +0000 | |
---|---|---|
committer | 2016-04-26 08:29:08 +0000 | |
commit | d9121976fa7b39372027c70edddf9eb3c0bba7a6 (patch) | |
tree | 3975f0d7133450a47e4fb4faf033c31c8b23cfa3 /src/test/java | |
parent | a2841d3d9f87199a34e09fe6bd58ece9b84f2c58 (diff) |
Create runfiles at both .runfiles/ws/external/repo and .runfiles/repo
The major piece of #848.
RELNOTES[INC]: All repositories are now directly under the x.runfiles directory in the runfiles tree (previously, external repositories were at x.runfiles/main-repo/external/other-repo. This simplifies handling remote repository runfiles considerably, but will break existing references to external repository runfiles.
--
MOS_MIGRATED_REVID=120722312
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java | 76 |
1 files changed, 73 insertions, 3 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java b/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java index 7b806f371d..1f83f28005 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java @@ -16,10 +16,12 @@ package com.google.devtools.build.lib.analysis; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.Root; +import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.EventKind; import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.vfs.PathFragment; @@ -41,7 +43,7 @@ public class RunfilesTest extends FoundationTestCase { private void checkWarning() { assertContainsEvent("obscured by a -> /workspace/a"); assertEquals("Runfiles.filterListForObscuringSymlinks should have warned once", - 1, eventCollector.count()); + 1, eventCollector.count()); assertEquals(EventKind.WARNING, Iterables.getOnlyElement(eventCollector).getKind()); } @@ -83,7 +85,7 @@ public class RunfilesTest extends FoundationTestCase { root); obscuringMap.put(pathA, artifactA); obscuringMap.put(new PathFragment("a/b"), new Artifact(new PathFragment("c/b"), - root)); + root)); assertThat(Runfiles.filterListForObscuringSymlinks(null, null, obscuringMap).entrySet()) .containsExactly(Maps.immutableEntry(pathA, artifactA)).inOrder(); } @@ -117,7 +119,7 @@ public class RunfilesTest extends FoundationTestCase { root); obscuringMap.put(pathBC, artifactBC); assertThat(Runfiles.filterListForObscuringSymlinks(reporter, null, obscuringMap) - .entrySet()).containsExactly(Maps.immutableEntry(pathA, artifactA), + .entrySet()).containsExactly(Maps.immutableEntry(pathA, artifactA), Maps.immutableEntry(pathBC, artifactBC)); assertNoEvents(); } @@ -316,4 +318,72 @@ public class RunfilesTest extends FoundationTestCase { Runfiles r4 = new Runfiles.Builder("TESTING").merge(r2).merge(r1).build(); assertEquals(Runfiles.ConflictPolicy.ERROR, r4.getConflictPolicy()); } + + @Test + public void testLegacyRunfilesStructure() { + Root root = Root.asSourceRoot(scratch.resolve("/workspace")); + PathFragment workspaceName = new PathFragment("wsname"); + PathFragment pathB = new PathFragment("external/repo/b"); + Artifact artifactB = new Artifact(pathB, root); + + Runfiles.ManifestBuilder builder = new Runfiles.ManifestBuilder(workspaceName, true); + + Map<PathFragment, Artifact> inputManifest = Maps.newHashMap(); + inputManifest.put(pathB, artifactB); + Runfiles.ConflictChecker checker = new Runfiles.ConflictChecker( + Runfiles.ConflictPolicy.WARN, reporter, null); + builder.addUnderWorkspace(inputManifest, checker); + + assertThat(builder.build().entrySet()).containsExactly( + Maps.immutableEntry(workspaceName.getRelative(pathB), artifactB), + Maps.immutableEntry(new PathFragment("repo/b"), artifactB)); + assertNoEvents(); + } + + @Test + public void testRunfileAdded() { + Root root = Root.asSourceRoot(scratch.resolve("/workspace")); + PathFragment workspaceName = new PathFragment("wsname"); + PathFragment pathB = new PathFragment("external/repo/b"); + Artifact artifactB = new Artifact(pathB, root); + + Runfiles.ManifestBuilder builder = new Runfiles.ManifestBuilder(workspaceName, false); + + Map<PathFragment, Artifact> inputManifest = ImmutableMap.<PathFragment, Artifact>builder() + .put(pathB, artifactB) + .build(); + Runfiles.ConflictChecker checker = new Runfiles.ConflictChecker( + Runfiles.ConflictPolicy.WARN, reporter, null); + builder.addUnderWorkspace(inputManifest, checker); + + assertThat(builder.build().entrySet()).containsExactly( + Maps.immutableEntry(workspaceName.getRelative(".runfile"), null), + Maps.immutableEntry(new PathFragment("repo/b"), artifactB)); + assertNoEvents(); + } + + // TODO(kchodorow): remove this once the default workspace name is always set. + @Test + public void testConflictWithExternal() { + Root root = Root.asSourceRoot(scratch.resolve("/workspace")); + PathFragment pathB = new PathFragment("repo/b"); + PathFragment externalPathB = Label.EXTERNAL_PACKAGE_NAME.getRelative(pathB); + Artifact artifactB = new Artifact(pathB, root); + Artifact artifactExternalB = new Artifact(externalPathB, root); + + Runfiles.ManifestBuilder builder = new Runfiles.ManifestBuilder( + PathFragment.EMPTY_FRAGMENT, false); + + Map<PathFragment, Artifact> inputManifest = ImmutableMap.<PathFragment, Artifact>builder() + .put(pathB, artifactB) + .put(externalPathB, artifactExternalB) + .build(); + Runfiles.ConflictChecker checker = new Runfiles.ConflictChecker( + Runfiles.ConflictPolicy.WARN, reporter, null); + builder.addUnderWorkspace(inputManifest, checker); + + assertThat(builder.build().entrySet()).containsExactly( + Maps.immutableEntry(new PathFragment("repo/b"), artifactExternalB)); + checkConflictWarning(); + } } |