aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-12-05 21:47:20 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-12-06 12:05:35 +0000
commit84e7bbc03d22a98e1036c9a3abf1d451e602348b (patch)
tree2322782f43d7e05d2e9a69e73e6cec115e6f3554 /src/test/java/com/google/devtools/build/lib
parent09b92a8fc9a6e4fcf451c71be098d9ba6ab379ac (diff)
Pass isExternal field to blaze ide info proto
Roll forward after fixing tests. The intellij aspect tests now correctly retains the required toolchain targets in the WORKSPACE file. -- PiperOrigin-RevId: 141093346 MOS_MIGRATED_REVID=141093346
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r--src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTest.java57
-rw-r--r--src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTestBase.java11
2 files changed, 64 insertions, 4 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTest.java b/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTest.java
index 6d157edb7b..649c3ff6b6 100644
--- a/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTest.java
+++ b/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTest.java
@@ -20,7 +20,9 @@ import static org.junit.Assert.assertNotNull;
import com.google.common.collect.Iterables;
import com.google.common.collect.ObjectArrays;
+import com.google.devtools.build.lib.actions.Root;
import com.google.devtools.build.lib.cmdline.RepositoryName;
+import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.ArtifactLocation;
import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo;
import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo;
@@ -60,6 +62,7 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase
assertThat(Paths.get(location.getRelativePath()).toString())
.isEqualTo(Paths.get("com/google/example/BUILD").toString());
assertThat(location.getIsSource()).isTrue();
+ assertThat(location.getIsExternal()).isFalse();
assertThat(targetIdeInfo.getKindString()).isEqualTo("java_library");
assertThat(relativePathsForJavaSourcesOf(targetIdeInfo))
.containsExactly("com/google/example/simple/Simple.java");
@@ -97,7 +100,6 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase
} else {
assertEquals(packageManifest.getRelativePath(), "com/google/example/simple.java-manifest");
}
-
}
@Test
@@ -1812,6 +1814,59 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase
buildIdeInfo("//com/google/example:foo");
}
+ @Test
+ public void testExternalRootCorrectlyIdentified() throws Exception {
+ ArtifactLocation location =
+ AndroidStudioInfoAspect.makeArtifactLocation(
+ Root.asSourceRoot(outputBase, false), new PathFragment("external/foo/bar.jar"));
+ assertThat(location.getIsExternal()).isTrue();
+ }
+
+ @Test
+ public void testNonExternalRootCorrectlyIdentified() throws Exception {
+ ArtifactLocation location =
+ AndroidStudioInfoAspect.makeArtifactLocation(
+ Root.asSourceRoot(rootDirectory, true), new PathFragment("foo/bar.jar"));
+ assertThat(location.getIsExternal()).isFalse();
+ }
+
+ @Test
+ public void testExternalTarget() throws Exception {
+ scratch.file(
+ "/r/BUILD", "java_import(", " name = 'junit',", " jars = ['junit.jar'],", ")");
+ scratch.file("/r/junit.jar");
+
+ // AnalysisMock adds required toolchains, etc. to WORKSPACE, so retain the previous contents.
+ String oldContents = scratch.readFile("WORKSPACE");
+ scratch.overwriteFile("WORKSPACE", oldContents + "\nlocal_repository(name='r', path='/r')");
+ invalidatePackages();
+
+ scratch.file(
+ "com/google/example/BUILD",
+ "java_library(",
+ " name = 'junit',",
+ " exports = ['@r//:junit'],",
+ ")");
+
+ Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:junit");
+ assertThat(
+ getTargetIdeInfoAndVerifyLabel("//com/google/example:junit", targetIdeInfos)
+ .getBuildFileArtifactLocation()
+ .getIsExternal())
+ .isFalse();
+
+ TargetIdeInfo targetInfo = getTargetIdeInfoAndVerifyLabel("@r//:junit", targetIdeInfos);
+ assertThat(targetInfo.getBuildFileArtifactLocation().getIsExternal()).isTrue();
+ assertThat(targetInfo.getBuildFileArtifactLocation().getRelativePath()).startsWith("external");
+
+ JavaIdeInfo javaInfo = targetInfo.getJavaIdeInfo();
+ assertThat(javaInfo.getJarsList()).hasSize(1);
+ ArtifactLocation jar = javaInfo.getJars(0).getJar();
+ assertThat(jar.getIsSource()).isTrue();
+ assertThat(jar.getIsExternal()).isTrue();
+ assertThat(jar.getRelativePath()).isEqualTo("external/r/junit.jar");
+ }
+
/**
* Returns true if we are testing the native aspect, not the Skylark one. Eventually Skylark
* aspect will be equivalent to a native one, and this method will be removed.
diff --git a/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTestBase.java b/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTestBase.java
index 2bbc0ce2ca..e9541691f7 100644
--- a/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTestBase.java
+++ b/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTestBase.java
@@ -72,22 +72,27 @@ abstract class AndroidStudioInfoAspectTestBase extends BuildViewTestCase {
StringBuilder stringBuilder = new StringBuilder();
if (libraryArtifact.hasJar()) {
stringBuilder.append("<jar:");
- stringBuilder.append(libraryArtifact.getJar().getRelativePath());
+ stringBuilder.append(artifactLocationPath(libraryArtifact.getJar()));
stringBuilder.append(">");
}
if (libraryArtifact.hasInterfaceJar()) {
stringBuilder.append("<ijar:");
- stringBuilder.append(libraryArtifact.getInterfaceJar().getRelativePath());
+ stringBuilder.append(artifactLocationPath(libraryArtifact.getInterfaceJar()));
stringBuilder.append(">");
}
if (libraryArtifact.hasSourceJar()) {
stringBuilder.append("<source:");
- stringBuilder.append(libraryArtifact.getSourceJar().getRelativePath());
+ stringBuilder.append(artifactLocationPath(libraryArtifact.getSourceJar()));
stringBuilder.append(">");
}
return stringBuilder.toString();
}
+
+ private String artifactLocationPath(ArtifactLocation artifact) {
+ String relativePath = artifact.getRelativePath();
+ return artifact.getIsExternal() ? relativePath + "[external]" : relativePath;
+ }
};
protected ConfiguredAspect configuredAspect;