A bit simple file name suffix management.
This commit is contained in:
committed by
alexander-gorshenev
parent
62134a0573
commit
c9ce175224
@@ -20,6 +20,8 @@ import com.intellij.openapi.Disposable
|
||||
import org.jetbrains.kotlin.backend.konan.*
|
||||
import org.jetbrains.kotlin.backend.konan.CompilerOutputKind.*
|
||||
import org.jetbrains.kotlin.backend.konan.util.profile
|
||||
import org.jetbrains.kotlin.backend.konan.util.suffixIfNot
|
||||
import org.jetbrains.kotlin.backend.konan.util.removeSuffixIfPresent
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
@@ -50,9 +52,6 @@ private fun maybeExecuteHelper(configuration: CompilerConfiguration) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun suffixIfNot(name: String, suffix: String) =
|
||||
if (name.endsWith(suffix)) name else "$name$suffix"
|
||||
|
||||
class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
|
||||
override fun doExecute(arguments : K2NativeCompilerArguments,
|
||||
@@ -113,23 +112,11 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
(arguments.produce ?: "program").toUpperCase())
|
||||
|
||||
put(PRODUCE, outputKind)
|
||||
val (defaultName, suffix) = when (outputKind) {
|
||||
CompilerOutputKind.LIBRARY -> {
|
||||
put(NOLINK, true)
|
||||
Pair("library", ".klib")
|
||||
}
|
||||
CompilerOutputKind.PROGRAM -> {
|
||||
put(NOLINK, false)
|
||||
Pair("program", ".kexe")
|
||||
}
|
||||
CompilerOutputKind.BITCODE -> {
|
||||
put(NOLINK, true)
|
||||
Pair("output", ".bc")
|
||||
}
|
||||
}
|
||||
val output = arguments.outputFile ?: defaultName
|
||||
val suffix = outputKind.suffix
|
||||
val output = arguments.outputFile?.removeSuffixIfPresent(suffix)
|
||||
?: outputKind.name.toLowerCase()
|
||||
put(OUTPUT_NAME, output)
|
||||
put(OUTPUT_FILE, suffixIfNot(output, suffix))
|
||||
put(OUTPUT_FILE, output.suffixIfNot(outputKind.suffix))
|
||||
|
||||
// This is a decision we could change
|
||||
put(CommonConfigurationKeys.MODULE_NAME, output)
|
||||
|
||||
+4
-6
@@ -46,8 +46,6 @@ class KonanConfigKeys {
|
||||
= CompilerConfigurationKey.create("module kind")
|
||||
val NATIVE_LIBRARY_FILES: CompilerConfigurationKey<List<String>>
|
||||
= CompilerConfigurationKey.create("native library file paths")
|
||||
val NOLINK: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("don't link, only produce a bitcode file ")
|
||||
val NOMAIN: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("assume 'main' entry point to be provided by external libraries")
|
||||
val NOSTDLIB: CompilerConfigurationKey<Boolean>
|
||||
@@ -95,8 +93,8 @@ class KonanConfigKeys {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CompilerOutputKind {
|
||||
PROGRAM,
|
||||
LIBRARY,
|
||||
BITCODE
|
||||
enum class CompilerOutputKind(val suffix: String) {
|
||||
PROGRAM(".kexe"),
|
||||
LIBRARY(".klib"),
|
||||
BITCODE(".bc")
|
||||
}
|
||||
|
||||
+2
-4
@@ -77,6 +77,8 @@ object KonanPhases {
|
||||
// Don't serialize anything to a final executable.
|
||||
KonanPhase.SERIALIZER.enabled =
|
||||
(get(PRODUCE) == CompilerOutputKind.LIBRARY)
|
||||
KonanPhase.LINK_STAGE.enabled =
|
||||
(get(PRODUCE) == CompilerOutputKind.PROGRAM)
|
||||
|
||||
val disabled = get(DISABLED_PHASES)
|
||||
disabled?.forEach { phases[known(it)]!!.enabled = false }
|
||||
@@ -86,10 +88,6 @@ object KonanPhases {
|
||||
|
||||
val verbose = get(VERBOSE_PHASES)
|
||||
verbose?.forEach { phases[known(it)]!!.verbose = true }
|
||||
|
||||
if (get(NOLINK) ?: false ) {
|
||||
KonanPhase.LINK_STAGE.enabled = false
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
+2
-6
@@ -19,18 +19,14 @@ package org.jetbrains.kotlin.backend.konan.library
|
||||
import org.jetbrains.kotlin.backend.konan.Distribution
|
||||
import org.jetbrains.kotlin.backend.konan.KonanProperties
|
||||
import org.jetbrains.kotlin.backend.konan.util.File
|
||||
import org.jetbrains.kotlin.backend.konan.util.suffixIfNot
|
||||
import org.jetbrains.kotlin.backend.konan.util.removeSuffixIfPresent
|
||||
|
||||
interface SearchPathResolver {
|
||||
val searchRoots: List<File>
|
||||
fun resolve(givenPath: String): File
|
||||
}
|
||||
|
||||
fun String.suffixIfNot(suffix: String) =
|
||||
if (this.endsWith(suffix)) this else "$this$suffix"
|
||||
|
||||
fun String.removeSuffixIfPresent(suffix: String) =
|
||||
if (this.endsWith(suffix)) this.dropLast(suffix.length) else this
|
||||
|
||||
class KonanLibrarySearchPathResolver(repositories: List<String>,
|
||||
val distribution: Distribution): SearchPathResolver {
|
||||
|
||||
|
||||
+5
@@ -51,3 +51,8 @@ fun <T: Any> T.onlyIf(condition: T.()->Boolean, then: (T)->Unit): T {
|
||||
return this
|
||||
}
|
||||
|
||||
fun String.suffixIfNot(suffix: String) =
|
||||
if (this.endsWith(suffix)) this else "$this$suffix"
|
||||
|
||||
fun String.removeSuffixIfPresent(suffix: String) =
|
||||
if (this.endsWith(suffix)) this.dropLast(suffix.length) else this
|
||||
|
||||
Reference in New Issue
Block a user