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:
+12
@@ -34,6 +34,7 @@ import java.util.jar.JarFile
|
|||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
|
import kotlin.test.assertNotNull
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class NewMultiplatformIT : BaseGradleIT() {
|
class NewMultiplatformIT : BaseGradleIT() {
|
||||||
@@ -1161,6 +1162,17 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
""".trimIndent()
|
""".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") {
|
build("compileKotlinJvmWithoutJava", "compileKotlinLinux64") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertFileExists(targetClassesDir("jvmWithoutJava") + "OptionalCommonUsage.class")
|
assertFileExists(targetClassesDir("jvmWithoutJava") + "OptionalCommonUsage.class")
|
||||||
|
|||||||
+2
@@ -116,10 +116,12 @@ internal open class GradleCompilerRunner(
|
|||||||
*/
|
*/
|
||||||
fun runMetadataCompilerAsync(
|
fun runMetadataCompilerAsync(
|
||||||
kotlinSources: List<File>,
|
kotlinSources: List<File>,
|
||||||
|
kotlinCommonSources: List<File>,
|
||||||
args: K2MetadataCompilerArguments,
|
args: K2MetadataCompilerArguments,
|
||||||
environment: GradleCompilerEnvironment
|
environment: GradleCompilerEnvironment
|
||||||
): WorkQueue? {
|
): WorkQueue? {
|
||||||
args.freeArgs += kotlinSources.map { it.absolutePath }
|
args.freeArgs += kotlinSources.map { it.absolutePath }
|
||||||
|
args.commonSources = kotlinCommonSources.map { it.absolutePath }.toTypedArray()
|
||||||
return runCompilerAsync(KotlinCompilerClass.METADATA, args, environment)
|
return runCompilerAsync(KotlinCompilerClass.METADATA, args, environment)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -150,6 +150,11 @@ abstract class KotlinCompileCommon @Inject constructor(
|
|||||||
reportingSettings = reportingSettings(),
|
reportingSettings = reportingSettings(),
|
||||||
outputFiles = allOutputFiles()
|
outputFiles = allOutputFiles()
|
||||||
)
|
)
|
||||||
compilerRunner.runMetadataCompilerAsync(sourceRoots.kotlinSourceFiles.files.toList(), args, environment)
|
compilerRunner.runMetadataCompilerAsync(
|
||||||
|
sourceRoots.kotlinSourceFiles.files.toList(),
|
||||||
|
commonSourceSet.files.toList(),
|
||||||
|
args,
|
||||||
|
environment
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user