Make Configurables more flexible (#9)
* Separated CLI tools into interfaces. * Added `additionalToolsDir ` to `AppleConfigurables`
This commit is contained in:
committed by
Ilya Matveev
parent
5503b12a17
commit
c6f06ef51e
@@ -91,7 +91,7 @@ open class Command(initialCommand: List<String>) {
|
|||||||
|
|
||||||
val process = builder.start()
|
val process = builder.start()
|
||||||
val code = process.waitFor()
|
val code = process.waitFor()
|
||||||
if (handleError) handleExitCode(code)
|
if (handleError) handleExitCode(code, outputFile.readLines())
|
||||||
|
|
||||||
return Result(code, outputFile.readLines())
|
return Result(code, outputFile.readLines())
|
||||||
} finally {
|
} finally {
|
||||||
@@ -101,8 +101,11 @@ open class Command(initialCommand: List<String>) {
|
|||||||
|
|
||||||
class Result(val exitCode: Int, val outputLines: List<String>)
|
class Result(val exitCode: Int, val outputLines: List<String>)
|
||||||
|
|
||||||
private fun handleExitCode(code: Int) {
|
private fun handleExitCode(code: Int, output: List<String> = emptyList()) {
|
||||||
if (code != 0) throw KonanExternalToolFailure("The ${command[0]} command returned non-zero exit code: $code.", command[0])
|
if (code != 0) throw KonanExternalToolFailure("""
|
||||||
|
The ${command[0]} command returned non-zero exit code: $code.
|
||||||
|
output: ${output.joinToString("\n")}
|
||||||
|
""".trimIndent(), command[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun log() {
|
private fun log() {
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ class AppleConfigurablesImpl(
|
|||||||
XcodePartsProvider.InternalServer -> absolute(toolchainDependency)
|
XcodePartsProvider.InternalServer -> absolute(toolchainDependency)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val absoluteAdditionalToolsDir: String get() = when (xcodePartsProvider) {
|
||||||
|
is XcodePartsProvider.Local -> xcodePartsProvider.xcode.additionalTools
|
||||||
|
XcodePartsProvider.InternalServer -> absolute(additionalToolsDir)
|
||||||
|
}
|
||||||
|
|
||||||
override val dependencies get() = super.dependencies + when (xcodePartsProvider) {
|
override val dependencies get() = super.dependencies + when (xcodePartsProvider) {
|
||||||
is XcodePartsProvider.Local -> emptyList()
|
is XcodePartsProvider.Local -> emptyList()
|
||||||
XcodePartsProvider.InternalServer -> listOf(sdkDependency, toolchainDependency)
|
XcodePartsProvider.InternalServer -> listOf(sdkDependency, toolchainDependency)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.konan.file.File
|
|||||||
|
|
||||||
class ClangArgs(private val configurables: Configurables) : Configurables by configurables {
|
class ClangArgs(private val configurables: Configurables) : Configurables by configurables {
|
||||||
|
|
||||||
val targetArg = if (configurables is NonAppleConfigurables)
|
val targetArg = if (configurables is TargetableConfigurables)
|
||||||
configurables.targetArg
|
configurables.targetArg
|
||||||
else null
|
else null
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,39 @@ package org.jetbrains.kotlin.konan.target
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.konan.properties.*
|
import org.jetbrains.kotlin.konan.properties.*
|
||||||
|
|
||||||
|
interface ClangFlags : TargetableExternalStorage {
|
||||||
|
val clangFlags get() = targetList("clangFlags")
|
||||||
|
val clangNooptFlags get() = targetList("clangNooptFlags")
|
||||||
|
val clangOptFlags get() = targetList("clangOptFlags")
|
||||||
|
val clangDebugFlags get() = targetList("clangDebugFlags")
|
||||||
|
val clangDynamicFlags get() = targetList("clangDynamicFlags")
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LlvmLtoFlags : TargetableExternalStorage {
|
||||||
|
val llvmLtoNooptFlags get() = targetList("llvmLtoNooptFlags")
|
||||||
|
val llvmLtoOptFlags get() = targetList("llvmLtoOptFlags")
|
||||||
|
val llvmLtoFlags get() = targetList("llvmLtoFlags")
|
||||||
|
val llvmLtoDynamicFlags get() = targetList("llvmLtoDynamicFlags")
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LlcFlags : TargetableExternalStorage {
|
||||||
|
val llcFlags get() = targetList("llcFlags")
|
||||||
|
val llcNooptFlags get() = targetList("llcNooptFlags")
|
||||||
|
val llcOptFlags get() = targetList("llcOptFlags")
|
||||||
|
val llcDebugFlags get() = targetList("llcDebugFlags")
|
||||||
|
}
|
||||||
|
|
||||||
|
interface OptFlags : TargetableExternalStorage {
|
||||||
|
val optFlags get() = targetList("optFlags")
|
||||||
|
val optNooptFlags get() = targetList("optNooptFlags")
|
||||||
|
val optOptFlags get() = targetList("optOptFlags")
|
||||||
|
val optDebugFlags get() = targetList("optDebugFlags")
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LldFlags : TargetableExternalStorage {
|
||||||
|
val lldFlags get() = targetList("lld")
|
||||||
|
}
|
||||||
|
|
||||||
interface Configurables : TargetableExternalStorage {
|
interface Configurables : TargetableExternalStorage {
|
||||||
|
|
||||||
val target: KonanTarget
|
val target: KonanTarget
|
||||||
@@ -27,16 +60,13 @@ interface Configurables : TargetableExternalStorage {
|
|||||||
val libffiDir get() = hostString("libffiDir")
|
val libffiDir get() = hostString("libffiDir")
|
||||||
|
|
||||||
// TODO: Delegate to a map?
|
// TODO: Delegate to a map?
|
||||||
val llvmLtoNooptFlags get() = targetList("llvmLtoNooptFlags")
|
|
||||||
val llvmLtoOptFlags get() = targetList("llvmLtoOptFlags")
|
|
||||||
val llvmLtoFlags get() = targetList("llvmLtoFlags")
|
|
||||||
val llvmLtoDynamicFlags get() = targetList("llvmLtoDynamicFlags")
|
|
||||||
val entrySelector get() = targetList("entrySelector")
|
val entrySelector get() = targetList("entrySelector")
|
||||||
val linkerOptimizationFlags get() = targetList("linkerOptimizationFlags")
|
val linkerOptimizationFlags get() = targetList("linkerOptimizationFlags")
|
||||||
val linkerKonanFlags get() = targetList("linkerKonanFlags")
|
val linkerKonanFlags get() = targetList("linkerKonanFlags")
|
||||||
val linkerNoDebugFlags get() = targetList("linkerNoDebugFlags")
|
val linkerNoDebugFlags get() = targetList("linkerNoDebugFlags")
|
||||||
val linkerDynamicFlags get() = targetList("linkerDynamicFlags")
|
val linkerDynamicFlags get() = targetList("linkerDynamicFlags")
|
||||||
val llvmDebugOptFlags get() = targetList("llvmDebugOptFlags")
|
val llvmDebugOptFlags get() = targetList("llvmDebugOptFlags")
|
||||||
|
val llvmDebugLlcFlags get() = targetList("llvmDebugLlcFlags")
|
||||||
val targetSysRoot get() = targetString("targetSysRoot")
|
val targetSysRoot get() = targetString("targetSysRoot")
|
||||||
|
|
||||||
// Notice: these ones are host-target.
|
// Notice: these ones are host-target.
|
||||||
@@ -47,19 +77,21 @@ interface Configurables : TargetableExternalStorage {
|
|||||||
val absoluteLlvmHome get() = absolute(llvmHome)
|
val absoluteLlvmHome get() = absolute(llvmHome)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NonAppleConfigurables : Configurables {
|
interface TargetableConfigurables : Configurables {
|
||||||
val targetArg get() = targetString("quadruple")
|
val targetArg get() = targetString("quadruple")
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AppleConfigurables : Configurables {
|
interface AppleConfigurables : Configurables, ClangFlags {
|
||||||
val arch get() = targetString("arch")!!
|
val arch get() = targetString("arch")!!
|
||||||
val osVersionMin get() = targetString("osVersionMin")!!
|
val osVersionMin get() = targetString("osVersionMin")!!
|
||||||
val osVersionMinFlagLd get() = targetString("osVersionMinFlagLd")!!
|
val osVersionMinFlagLd get() = targetString("osVersionMinFlagLd")!!
|
||||||
|
val additionalToolsDir get() = hostString("additionalToolsDir")
|
||||||
|
val absoluteAdditionalToolsDir get() = absolute(additionalToolsDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MingwConfigurables : NonAppleConfigurables
|
interface MingwConfigurables : TargetableConfigurables, LlvmLtoFlags
|
||||||
|
|
||||||
interface LinuxBasedConfigurables : NonAppleConfigurables {
|
interface LinuxBasedConfigurables : TargetableConfigurables, LlvmLtoFlags {
|
||||||
val gccToolchain get() = hostString("gccToolchain")
|
val gccToolchain get() = hostString("gccToolchain")
|
||||||
val absoluteGccToolchain get() = absolute(gccToolchain)
|
val absoluteGccToolchain get() = absolute(gccToolchain)
|
||||||
|
|
||||||
@@ -72,24 +104,10 @@ interface LinuxBasedConfigurables : NonAppleConfigurables {
|
|||||||
interface LinuxConfigurables : LinuxBasedConfigurables
|
interface LinuxConfigurables : LinuxBasedConfigurables
|
||||||
interface LinuxMIPSConfigurables : LinuxBasedConfigurables
|
interface LinuxMIPSConfigurables : LinuxBasedConfigurables
|
||||||
interface RaspberryPiConfigurables : LinuxBasedConfigurables
|
interface RaspberryPiConfigurables : LinuxBasedConfigurables
|
||||||
interface AndroidConfigurables : NonAppleConfigurables
|
interface AndroidConfigurables : TargetableConfigurables
|
||||||
|
|
||||||
interface WasmConfigurables : NonAppleConfigurables {
|
interface WasmConfigurables : TargetableConfigurables, OptFlags, LlcFlags, LldFlags
|
||||||
|
|
||||||
val llcFlags get() = targetList("llcFlags")
|
interface ZephyrConfigurables : TargetableConfigurables {
|
||||||
val llcNooptFlags get() = targetList("llcNooptFlags")
|
|
||||||
val llcOptFlags get() = targetList("llcOptFlags")
|
|
||||||
val llcDebugFlags get() = targetList("llcDebugFlags")
|
|
||||||
|
|
||||||
val optFlags get() = targetList("optFlags")
|
|
||||||
val optNooptFlags get() = targetList("optNooptFlags")
|
|
||||||
val optOptFlags get() = targetList("optOptFlags")
|
|
||||||
val optDebugFlags get() = targetList("optDebugFlags")
|
|
||||||
|
|
||||||
val lldFlags get() = targetList("lld")
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ZephyrConfigurables : NonAppleConfigurables {
|
|
||||||
val boardSpecificClangFlags get() = targetList("boardSpecificClangFlags")
|
val boardSpecificClangFlags get() = targetList("boardSpecificClangFlags")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.konan.target
|
package org.jetbrains.kotlin.konan.target
|
||||||
|
|
||||||
import org.jetbrains.kotlin.konan.KonanExternalToolFailure
|
|
||||||
import org.jetbrains.kotlin.konan.exec.Command
|
import org.jetbrains.kotlin.konan.exec.Command
|
||||||
import org.jetbrains.kotlin.konan.file.File
|
import org.jetbrains.kotlin.konan.file.File
|
||||||
|
|
||||||
@@ -26,6 +25,8 @@ interface Xcode {
|
|||||||
val iphoneosSdk: String
|
val iphoneosSdk: String
|
||||||
val iphonesimulatorSdk: String
|
val iphonesimulatorSdk: String
|
||||||
val version: String
|
val version: String
|
||||||
|
// Xcode.app/Contents/Developer/usr
|
||||||
|
val additionalTools: String
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val current: Xcode by lazy {
|
val current: Xcode by lazy {
|
||||||
@@ -41,6 +42,11 @@ private object CurrentXcode : Xcode {
|
|||||||
File(ldPath).parentFile.parentFile.parentFile.absolutePath
|
File(ldPath).parentFile.parentFile.parentFile.absolutePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val additionalTools: String by lazy {
|
||||||
|
val bitcodeBuildToolPath = xcrun("-f", "bitcode-build-tool")
|
||||||
|
File(bitcodeBuildToolPath).parentFile.absolutePath
|
||||||
|
}
|
||||||
|
|
||||||
override val macosxSdk by lazy { getSdkPath("macosx") }
|
override val macosxSdk by lazy { getSdkPath("macosx") }
|
||||||
override val iphoneosSdk by lazy { getSdkPath("iphoneos") }
|
override val iphoneosSdk by lazy { getSdkPath("iphoneos") }
|
||||||
override val iphonesimulatorSdk by lazy { getSdkPath("iphonesimulator") }
|
override val iphonesimulatorSdk by lazy { getSdkPath("iphonesimulator") }
|
||||||
|
|||||||
Reference in New Issue
Block a user