diff options
author | Ivan Gavrilovic <gavra@google.com> | 2022-04-28 21:17:39 +0100 |
---|---|---|
committer | Alex Golubev <alexgolubev@google.com> | 2022-06-13 18:55:46 +0000 |
commit | 42326ca0f6c959fdfff8771e8bcb40012acb5c6f (patch) | |
tree | a16158f010db8941726a470c732cc22a647e2a8f | |
parent | 5b5187ed89b0c917d14b79cdaa147eaa828d979f (diff) | |
download | base-42326ca0f6c959fdfff8771e8bcb40012acb5c6f.tar.gz |
Add test for graph nodes with dependencies only
It is possible for nodes in the dependency graph
to contain only dependenices (no files). This commit
adds a test for such scenario.
Bug: 230648123
Test: FullDependencyGraphBuilderTest, DependencyWithoutFileWithDependenciesTest
Change-Id: I515ed12cd03d5072667f59cd8287779b801d6fe1
4 files changed, 170 insertions, 5 deletions
diff --git a/build-system/gradle-core/src/test/java/com/android/build/gradle/internal/ide/dependencies/FullDependencyGraphBuilderTest.kt b/build-system/gradle-core/src/test/java/com/android/build/gradle/internal/ide/dependencies/FullDependencyGraphBuilderTest.kt index 5c74aa3de5..afb715b41b 100644 --- a/build-system/gradle-core/src/test/java/com/android/build/gradle/internal/ide/dependencies/FullDependencyGraphBuilderTest.kt +++ b/build-system/gradle-core/src/test/java/com/android/build/gradle/internal/ide/dependencies/FullDependencyGraphBuilderTest.kt @@ -186,6 +186,27 @@ internal class FullDependencyGraphBuilderTest { .assertThat(graphs.compileDependencies.map { it.key }) .containsExactly("foo|bar-parent|1.0||", "foo|bar|1.0||") } + + /** Regression test for http://b/230648123. */ + @Test + fun testDependencyWithoutFileWithDependencies() { + val (graphs, _) = buildModelGraph { + module("foo", "bar", "1.0") { + file = null + // intentionally no file present, just a dependency on parent + dependency( + module("foo", "bar-parent", "1.0") { + file = File("path/to/bar-parent-1.0.jar") + } + ) + } + } + + // Once b/230648123 is fixed, this should contain "foo|bar-parent|1.0||", "foo|bar|1.0||". + Truth + .assertThat(graphs.compileDependencies.map { it.key }) + .isEmpty() + } } // ------------- diff --git a/build-system/gradle-core/src/test/java/com/android/build/gradle/internal/ide/dependencies/GraphUtils.kt b/build-system/gradle-core/src/test/java/com/android/build/gradle/internal/ide/dependencies/GraphUtils.kt index 3225dbacb5..eaed8a63ec 100644 --- a/build-system/gradle-core/src/test/java/com/android/build/gradle/internal/ide/dependencies/GraphUtils.kt +++ b/build-system/gradle-core/src/test/java/com/android/build/gradle/internal/ide/dependencies/GraphUtils.kt @@ -65,7 +65,7 @@ interface DependencyBuilder { interface DependencyNodeBuilder: DependencyBuilder { var dependencyType: DependencyType - var file: File + var file: File? fun capability(group: String, name: String, version: String? = null) fun <T: Any> attribute(attribute: Attribute<T>, value: T) @@ -158,9 +158,10 @@ open class DependencyBuilderImpl: DependencyBuilder { externalVariant = Optional.ofNullable(externalVariant) ) - // if there's an external variant due to relocation then that particular module - // will not have a matching artifact. - if (externalVariant == null) { + // Module will not have a matching artifact: + // - if there's an external variant due to relocation + // - file is missing e.g. there are only dependencies on other modules + if (externalVariant == null && node.file != null) { artifacts.add( ResolvedArtifact( componentIdentifier = componentIdentifier, @@ -217,7 +218,7 @@ abstract class DependencyNodeBuilderImpl: DependencyBuilderImpl(), DependencyNod abstract fun getComponentIdentifier(): ComponentIdentifier - override var file: File = File("") + override var file: File? = File("") override fun capability(group: String, name: String, version: String?) { capabilities.add(FakeCapability(group, name, version)) } diff --git a/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/model/AppModelTest.kt b/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/model/AppModelTest.kt index f2764ff32c..f61383fc82 100644 --- a/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/model/AppModelTest.kt +++ b/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/model/AppModelTest.kt @@ -21,6 +21,7 @@ import com.android.build.gradle.integration.common.fixture.model.ReferenceModelC import com.android.build.gradle.integration.common.fixture.testprojects.PluginType import com.android.build.gradle.integration.common.fixture.testprojects.createGradleProject import com.android.build.gradle.integration.common.fixture.testprojects.prebuilts.setUpHelloWorld +import com.android.build.gradle.options.BooleanOption import com.android.builder.model.v2.ide.SyncIssue import com.android.testutils.MavenRepoGenerator import com.android.testutils.TestInputsGenerator @@ -592,3 +593,76 @@ class RelocatedArtifactTest: ModelComparator() { with(result).compareVariantDependencies(goldenFile = "VariantDependencies") } } + +/** Regression test for http://b/229298359. */ +class DependencyWithoutFileWithDependenciesTest: ModelComparator() { + + @get:Rule + val project = createGradleProject { + subProject(":app") { + plugins.add(PluginType.ANDROID_APP) + android { + setUpHelloWorld() + } + appendToBuildFile { + """ + repositories { + maven { + url { '../repo' } + } + } + dependencies { + testImplementation("com.foo:bar:1.0") { + capabilities { + requireCapability("com.foo:bar-custom:1.0") + } + } + } + """.trimIndent() + } + } + subProject(":bar") { + plugins.add(PluginType.JAVA_LIBRARY) + plugins.add(PluginType.MAVEN_PUBLISH) + appendToBuildFile { + """ + group = "com.foo" + version = "1.0" + + Configuration customCapability = configurations.create("customCapability") + customCapability.setCanBeConsumed(true) + customCapability.setCanBeResolved(false) + customCapability.attributes.attribute( + TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, + objects.named(TargetJvmEnvironment.class, TargetJvmEnvironment.STANDARD_JVM) + ) + customCapability.outgoing.capability("com.foo:bar-custom:1.0") + dependencies.add("customCapability", 'androidx.collection:collection:1.0.0') + components.java.addVariantsFromConfiguration(customCapability) { mapToOptional() } + + publishing { + repositories { + maven { url = '../repo' } + } + publications { + mavenJava(MavenPublication) { + from components.java + } + } + } + """.trimIndent() + } + } + } + + @Test + fun `test models`() { + project.executor().run(":bar:publish") + val result = project.modelV2() + .with(BooleanOption.USE_ANDROID_X, true) + .ignoreSyncIssues(SyncIssue.SEVERITY_WARNING) + .fetchModels(variantName = "debug") + + with(result).compareVariantDependencies(goldenFile = "VariantDependencies") + } +} diff --git a/build-system/integration-test/application/src/test/resources/com/android/build/gradle/integration/model/DependencyWithoutFileWithDependenciesTest_VariantDependencies.txt b/build-system/integration-test/application/src/test/resources/com/android/build/gradle/integration/model/DependencyWithoutFileWithDependenciesTest_VariantDependencies.txt new file mode 100644 index 0000000000..e22c9f629a --- /dev/null +++ b/build-system/integration-test/application/src/test/resources/com/android/build/gradle/integration/model/DependencyWithoutFileWithDependenciesTest_VariantDependencies.txt @@ -0,0 +1,69 @@ +> VariantDependencies: + - name = "debug" + - mainArtifact: + - compileDependencies = [] + - runtimeDependencies = [] + - unresolvedDependencies = [] + - androidTestArtifact: + - compileDependencies: + - :|:app|debug|com.android.build.api.attributes.AgpVersionAttr>{AGP_Version}, com.android.build.gradle.internal.attributes.VariantAttr>debug, org.gradle.libraryelements>jar, org.gradle.usage>java-api|project:app:unspecified: + - requestedCoordinates = (null) + - dependencies = [] + - runtimeDependencies = [] + - unresolvedDependencies = [] + > unitTestArtifact: + - compileDependencies: + - :|:app|debug|com.android.build.api.attributes.AgpVersionAttr>{AGP_Version}, com.android.build.gradle.internal.attributes.VariantAttr>debug, org.gradle.libraryelements>jar, org.gradle.usage>java-api|project:app:unspecified: + - requestedCoordinates = (null) + - dependencies = [] + - runtimeDependencies: + - :|:app|debug|com.android.build.api.attributes.AgpVersionAttr>{AGP_Version}, com.android.build.gradle.internal.attributes.VariantAttr>debug, org.gradle.usage>java-runtime|project:app:unspecified: + - requestedCoordinates = (null) + - dependencies = [] + - unresolvedDependencies = [] + < unitTestArtifact + - testFixturesArtifact = (null) + > libraries: + > :|:app|debug|com.android.build.api.attributes.AgpVersionAttr>{AGP_Version}, com.android.build.gradle.internal.attributes.VariantAttr>debug, org.gradle.libraryelements>jar, org.gradle.usage>java-api|project:app:unspecified: + - type = PROJECT + - artifact = {PROJECT}/app/build/intermediates/compile_app_classes_jar/debug/classes.jar{!} + > projectInfo: + - buildId = ":" + - projectPath = ":app" + - isTestFixtures = false + - buildType = "debug" + - productFlavors = [] + - attributes: + * "com.android.build.api.attributes.AgpVersionAttr -> {AGP_Version}" + * "com.android.build.gradle.internal.attributes.VariantAttr -> debug" + * "org.gradle.libraryelements -> jar" + * "org.gradle.usage -> java-api" + - capabilities: + * "project:app:unspecified" + < projectInfo + - libraryInfo = (null) + - lintJar = (null) + - androidLibraryData = (null) + < :|:app|debug|com.android.build.api.attributes.AgpVersionAttr>{AGP_Version}, com.android.build.gradle.internal.attributes.VariantAttr>debug, org.gradle.libraryelements>jar, org.gradle.usage>java-api|project:app:unspecified + > :|:app|debug|com.android.build.api.attributes.AgpVersionAttr>{AGP_Version}, com.android.build.gradle.internal.attributes.VariantAttr>debug, org.gradle.usage>java-runtime|project:app:unspecified: + - type = PROJECT + - artifact = (null) + > projectInfo: + - buildId = ":" + - projectPath = ":app" + - isTestFixtures = false + - buildType = "debug" + - productFlavors = [] + - attributes: + * "com.android.build.api.attributes.AgpVersionAttr -> {AGP_Version}" + * "com.android.build.gradle.internal.attributes.VariantAttr -> debug" + * "org.gradle.usage -> java-runtime" + - capabilities: + * "project:app:unspecified" + < projectInfo + - libraryInfo = (null) + - lintJar = (null) + - androidLibraryData = (null) + < :|:app|debug|com.android.build.api.attributes.AgpVersionAttr>{AGP_Version}, com.android.build.gradle.internal.attributes.VariantAttr>debug, org.gradle.usage>java-runtime|project:app:unspecified + < libraries +< VariantDependencies |