Support OptionalExpectation (#2040)

This commit is contained in:
Ilya Matveev
2018-09-12 17:23:59 +03:00
committed by Nikolay Igotti
parent 88e86cbdd4
commit d406b1b16d
7 changed files with 71 additions and 6 deletions
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.cli.common.CLICompiler
import org.jetbrains.kotlin.cli.common.CLITool
import org.jetbrains.kotlin.cli.common.CommonCompilerPerformanceManager
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.kotlinSourceRoots
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
@@ -108,7 +109,10 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
arguments : K2NativeCompilerArguments,
services : Services) {
configuration.addKotlinSourceRoots(arguments.freeArgs)
val commonSources = arguments.commonSources?.toSet().orEmpty()
arguments.freeArgs.forEach {
configuration.addKotlinSourceRoot(it, it in commonSources)
}
with(KonanConfigKeys) {
with(configuration) {
+9
View File
@@ -2301,6 +2301,15 @@ task mpp_default_args(type: RunStandaloneKonanTest) {
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) {
goldValue = "First\nkotlin.Unit\n"
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()
}
@@ -80,6 +80,8 @@ internal abstract class KonanCliRunner(
this
}
open protected fun transformArgs(args: List<String>): List<String> = args
override fun run(args: List<String>) {
project.logger.info("Run tool: $toolName with args: ${args.joinToString(separator = " ")}")
if (classpath.isEmpty) {
@@ -99,7 +101,7 @@ internal abstract class KonanCliRunner(
.toMap()
)
spec.systemProperties(additionalSystemProperties)
spec.args(listOf(toolName) + args)
spec.args(listOf(toolName) + transformArgs(args))
blacklistEnvironment.forEach { spec.environment.remove(it) }
spec.environment(environment)
}
@@ -119,8 +121,29 @@ internal class KonanInteropRunner(project: Project, additionalJvmArgs: List<Stri
}
}
internal class KonanCompilerRunner(project: Project, additionalJvmArgs: List<String> = emptyList())
: KonanCliRunner("konanc", "Kotlin/Native compiler", project, additionalJvmArgs)
internal class KonanCompilerRunner(
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())
: KonanCliRunner("klib", "Klib management tool", project, additionalJvmArgs)
@@ -45,6 +45,11 @@ open class KotlinNativeCompile @Inject constructor(internal val binary: Abstract
val sources: FileCollection
@InputFiles get() = binary.sources
private val commonSources: FileCollection
get() = with(binary.sourceSet) {
getCommonMultiplatformSources() + getCommonNativeSources()
}
val libraries: Configuration
@InputFiles get() = binary.klibraries
@@ -129,6 +134,7 @@ open class KotlinNativeCompile @Inject constructor(internal val binary: Abstract
addListArg("-linker-options", linkerOpts)
addAll(sources.files.map { it.absolutePath })
commonSources.files.mapTo(this) { "-Xcommon-sources=${it.absolutePath}" }
}
KonanCompilerRunner(project).run(args)
@@ -141,7 +141,10 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
addAll(extraOpts)
allSourceFiles.mapTo(this) { it.canonicalPath }
allSourceFiles.mapTo(this) { it.absolutePath }
commonSrcFiles
.flatMap { it.files }
.mapTo(this) { "-Xcommon-sources=${it.absolutePath}" }
}
// region DSL.
@@ -84,7 +84,17 @@ class MultiplatformSpecification extends BaseKonanSpecification {
createCommonSource(commonDirectory,
["src", "main", "kotlin"],
"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.buildFile.append("""