From f92da32454984e29190b8e191aca03b3e10e6b0c Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Mon, 3 Oct 2016 20:56:33 +0300 Subject: [PATCH] Add properties expansion. --- .../Indexer/src/main/kotlin/clang/Clang.def | 2 -- .../kotlin/native/interop/gen/jvm/main.kt | 26 +++++++++++++++++++ InteropExample/src/main/kotlin/llvm/LLVM.def | 5 ++-- .../ir/backend.native/src/llvm/LLVM.def | 4 +-- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Interop/Indexer/src/main/kotlin/clang/Clang.def b/Interop/Indexer/src/main/kotlin/clang/Clang.def index 6156817f404..91dfe324588 100644 --- a/Interop/Indexer/src/main/kotlin/clang/Clang.def +++ b/Interop/Indexer/src/main/kotlin/clang/Clang.def @@ -10,5 +10,3 @@ linker = clang linkerOpts = -fPIC \ -lclang - -excludedFunctions = \ No newline at end of file diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt index 60bf386f974..b31422a929e 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt @@ -22,11 +22,37 @@ fun main(args: Array) { } } +// Performs substitution similar to: +// foo = ${foo} ${foo.${arch}} ${foo.${os}} +private fun substitute(properties: Properties, substitutions: Map) { + for (key in properties.stringPropertyNames()) { + if (key.contains('.')) { + continue + } + var value = "" + for (substitution in substitutions.keys) { + val property = properties.getProperty(key + "." + substitutions[substitution]) + if (property != null) { + value += " " + property + } + } + if (value != "") { + properties.setProperty(key, properties.getProperty(key, "") + " " + value) + } + } +} + private fun processDefFile(ktSrcRoot: String, defFile: File, ktGenRoot: String, nativeLibsDir: String, llvmInstallPath: String) { val config = Properties() defFile.bufferedReader().use { reader -> config.load(reader) } + // TODO: remove OSX defaults. + val substitutions = mapOf( + "arch" to (System.getenv("TARGET_ARCH") ?: "x86-64"), + "os" to (System.getenv("TARGET_OS") ?: "osx") + ) + substitute(config, substitutions) val headerFiles = config.getProperty("headers").split(' ') val compilerOpts = config.getProperty("compilerOpts").split(' ') diff --git a/InteropExample/src/main/kotlin/llvm/LLVM.def b/InteropExample/src/main/kotlin/llvm/LLVM.def index 978549441d8..b3766f6a773 100644 --- a/InteropExample/src/main/kotlin/llvm/LLVM.def +++ b/InteropExample/src/main/kotlin/llvm/LLVM.def @@ -23,7 +23,6 @@ linkerOpts = -stdlib=libc++ -fPIC -fvisibility-inlines-hidden \ -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMInterpreter \ -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMInstrumentation -lLLVMProfileData -lLLVMTransformUtils \ -lLLVMBitWriter -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser \ - -lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lcurses -lpthread -lz -lm \ - -lffi + -lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lz -lm -lffi -excludedFunctions = +linkerOpts.osx = -lcurses diff --git a/backend.native/compiler/ir/backend.native/src/llvm/LLVM.def b/backend.native/compiler/ir/backend.native/src/llvm/LLVM.def index e917f405f7f..c1e7aacf054 100644 --- a/backend.native/compiler/ir/backend.native/src/llvm/LLVM.def +++ b/backend.native/compiler/ir/backend.native/src/llvm/LLVM.def @@ -23,7 +23,7 @@ linkerOpts = -stdlib=libc++ -fPIC -fvisibility-inlines-hidden \ -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMInterpreter \ -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMInstrumentation -lLLVMProfileData -lLLVMTransformUtils \ -lLLVMBitWriter -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser \ - -lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lcurses -lpthread -lz -lm \ + -lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lpthread -lz -lm \ -lffi -excludedFunctions = +linkerOpts.osx = -lcurses