KT-49089 Fix using @OptionalExpectation annotations from dependencies

Fix the behavior of the common (metadata KLIB) compiler with
hierarchical project structures support as
it analyses usages of annotations from dependencies that are marked
with `@OptionalExpectations`.

The fix on the Kotlin Gradle plugin side is to add the
-Xcommon-sources=... compiler argument to those the invocations of the
compiler, just as it is done with the other compilers.

Issue #KT-49089 Verification Pending
This commit is contained in:
Sergey Igushkin
2022-01-25 00:37:09 +04:00
committed by Space
parent 9e1a771d57
commit 62c351874f
3 changed files with 20 additions and 1 deletions
@@ -34,6 +34,7 @@ import java.util.jar.JarFile
import java.util.zip.ZipFile
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
class NewMultiplatformIT : BaseGradleIT() {
@@ -1161,6 +1162,17 @@ class NewMultiplatformIT : BaseGradleIT() {
""".trimIndent()
)
build("compileCommonMainKotlinMetadata") {
assertSuccessful()
val compilerArgsLine = output.lines().singleOrNull { ":compileCommonMainKotlinMetadata Kotlin compiler args" in it }
assertNotNull(compilerArgsLine, "The debug log should contain the compiler args for the task :compileCommonMainKotlinMetadata")
val args = compilerArgsLine.split(" ")
val xCommonSourcesArg = args.singleOrNull { it.startsWith("-Xcommon-sources=") }
assertNotNull(xCommonSourcesArg, "The compiler args for K2Metadata should contain the -Xcommon-sources argument")
val xCommonSourcesFiles = xCommonSourcesArg.substringAfter("-Xcommon-sources=").split(",")
assertTrue { xCommonSourcesFiles.any { it.endsWith("Optional.kt") } }
}
build("compileKotlinJvmWithoutJava", "compileKotlinLinux64") {
assertSuccessful()
assertFileExists(targetClassesDir("jvmWithoutJava") + "OptionalCommonUsage.class")
@@ -116,10 +116,12 @@ internal open class GradleCompilerRunner(
*/
fun runMetadataCompilerAsync(
kotlinSources: List<File>,
kotlinCommonSources: List<File>,
args: K2MetadataCompilerArguments,
environment: GradleCompilerEnvironment
): WorkQueue? {
args.freeArgs += kotlinSources.map { it.absolutePath }
args.commonSources = kotlinCommonSources.map { it.absolutePath }.toTypedArray()
return runCompilerAsync(KotlinCompilerClass.METADATA, args, environment)
}
@@ -150,6 +150,11 @@ abstract class KotlinCompileCommon @Inject constructor(
reportingSettings = reportingSettings(),
outputFiles = allOutputFiles()
)
compilerRunner.runMetadataCompilerAsync(sourceRoots.kotlinSourceFiles.files.toList(), args, environment)
compilerRunner.runMetadataCompilerAsync(
sourceRoots.kotlinSourceFiles.files.toList(),
commonSourceSet.files.toList(),
args,
environment
)
}
}