Allow running compiler only for libraries (#1508)
This commit is contained in:
@@ -256,3 +256,16 @@ protobuf {
|
||||
artifact = "com.google.protobuf:protoc:${protobufVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
task debugCompiler(type: JavaExec) {
|
||||
dependsOn ':dist'
|
||||
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
||||
classpath = project.fileTree("${distDir.canonicalPath}/konan/lib/") {
|
||||
include '*.jar'
|
||||
}
|
||||
jvmArgs "-Dkonan.home=${distDir.canonicalPath}",
|
||||
"-Djava.library.path=${distDir.canonicalPath}/konan/nativelib"
|
||||
enableAssertions = true
|
||||
args = findProperty("konan.debug.args").toString().tokenize() ?: []
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.backend.konan.util.profile
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||
import org.jetbrains.kotlin.cli.common.CLITool
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
@@ -49,15 +49,21 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
return ExitCode.OK
|
||||
}
|
||||
|
||||
if (arguments.freeArgs.isEmpty() && !arguments.isUsefulWithoutFreeArgs) {
|
||||
configuration.report(ERROR, "You have not specified any compilation arguments. No output has been produced.")
|
||||
}
|
||||
|
||||
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable,
|
||||
configuration, EnvironmentConfigFiles.NATIVE_CONFIG_FILES)
|
||||
val project = environment.project
|
||||
val konanConfig = KonanConfig(project, configuration)
|
||||
|
||||
val enoughArguments = arguments.freeArgs.isNotEmpty() || arguments.isUsefulWithoutFreeArgs
|
||||
if (!enoughArguments) {
|
||||
configuration.report(ERROR, "You have not specified any compilation arguments. No output has been produced.")
|
||||
}
|
||||
|
||||
if (konanConfig.linkOnly) {
|
||||
configuration.report(WARNING, "You have not specified any source files. " +
|
||||
"Only libraries will be used to produce the output binary.")
|
||||
}
|
||||
|
||||
try {
|
||||
runTopLevelPhases(konanConfig, environment)
|
||||
} catch (e: KonanCompilationException) {
|
||||
@@ -78,7 +84,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
}
|
||||
|
||||
val K2NativeCompilerArguments.isUsefulWithoutFreeArgs: Boolean
|
||||
get() = this.listTargets || this.listPhases || this.checkDependencies
|
||||
get() = this.listTargets || this.listPhases || this.checkDependencies || this.libraries?.isNotEmpty() ?: false
|
||||
|
||||
fun Array<String>?.toNonNullList(): List<String> {
|
||||
return this?.asList<String>() ?: listOf<String>()
|
||||
|
||||
+6
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.kotlinSourceRoots
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.konan.TempFiles
|
||||
@@ -48,6 +49,11 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
||||
internal val targetManager = platformManager.targetManager(configuration.get(KonanConfigKeys.TARGET))
|
||||
internal val target = targetManager.target
|
||||
|
||||
val linkOnly: Boolean =
|
||||
configuration.kotlinSourceRoots.isEmpty() && libraryNames.isNotEmpty() && produce.isNativeBinary
|
||||
|
||||
val infoArgsOnly = configuration.kotlinSourceRoots.isEmpty() && !linkOnly
|
||||
|
||||
init {
|
||||
if (!platformManager.isEnabled(target)) {
|
||||
error("Target ${target.visibleName} is not available on the ${HostManager.hostName} host")
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEnvironme
|
||||
KonanPhases.list()
|
||||
}
|
||||
|
||||
if (config.kotlinSourceRoots.isEmpty()) return
|
||||
if (konanConfig.infoArgsOnly) return
|
||||
|
||||
val context = Context(konanConfig)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user