summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarima Ichou <karimai@google.com>2022-05-13 15:10:05 +0100
committerKarima Ichou <karimai@google.com>2022-05-16 18:29:16 +0000
commit8c0fc8ddde8f0cdae8ad6c5b91663f83b2b7bb4e (patch)
tree87daae18b331a4ad88ac58bd9e03ee8418746068
parent2b7a9696150e99b0bad75692d16dedabee0c62b2 (diff)
downloadidea-8c0fc8ddde8f0cdae8ad6c5b91663f83b2b7bb4e.tar.gz
[Unit Tests] Add compiler output info for GradleSourceSets.
Now that we use MPSS, we do have all the Gradle sources as modules, and they should also specify information about the compiler output paths. Bug: N/A Test: verified manually through running tests with coverage. Change-Id: I1e08d7229542481b1ae06306bb3cc43d873f98a2
-rw-r--r--android-test-framework/testSrc/com/android/tools/idea/testing/AndroidGradleTestUtils.kt2
-rw-r--r--android/testData/snapshots/syncedProjects/kmp.txt2
-rw-r--r--project-system-gradle/src/com/android/tools/idea/gradle/project/sync/idea/AndroidGradleProjectResolver.java2
-rw-r--r--project-system-gradle/src/com/android/tools/idea/gradle/project/sync/idea/CompilerOutputUtil.kt16
4 files changed, 19 insertions, 3 deletions
diff --git a/android-test-framework/testSrc/com/android/tools/idea/testing/AndroidGradleTestUtils.kt b/android-test-framework/testSrc/com/android/tools/idea/testing/AndroidGradleTestUtils.kt
index 7314445d460..348cba06f23 100644
--- a/android-test-framework/testSrc/com/android/tools/idea/testing/AndroidGradleTestUtils.kt
+++ b/android-test-framework/testSrc/com/android/tools/idea/testing/AndroidGradleTestUtils.kt
@@ -1959,7 +1959,7 @@ private fun setupDataNodesForSelectedVariant(
} ?: return@forEach
// Now we need to recreate these nodes using the information from the new variant.
- moduleNode.setupCompilerOutputPaths(newVariant)
+ moduleNode.setupCompilerOutputPaths(newVariant, false)
// Then patch in any Kapt generated sources that we need
val libraryFilePaths = LibraryFilePaths.getInstance(project)
moduleNode.setupAndroidDependenciesForMpss({ path: GradleSourceSetProjectPath -> moduleIdToDataMap[path] }, { id ->
diff --git a/android/testData/snapshots/syncedProjects/kmp.txt b/android/testData/snapshots/syncedProjects/kmp.txt
index 4406895f0a4..aec4b0413cc 100644
--- a/android/testData/snapshots/syncedProjects/kmp.txt
+++ b/android/testData/snapshots/syncedProjects/kmp.txt
@@ -625,6 +625,8 @@ PROJECT : kotlinMultiPlatform
LinkedProjectPath : <PROJECT>/module2
RootProjectPath : <PROJECT>
COMPILER_MODULE_EXTENSION
+ compilerSourceOutputPath : file://<PROJECT>/module2/build/intermediates/javac/debug/classes [-]
+ compilerTestOutputPath : file://<PROJECT>/module2/build/intermediates/javac/debugUnitTest/classes [-]
isCompilerPathInherited : false
isExcludeOutput : true
ModuleFile : <PROJECT>/.idea/modules/module2/kotlinMultiPlatform.module2.iml [-]
diff --git a/project-system-gradle/src/com/android/tools/idea/gradle/project/sync/idea/AndroidGradleProjectResolver.java b/project-system-gradle/src/com/android/tools/idea/gradle/project/sync/idea/AndroidGradleProjectResolver.java
index 2b6e599726a..3fd04eff27e 100644
--- a/project-system-gradle/src/com/android/tools/idea/gradle/project/sync/idea/AndroidGradleProjectResolver.java
+++ b/project-system-gradle/src/com/android/tools/idea/gradle/project/sync/idea/AndroidGradleProjectResolver.java
@@ -324,7 +324,7 @@ public final class AndroidGradleProjectResolver extends AbstractProjectResolverE
public void populateModuleCompileOutputSettings(@NotNull IdeaModule gradleModule,
@NotNull DataNode<ModuleData> ideModule) {
super.populateModuleCompileOutputSettings(gradleModule, ideModule);
- CompilerOutputUtilKt.setupCompilerOutputPaths(ideModule);
+ CompilerOutputUtilKt.setupCompilerOutputPaths(ideModule, resolverCtx.isDelegatedBuild());
}
@Override
diff --git a/project-system-gradle/src/com/android/tools/idea/gradle/project/sync/idea/CompilerOutputUtil.kt b/project-system-gradle/src/com/android/tools/idea/gradle/project/sync/idea/CompilerOutputUtil.kt
index 0f242bff3ad..8e2adbf0c7a 100644
--- a/project-system-gradle/src/com/android/tools/idea/gradle/project/sync/idea/CompilerOutputUtil.kt
+++ b/project-system-gradle/src/com/android/tools/idea/gradle/project/sync/idea/CompilerOutputUtil.kt
@@ -21,21 +21,35 @@ import com.intellij.openapi.externalSystem.model.DataNode
import com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType
import com.intellij.openapi.externalSystem.model.project.ModuleData
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
+import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
/**
* Sets the compiler output paths on the module [DataNode].
*/
// TODO(b/213887150) : once this bug is fixed and we have code coverage exclusively with Jacoco, then this can be deleted.
@JvmOverloads
-fun DataNode<ModuleData>.setupCompilerOutputPaths(variant: IdeVariant? = null) {
+fun DataNode<ModuleData>.setupCompilerOutputPaths(variant: IdeVariant? = null, isDelegatedBuildUsed: Boolean) {
val androidModel = ExternalSystemApiUtil.find(this, AndroidProjectKeys.ANDROID_MODEL)?.data ?: return
val selectedVariant = variant ?: androidModel.selectedVariantCore
+ data.useExternalCompilerOutput(isDelegatedBuildUsed)
data.isInheritProjectCompileOutputPath = false
+ // TODO(b/232780259): Look for the compilation output folder. We can have both java and kotlin compilation outputs in classesFolder(IDEA-235250).
val sourceCompilerOutput = selectedVariant.mainArtifact.classesFolder.first().absolutePath
val testCompilerOutput = selectedVariant.unitTestArtifact?.classesFolder?.first()?.absolutePath
+
+ // MPSS: Set compilation data for Gradle sourceSets too.
+ for (sourceSet in ExternalSystemApiUtil.findAll(this, GradleSourceSetData.KEY)) {
+ val sourceSetData = sourceSet.data
+ sourceSetData.useExternalCompilerOutput(isDelegatedBuildUsed)
+ sourceSetData.setCompileOutputPath(ExternalSystemSourceType.SOURCE, null)
+ sourceSetData.setCompileOutputPath(ExternalSystemSourceType.TEST, null)
+ sourceSetData.setExternalCompilerOutputPath(ExternalSystemSourceType.SOURCE, sourceCompilerOutput)
+ sourceSetData.setExternalCompilerOutputPath(ExternalSystemSourceType.TEST, testCompilerOutput)
+ }
+
data.setCompileOutputPath(ExternalSystemSourceType.SOURCE, null)
data.setCompileOutputPath(ExternalSystemSourceType.TEST, null)
data.setExternalCompilerOutputPath(ExternalSystemSourceType.SOURCE, sourceCompilerOutput)