diff options
author | 2015-10-02 03:40:36 +0000 | |
---|---|---|
committer | 2015-10-02 09:32:30 +0000 | |
commit | d12c05f2a9535216f15224518ad00e3c4b55be66 (patch) | |
tree | 528a739d1a512151bf408cc2c4706564e43142c2 /src/test/java | |
parent | ac0f10a9dcd3d482dd060b58c6a41f3767aa0b56 (diff) |
Add Android aspect resolve output group.
* Add ide-resolve output group
* Add jars, ijars, source jars
* Add idl jars
* Add gen jars
* Add java_import inputs (in case they are generated)
* Add manifest inputs (in case they are generated)
* Rename ide-build -> ide-info (build is too ambiguous)
* Remove generated manifest
--
MOS_MIGRATED_REVID=104464380
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTest.java | 142 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTestBase.java | 51 |
2 files changed, 174 insertions, 19 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 e88b0ec608..887ff944fd 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 @@ -35,11 +35,6 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase "java_library(", " name = 'simple',", " srcs = ['simple/Simple.java']", - ")", - "java_library(", - " name = 'complex',", - " srcs = ['complex/Complex.java'],", - " deps = [':simple']", ")"); Map<String, RuleIdeInfo> ruleIdeInfos = buildRuleIdeInfo("//com/google/example:simple"); assertThat(ruleIdeInfos.size()).isEqualTo(1); @@ -54,6 +49,12 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase transform(ruleIdeInfo.getJavaRuleIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING)) .containsExactly(jarString("com/google/example", "libsimple.jar", "libsimple-ijar.jar", "libsimple-src.jar")); + + assertThat(getIdeResolveFiles()).containsExactly( + "com/google/example/libsimple.jar", + "com/google/example/libsimple-ijar.jar", + "com/google/example/libsimple-src.jar" + ); } public void testJavaLibraryProtoWithDependencies() throws Exception { @@ -119,6 +120,17 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase assertThat(extraComplexRuleIdeInfo.getTransitiveDependenciesList()) .containsExactly("//com/google/example:simple", "//com/google/example:complex") .inOrder(); + assertThat(getIdeResolveFiles()).containsExactly( + "com/google/example/libextracomplex.jar", + "com/google/example/libextracomplex-ijar.jar", + "com/google/example/libextracomplex-src.jar", + "com/google/example/libcomplex.jar", + "com/google/example/libcomplex-ijar.jar", + "com/google/example/libcomplex-src.jar", + "com/google/example/libsimple.jar", + "com/google/example/libsimple-ijar.jar", + "com/google/example/libsimple-src.jar" + ); } public void testJavaLibraryWithDiamondDependencies() throws Exception { @@ -207,6 +219,17 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase "//com/google/example:simple", "//com/google/example:complex") .inOrder(); + assertThat(getIdeResolveFiles()).containsExactly( + "com/google/example/libextracomplex.jar", + "com/google/example/libextracomplex-ijar.jar", + "com/google/example/libextracomplex-src.jar", + "com/google/example/libcomplex.jar", + "com/google/example/libcomplex-ijar.jar", + "com/google/example/libcomplex-src.jar", + "com/google/example/libsimple.jar", + "com/google/example/libsimple-ijar.jar", + "com/google/example/libsimple-src.jar" + ); } public void testJavaLibraryWithTransitiveExports() throws Exception { @@ -286,6 +309,12 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase jarString("com/google/example", "a.jar", null, "impsrc.jar"), jarString("com/google/example", "b.jar", null, "impsrc.jar")) .inOrder(); + + assertThat(getIdeResolveFiles()).containsExactly( + "com/google/example/liblib.jar", + "com/google/example/liblib-ijar.jar", + "com/google/example/liblib-src.jar" + ); } public void testJavaImportWithExports() throws Exception { @@ -318,6 +347,31 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase .inOrder(); } + public void testGeneratedJavaImportFilesAreAddedToOutputGroup() throws Exception { + scratch.file( + "com/google/example/BUILD", + "java_import(", + " name = 'imp',", + " jars = [':gen_jar'],", + " srcjar = ':gen_srcjar',", + ")", + "genrule(", + " name = 'gen_jar',", + " outs = ['gen_jar.jar'],", + " cmd = '',", + ")", + "genrule(", + " name = 'gen_srcjar',", + " outs = ['gen_srcjar.jar'],", + " cmd = '',", + ")"); + buildTarget("//com/google/example:imp"); + assertThat(getIdeResolveFiles()).containsExactly( + "com/google/example/gen_jar.jar", + "com/google/example/gen_srcjar.jar" + ); + } + public void testAspectIsPropagatedAcrossExports() throws Exception { scratch.file( "com/google/example/BUILD", @@ -359,6 +413,14 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase assertThat(transform(testInfo.getJavaRuleIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING)) .containsExactly(jarString("java/com/google/example", "FooBarTest.jar", null, "FooBarTest-src.jar")); + + assertThat(getIdeResolveFiles()).containsExactly( + "java/com/google/example/libfoobar.jar", + "java/com/google/example/libfoobar-ijar.jar", + "java/com/google/example/libfoobar-src.jar", + "java/com/google/example/FooBarTest.jar", + "java/com/google/example/FooBarTest-src.jar" + ); } public void testJavaBinary() throws Exception { @@ -384,6 +446,14 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase assertThat(transform(binaryInfo.getJavaRuleIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING)) .containsExactly(jarString("com/google/example", "foobar-exe.jar", null, "foobar-exe-src.jar")); + + assertThat(getIdeResolveFiles()).containsExactly( + "com/google/example/libfoobar.jar", + "com/google/example/libfoobar-ijar.jar", + "com/google/example/libfoobar-src.jar", + "com/google/example/foobar-exe.jar", + "com/google/example/foobar-exe-src.jar" + ); } public void testAndroidLibrary() throws Exception { @@ -425,6 +495,14 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase ARTIFACT_TO_RELATIVE_PATH)) .containsExactly("com/google/example/r1", "com/google/example/res") .inOrder(); + assertThat(getIdeResolveFiles()).containsExactly( + "com/google/example/libl.jar", + "com/google/example/libl-ijar.jar", + "com/google/example/libl-src.jar", + "com/google/example/libl1.jar", + "com/google/example/libl1-ijar.jar", + "com/google/example/libl1-src.jar" + ); } public void testAndroidBinary() throws Exception { @@ -468,6 +546,15 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase ARTIFACT_TO_RELATIVE_PATH)) .containsExactly("com/google/example/r1", "com/google/example/res") .inOrder(); + + assertThat(getIdeResolveFiles()).containsExactly( + "com/google/example/libb.jar", + "com/google/example/libb-ijar.jar", + "com/google/example/libb-src.jar", + "com/google/example/libl1.jar", + "com/google/example/libl1-ijar.jar", + "com/google/example/libl1-src.jar" + ); } public void testAndroidInferredPackage() throws Exception { @@ -524,6 +611,35 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase "libhas_idl-idl.jar", null, "libhas_idl-idl.srcjar")); assertThat(relativePathsForSourcesOf(idlRuleInfo)) .isEmpty(); + assertThat(getIdeResolveFiles()).containsExactly( + "java/com/google/example/libhas_idl.jar", + "java/com/google/example/libhas_idl-ijar.jar", + "java/com/google/example/libhas_idl-src.jar", + "java/com/google/example/libhas_idl-idl.jar", + "java/com/google/example/libhas_idl-idl.srcjar" + ); + } + + public void testAndroidLibraryGeneratedManifestIsAddedToOutputGroup() throws Exception { + scratch.file( + "com/google/example/BUILD", + "android_library(", + " name = 'lib',", + " manifest = ':manifest',", + " custom_package = 'com.google.example',", + ")", + "genrule(", + " name = 'manifest',", + " outs = ['AndroidManifest.xml'],", + " cmd = '',", + ")"); + buildTarget("//com/google/example:lib"); + assertThat(getIdeResolveFiles()).containsExactly( + "com/google/example/liblib.jar", + "com/google/example/liblib-ijar.jar", + "com/google/example/liblib-src.jar", + "com/google/example/AndroidManifest.xml" + ); } public void testJavaLibraryWithoutGeneratedSourcesHasNoGenJars() throws Exception { @@ -547,6 +663,7 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase "java/com/google/example/BUILD", "java_library(", " name = 'test',", + " srcs = ['Test.java'],", " plugins = [':plugin']", ")", "java_plugin(", @@ -563,13 +680,18 @@ public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase RuleIdeInfo ruleIdeInfo = getRuleInfoAndVerifyLabel( "//java/com/google/example:test", ruleIdeInfos); - assertThat( - transform(ruleIdeInfo.getJavaRuleIdeInfo().getGeneratedJarsList(), - LIBRARY_ARTIFACT_TO_STRING)) + assertThat(transform( + ruleIdeInfo.getJavaRuleIdeInfo().getGeneratedJarsList(), + LIBRARY_ARTIFACT_TO_STRING)) .containsExactly(jarString("java/com/google/example", "libtest-gen.jar", null, "libtest-gensrc.jar")); - assertThat(relativePathsForSourcesOf(ruleIdeInfo)) - .isEmpty(); + assertThat(getIdeResolveFiles()).containsExactly( + "java/com/google/example/libtest.jar", + "java/com/google/example/libtest-ijar.jar", + "java/com/google/example/libtest-src.jar", + "java/com/google/example/libtest-gen.jar", + "java/com/google/example/libtest-gensrc.jar" + ); } public void testNonConformingPackageName() throws Exception { 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 772321ec54..4c6e7797ae 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 @@ -19,17 +19,22 @@ import static com.google.common.truth.Truth.assertThat; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; import com.google.common.eventbus.EventBus; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.analysis.Aspect; import com.google.devtools.build.lib.analysis.BuildView.AnalysisResult; +import com.google.devtools.build.lib.analysis.OutputGroupProvider; import com.google.devtools.build.lib.analysis.actions.BinaryFileWriteAction; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; +import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.ideinfo.androidstudio.AndroidStudioIdeInfo.ArtifactLocation; import com.google.devtools.build.lib.ideinfo.androidstudio.AndroidStudioIdeInfo.LibraryArtifact; import com.google.devtools.build.lib.ideinfo.androidstudio.AndroidStudioIdeInfo.RuleIdeInfo; import com.google.devtools.build.lib.skyframe.AspectValue; import java.util.Collection; +import java.util.List; import java.util.Map; import javax.annotation.Nullable; @@ -39,7 +44,7 @@ import javax.annotation.Nullable; */ abstract class AndroidStudioInfoAspectTestBase extends BuildViewTestCase { - public static final Function<ArtifactLocation, String> ARTIFACT_TO_RELATIVE_PATH = + protected static final Function<ArtifactLocation, String> ARTIFACT_TO_RELATIVE_PATH = new Function<ArtifactLocation, String>() { @Nullable @Override @@ -47,7 +52,7 @@ abstract class AndroidStudioInfoAspectTestBase extends BuildViewTestCase { return artifactLocation.getRelativePath(); } }; - public static final Function<LibraryArtifact, String> LIBRARY_ARTIFACT_TO_STRING = + protected static final Function<LibraryArtifact, String> LIBRARY_ARTIFACT_TO_STRING = new Function<LibraryArtifact, String>() { @Override public String apply(LibraryArtifact libraryArtifact) { @@ -72,7 +77,10 @@ abstract class AndroidStudioInfoAspectTestBase extends BuildViewTestCase { } }; - static String jarString(String base, String jar, String iJar, String sourceJar) { + private AnalysisResult analysisResult; + private Aspect aspect; + + protected static String jarString(String base, String jar, String iJar, String sourceJar) { StringBuilder sb = new StringBuilder(); if (jar != null) { sb.append("<jar:" + base + "/" + jar + ">"); @@ -97,8 +105,8 @@ abstract class AndroidStudioInfoAspectTestBase extends BuildViewTestCase { return ruleIdeInfo; } - protected Map<String, RuleIdeInfo> buildRuleIdeInfo(String target) throws Exception { - AnalysisResult analysisResult = + protected void buildTarget(String target) throws Exception { + this.analysisResult = update( ImmutableList.of(target), ImmutableList.of(AndroidStudioInfoAspect.NAME), @@ -109,17 +117,42 @@ abstract class AndroidStudioInfoAspectTestBase extends BuildViewTestCase { Collection<AspectValue> aspects = analysisResult.getAspects(); assertThat(aspects.size()).isEqualTo(1); AspectValue value = aspects.iterator().next(); - assertThat(value.getAspect().getName()).isEqualTo(AndroidStudioInfoAspect.NAME); + this.aspect = value.getAspect(); + assertThat(aspect.getName()).isEqualTo(AndroidStudioInfoAspect.NAME); + } + + protected Map<String, RuleIdeInfo> buildRuleIdeInfo(String target) throws Exception { + buildTarget(target); AndroidStudioInfoFilesProvider provider = - value.getAspect().getProvider(AndroidStudioInfoFilesProvider.class); - Iterable<Artifact> artifacts = provider.getIdeBuildFiles(); + aspect.getProvider(AndroidStudioInfoFilesProvider.class); + Iterable<Artifact> artifacts = provider.getIdeInfoFiles(); ImmutableMap.Builder<String, RuleIdeInfo> builder = ImmutableMap.builder(); for (Artifact artifact : artifacts) { BinaryFileWriteAction generatingAction = - (BinaryFileWriteAction) getGeneratingAction(artifact); + (BinaryFileWriteAction) getGeneratingAction(artifact); RuleIdeInfo ruleIdeInfo = RuleIdeInfo.parseFrom(generatingAction.getSource().openStream()); builder.put(ruleIdeInfo.getLabel(), ruleIdeInfo); } return builder.build(); } + + protected List<String> getOutputGroupResult(String outputGroup) { + OutputGroupProvider outputGroupProvider = this.aspect.getProvider(OutputGroupProvider.class); + assert outputGroupProvider != null; + NestedSet<Artifact> artifacts = outputGroupProvider.getOutputGroup(outputGroup); + + for (Artifact artifact : artifacts) { + assertThat(getGeneratingAction(artifact)).isNotNull(); + } + + List<String> artifactRelativePaths = Lists.newArrayList(); + for (Artifact artifact : artifacts) { + artifactRelativePaths.add(artifact.getRootRelativePathString()); + } + return artifactRelativePaths; + } + + protected List<String> getIdeResolveFiles() { + return getOutputGroupResult(AndroidStudioInfoAspect.IDE_RESOLVE); + } } |