Support OptionalExpectation (#2040)
This commit is contained in:
committed by
Nikolay Igotti
parent
88e86cbdd4
commit
d406b1b16d
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.cli.common.CLICompiler
|
|||||||
import org.jetbrains.kotlin.cli.common.CLITool
|
import org.jetbrains.kotlin.cli.common.CLITool
|
||||||
import org.jetbrains.kotlin.cli.common.CommonCompilerPerformanceManager
|
import org.jetbrains.kotlin.cli.common.CommonCompilerPerformanceManager
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
|
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot
|
||||||
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoots
|
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoots
|
||||||
import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots
|
import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
|
||||||
@@ -108,7 +109,10 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
|||||||
arguments : K2NativeCompilerArguments,
|
arguments : K2NativeCompilerArguments,
|
||||||
services : Services) {
|
services : Services) {
|
||||||
|
|
||||||
configuration.addKotlinSourceRoots(arguments.freeArgs)
|
val commonSources = arguments.commonSources?.toSet().orEmpty()
|
||||||
|
arguments.freeArgs.forEach {
|
||||||
|
configuration.addKotlinSourceRoot(it, it in commonSources)
|
||||||
|
}
|
||||||
|
|
||||||
with(KonanConfigKeys) {
|
with(KonanConfigKeys) {
|
||||||
with(configuration) {
|
with(configuration) {
|
||||||
|
|||||||
@@ -2301,6 +2301,15 @@ task mpp_default_args(type: RunStandaloneKonanTest) {
|
|||||||
flags = ['-tr', '-Xmulti-platform']
|
flags = ['-tr', '-Xmulti-platform']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task mpp_optional_expectation(type: RunStandaloneKonanTest) {
|
||||||
|
source = "codegen/mpp/mpp_optional_expectation.kt"
|
||||||
|
def outputRoot = project.ext."$outputSourceSetName"
|
||||||
|
flags = [
|
||||||
|
'-Xmulti-platform',
|
||||||
|
"-Xcommon-sources=${file("$outputRoot/$name/mpp_optional_expectation.kt")}"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
task unit1(type: RunKonanTest) {
|
task unit1(type: RunKonanTest) {
|
||||||
goldValue = "First\nkotlin.Unit\n"
|
goldValue = "First\nkotlin.Unit\n"
|
||||||
source = "codegen/basics/unit1.kt"
|
source = "codegen/basics/unit1.kt"
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@file:Suppress("EXPERIMENTAL_API_USAGE_ERROR")
|
||||||
|
@OptionalExpectation
|
||||||
|
expect annotation class Optional()
|
||||||
|
|
||||||
|
@Optional
|
||||||
|
fun foo() { println(42) }
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
foo()
|
||||||
|
}
|
||||||
+26
-3
@@ -80,6 +80,8 @@ internal abstract class KonanCliRunner(
|
|||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open protected fun transformArgs(args: List<String>): List<String> = args
|
||||||
|
|
||||||
override fun run(args: List<String>) {
|
override fun run(args: List<String>) {
|
||||||
project.logger.info("Run tool: $toolName with args: ${args.joinToString(separator = " ")}")
|
project.logger.info("Run tool: $toolName with args: ${args.joinToString(separator = " ")}")
|
||||||
if (classpath.isEmpty) {
|
if (classpath.isEmpty) {
|
||||||
@@ -99,7 +101,7 @@ internal abstract class KonanCliRunner(
|
|||||||
.toMap()
|
.toMap()
|
||||||
)
|
)
|
||||||
spec.systemProperties(additionalSystemProperties)
|
spec.systemProperties(additionalSystemProperties)
|
||||||
spec.args(listOf(toolName) + args)
|
spec.args(listOf(toolName) + transformArgs(args))
|
||||||
blacklistEnvironment.forEach { spec.environment.remove(it) }
|
blacklistEnvironment.forEach { spec.environment.remove(it) }
|
||||||
spec.environment(environment)
|
spec.environment(environment)
|
||||||
}
|
}
|
||||||
@@ -119,8 +121,29 @@ internal class KonanInteropRunner(project: Project, additionalJvmArgs: List<Stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class KonanCompilerRunner(project: Project, additionalJvmArgs: List<String> = emptyList())
|
internal class KonanCompilerRunner(
|
||||||
: KonanCliRunner("konanc", "Kotlin/Native compiler", project, additionalJvmArgs)
|
project: Project,
|
||||||
|
additionalJvmArgs: List<String> = emptyList(),
|
||||||
|
val useArgFile: Boolean = true
|
||||||
|
) : KonanCliRunner("konanc", "Kotlin/Native compiler", project, additionalJvmArgs)
|
||||||
|
{
|
||||||
|
override fun transformArgs(args: List<String>): List<String> {
|
||||||
|
if (!useArgFile) {
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
|
val argFile = createTempFile(prefix = "konancArgs", suffix = ".lst").apply {
|
||||||
|
deleteOnExit()
|
||||||
|
}
|
||||||
|
argFile.printWriter().use { writer ->
|
||||||
|
args.forEach {
|
||||||
|
writer.println(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return listOf("@${argFile.absolutePath}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal class KonanKlibRunner(project: Project, additionalJvmArgs: List<String> = emptyList())
|
internal class KonanKlibRunner(project: Project, additionalJvmArgs: List<String> = emptyList())
|
||||||
: KonanCliRunner("klib", "Klib management tool", project, additionalJvmArgs)
|
: KonanCliRunner("klib", "Klib management tool", project, additionalJvmArgs)
|
||||||
|
|||||||
+6
@@ -45,6 +45,11 @@ open class KotlinNativeCompile @Inject constructor(internal val binary: Abstract
|
|||||||
val sources: FileCollection
|
val sources: FileCollection
|
||||||
@InputFiles get() = binary.sources
|
@InputFiles get() = binary.sources
|
||||||
|
|
||||||
|
private val commonSources: FileCollection
|
||||||
|
get() = with(binary.sourceSet) {
|
||||||
|
getCommonMultiplatformSources() + getCommonNativeSources()
|
||||||
|
}
|
||||||
|
|
||||||
val libraries: Configuration
|
val libraries: Configuration
|
||||||
@InputFiles get() = binary.klibraries
|
@InputFiles get() = binary.klibraries
|
||||||
|
|
||||||
@@ -129,6 +134,7 @@ open class KotlinNativeCompile @Inject constructor(internal val binary: Abstract
|
|||||||
addListArg("-linker-options", linkerOpts)
|
addListArg("-linker-options", linkerOpts)
|
||||||
|
|
||||||
addAll(sources.files.map { it.absolutePath })
|
addAll(sources.files.map { it.absolutePath })
|
||||||
|
commonSources.files.mapTo(this) { "-Xcommon-sources=${it.absolutePath}" }
|
||||||
}
|
}
|
||||||
|
|
||||||
KonanCompilerRunner(project).run(args)
|
KonanCompilerRunner(project).run(args)
|
||||||
|
|||||||
+4
-1
@@ -141,7 +141,10 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
|||||||
|
|
||||||
addAll(extraOpts)
|
addAll(extraOpts)
|
||||||
|
|
||||||
allSourceFiles.mapTo(this) { it.canonicalPath }
|
allSourceFiles.mapTo(this) { it.absolutePath }
|
||||||
|
commonSrcFiles
|
||||||
|
.flatMap { it.files }
|
||||||
|
.mapTo(this) { "-Xcommon-sources=${it.absolutePath}" }
|
||||||
}
|
}
|
||||||
|
|
||||||
// region DSL.
|
// region DSL.
|
||||||
|
|||||||
+11
-1
@@ -84,7 +84,17 @@ class MultiplatformSpecification extends BaseKonanSpecification {
|
|||||||
createCommonSource(commonDirectory,
|
createCommonSource(commonDirectory,
|
||||||
["src", "main", "kotlin"],
|
["src", "main", "kotlin"],
|
||||||
"common.kt",
|
"common.kt",
|
||||||
"expect fun foo(): Int")
|
"""\
|
||||||
|
@file:Suppress("EXPERIMENTAL_API_USAGE_ERROR")
|
||||||
|
@OptionalExpectation
|
||||||
|
expect annotation class Optional()
|
||||||
|
|
||||||
|
@Optional
|
||||||
|
fun opt() = 42
|
||||||
|
|
||||||
|
expect fun foo(): Int
|
||||||
|
""".stripIndent()
|
||||||
|
)
|
||||||
|
|
||||||
it.generateSrcFile("platform.kt", "actual fun foo() = 42")
|
it.generateSrcFile("platform.kt", "actual fun foo() = 42")
|
||||||
it.buildFile.append("""
|
it.buildFile.append("""
|
||||||
|
|||||||
Reference in New Issue
Block a user