aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-12-02 18:05:25 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2016-12-02 19:09:09 +0000
commit9de9f374cf63e8e6938c9ce80820c9f46f641241 (patch)
tree138a4c82d83bdb125649245bb94f62938bb35d10 /src/test
parente0a330577d9fe98169645cb68d9fc22cc787eeb6 (diff)
Pass isExternal field to blaze ide info proto
-- PiperOrigin-RevId: 140862659 MOS_MIGRATED_REVID=140862659
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTest.java54
-rw-r--r--src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTestBase.java11
2 files changed, 61 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..19611715e7 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,56 @@ 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");
+ scratch.overwriteFile("WORKSPACE", "local_repository(name='r', path='/r')");
+ invalidatePackages(/*alsoConfigs=*/ false); // Repository shuffling messes with toolchain labels
+
+ 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;