diff --git a/INTEROP.md b/INTEROP.md index 364209ec0bb..8b307d8b83d 100644 --- a/INTEROP.md +++ b/INTEROP.md @@ -24,7 +24,7 @@ Build the dependencies and the compiler (see `README.md`). Prepare stubs for the system sockets library: cd samples/socket - ../../dist/bin/cinterop -def:sockets.def -o:sockets.kt.bc + ../../dist/bin/cinterop -def sockets.def -o sockets.kt.bc Compile the echo server: @@ -57,7 +57,7 @@ Structurally it's a simple property file, looking like this: Then run `cinterop` tool with something like (note that for host libraries not included in sysroot search paths for headers may be needed): - cinterop -def:zlib.def -copt:-I/opt/local/include -o:zlib.kt.bc + cinterop -def zlib.def -copt -I/opt/local/include -o zlib.kt.bc This command will produce `zlib.kt.bc` compiled library and `zlib.kt.bc-build/kotlin` directory containing Kotlin source code for the library. 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 675c6b8777e..c082af39db6 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 @@ -34,7 +34,23 @@ fun main(args: Array) { "os" to (System.getenv("TARGET_OS") ?: detectHost()) ) - processLib(konanHome, substitutions, args.asList()) + processLib(konanHome, substitutions, parseArgs(args)) +} + +private fun parseArgs(args: Array): Map> { + val commandLine = mutableMapOf>() + for(index in 0..args.size-1 step 2) { + val key = args[index] + if (key[0] != '-') { + throw IllegalArgumentException("Expected a flag with initial dash: $key") + } + if (index+1 == args.size) { + throw IllegalArgumentException("Expected an value after $key") + } + val value = args[index+1] + commandLine[key] ?. add(value) ?: commandLine.put(key, mutableListOf(value)) + } + return commandLine } private fun detectHost(): String { @@ -53,6 +69,7 @@ private fun detectHost(): String { private fun defaultTarget() = detectHost() private val knownTargets = mapOf( + "host" to defaultTarget(), "linux" to "linux", "macbook" to "osx", "iphone" to "osx-ios", @@ -83,24 +100,6 @@ private fun substitute(properties: Properties, substitutions: Map): Pro private fun usage() { println(""" -Run interop tool with -def:.def +Run interop tool with -def .def Following flags are supported: - -def:.def specifies library definition file - -copt: specifies flags passed to clang - -lopt: specifies flags passed to linker - -verbose increases verbosity - -shims adds generation of shims tracing native library calls - -pkg: - -h:.h header files to parse + -def .def specifies library definition file + -copt specifies flags passed to clang + -lopt specifies flags passed to linker + -verbose increases verbosity + -shims adds generation of shims tracing native library calls + -pkg place the resulting definitions into the package + -h .h header files to parse """) } private fun processLib(konanHome: String, substitutions: Map, - commandArgs: List) { - - val args = commandArgs.groupBy ({ getArgPrefix(it) }, { dropPrefix(it) }) // TODO + args: Map>) { val userDir = System.getProperty("user.dir") val ktGenRoot = args["-generated"]?.single() ?: userDir diff --git a/README.md b/README.md index 51bf0d10338..40f37b04208 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,6 @@ For some tests, use: To generate interoperability stubs create library definition file (take a look on `samples/tetris/tetris.sdl`) and run `cinterop` tool like this: - cinterop -def:lib.def + cinterop -def lib.def -See provided samples and `INTEROP.md` for more details. \ No newline at end of file +See provided samples and `INTEROP.md` for more details. diff --git a/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy b/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy index ef53a361e13..b6627822b3e 100644 --- a/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy +++ b/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy @@ -206,42 +206,42 @@ class NamedNativeInteropConfig implements Named { linkerOpts += linkFiles.files - args "-properties:" + project.findProject(":backend.native").file("konan.properties") - args "-generated:" + generatedSrcDir - args "-natives:" + nativeLibsDir - args "-flavor:" + this.flavor + args '-properties', project.findProject(":backend.native").file("konan.properties") + args '-generated', generatedSrcDir + args '-natives', nativeLibsDir + args '-flavor', this.flavor // Uncomment to debug. - // args "-verbose:true" + // args '-verbose', 'true' if (defFile != null) { - args "-def:" + project.file(defFile) + args '-def', project.file(defFile) } if (pkg != null) { - args "-pkg:" + pkg + args '-pkg', pkg } if (linker != null) { - args "-linker:" + linker + args '-linker', linker } if (target != null) { - args "-target:" + target + args '-target', target } // TODO: the interop plugin should probably be reworked to execute clang from build scripts directly environment['PATH'] = project.files(project.clangPath).asPath + File.pathSeparator + environment['PATH'] - args compilerOpts.collect { "-copt:$it" } - args linkerOpts.collect { "-lopt:$it" } + args compilerOpts.collectMany { ['-copt', it] } + args linkerOpts.collectMany { ['-lopt', it] } headers.each { - args "-h:$it" + args '-h', it } - if (project.hasProperty("shims")) { - args "-shims:$project.ext.shims" + if (project.hasProperty('shims')) { + args '-shims', project.ext.shims } } diff --git a/cmd/cinterop b/cmd/cinterop index d48bd2ea1bd..d0e472f7f52 100644 --- a/cmd/cinterop +++ b/cmd/cinterop @@ -37,13 +37,13 @@ while [ $# -gt 0 ]; do java_args=("${java_args[@]}" "${1:2}") shift ;; - -o:*) - OUTPUT_FILE_NAME="${1:3}" - shift + -o) + OUTPUT_FILE_NAME="$2" + shift 2 ;; - -target:*) - TARGET="${1:8}" - shift + -target) + TARGET="$2" + shift 2 ;; *) interop_args=("${interop_args[@]}" "$1") @@ -76,22 +76,22 @@ HELPERS_JAR="${KONAN_HOME}/konan/lib/helpers.jar" INTEROP_CLASSPATH="$STUB_GENERATOR_JAR:$KOTLIN_JAR:$INTEROP_INDEXER_JAR:$INTEROP_RUNTIME_JAR:$HELPERS_JAR" INTEROP_TOOL=org.jetbrains.kotlin.native.interop.gen.jvm.MainKt -FLAVOR_ARG=-flavor:native +FLAVOR_ARG="-flavor native" GENERATED_DIR="$OUTPUT_FILE_NAME-build/kotlin" -GENERATED_ARG="-generated:$GENERATED_DIR" +GENERATED_ARG="-generated $GENERATED_DIR" NATIVES_DIR="$OUTPUT_FILE_NAME-build/natives" -NATIVES_ARG="-natives:$NATIVES_DIR" +NATIVES_ARG="-natives $NATIVES_DIR" CSTUBSNAME=cstubs -CSTUBSNAME_ARG="-cstubsname:$CSTUBSNAME" +CSTUBSNAME_ARG="-cstubsname $CSTUBSNAME" LIBCLANG_DISABLE_CRASH_RECOVERY=1 \ LD_LIBRARY_PATH=${NATIVE_LIB} \ $JAVACMD $JAVA_OPTS ${java_args[@]} \ -cp $INTEROP_CLASSPATH \ $INTEROP_TOOL \ - "$GENERATED_ARG" "$NATIVES_ARG" "$CSTUBSNAME_ARG" \ - $FLAVOR_ARG -target:$TARGET "${interop_args[@]}" \ + $GENERATED_ARG $NATIVES_ARG $CSTUBSNAME_ARG \ + $FLAVOR_ARG -target $TARGET "${interop_args[@]}" \ || exit 1 # Stubs may be rather big, so we may need more heap space. diff --git a/samples/csvparser/build.sh b/samples/csvparser/build.sh index 8746699f767..5922d14c1da 100755 --- a/samples/csvparser/build.sh +++ b/samples/csvparser/build.sh @@ -18,5 +18,5 @@ LINKER_ARGS=${!var} var=COMPILER_ARGS_${TARGET} COMPILER_ARGS=${!var} # add -opt for an optimized build. -cinterop -def:$DIR/stdio.def -copt:"$CFLAGS" -target:$TARGET -o:stdio.kt.bc || exit 1 +cinterop -def $DIR/stdio.def -copt "$CFLAGS" -target $TARGET -o stdio.kt.bc || exit 1 konanc $COMPILER_ARGS -target $TARGET $DIR/CsvParser.kt -library stdio.kt.bc -o CsvParser.kexe || exit 1 diff --git a/samples/gitchurn/build.sh b/samples/gitchurn/build.sh index 40f805fe654..ec9b369abe2 100755 --- a/samples/gitchurn/build.sh +++ b/samples/gitchurn/build.sh @@ -23,5 +23,5 @@ LINKER_ARGS=${!var} var=COMPILER_ARGS_${TARGET} COMPILER_ARGS=${!var} # add -opt for an optimized build. -cinterop -copt:$CFLAGS -def:$DIR/libgit2.def -target:$TARGET -o:libgit2.kt.bc || exit 1 +cinterop -copt $CFLAGS -def $DIR/libgit2.def -target $TARGET -o libgit2.kt.bc || exit 1 konanc -target $TARGET src -library libgit2.kt.bc -linkerArgs "$LINKER_ARGS" -o GitChurn.kexe || exit 1 diff --git a/samples/libcurl/build.sh b/samples/libcurl/build.sh index 756261cba18..b57d65e4d82 100755 --- a/samples/libcurl/build.sh +++ b/samples/libcurl/build.sh @@ -23,5 +23,5 @@ LINKER_ARGS=${!var} var=COMPILER_ARGS_${TARGET} COMPILER_ARGS=${!var} # add -opt for an optimized build. -cinterop -copt:"$CFLAGS" -copt:-I. -def:$DIR/libcurl.def -target:$TARGET -o:libcurl.bc || exit 1 +cinterop -copt "$CFLAGS" -copt -I. -def $DIR/libcurl.def -target $TARGET -o libcurl.bc || exit 1 konanc -target $TARGET src -library libcurl.bc -linkerArgs "$LINKER_ARGS" -o Curl.kexe || exit 1 diff --git a/samples/opengl/build.sh b/samples/opengl/build.sh index 343b81be101..5ce3238908d 100755 --- a/samples/opengl/build.sh +++ b/samples/opengl/build.sh @@ -21,5 +21,5 @@ LINKER_ARGS=${!var} var=COMPILER_ARGS_${TARGET} COMPILER_ARGS=${!var} # add -opt for an optimized build. -cinterop -def:$DIR/opengl.def -target:$TARGET -o:opengl.kt.bc || exit 1 +cinterop -def $DIR/opengl.def -target $TARGET -o opengl.kt.bc || exit 1 konanc -target $TARGET $DIR/OpenGlTeapot.kt -library opengl.kt.bc -linkerArgs "$LINKER_ARGS" -o OpenGlTeapot.kexe || exit 1 diff --git a/samples/socket/build.sh b/samples/socket/build.sh index 176d1bf242f..4962195956d 100755 --- a/samples/socket/build.sh +++ b/samples/socket/build.sh @@ -18,5 +18,5 @@ LINKER_ARGS=${!var} var=COMPILER_ARGS_${TARGET} COMPILER_ARGS=${!var} # add -opt for an optimized build. -cinterop -def:$DIR/sockets.def -copt:"$CFLAGS" -target:$TARGET -o:sockets.kt.bc || exit 1 +cinterop -def $DIR/sockets.def -copt "$CFLAGS" -target $TARGET -o sockets.kt.bc || exit 1 konanc $COMPILER_ARGS -target $TARGET $DIR/EchoServer.kt -library sockets.kt.bc -o EchoServer.kexe || exit 1 diff --git a/samples/tetris/build.sh b/samples/tetris/build.sh index d35a41d29f9..1b111c9424c 100755 --- a/samples/tetris/build.sh +++ b/samples/tetris/build.sh @@ -39,6 +39,6 @@ LINKER_ARGS=${!var} var=COMPILER_ARGS_${TARGET} COMPILER_ARGS=${!var} # add -opt for an optimized build. -cinterop -def:$DIR/sdl.def -copt:"$CFLAGS" -target:$TARGET -o:sdl.kt.bc || exit 1 +cinterop -def $DIR/sdl.def -copt "$CFLAGS" -target $TARGET -o sdl.kt.bc || exit 1 konanc $COMPILER_ARGS -target $TARGET $DIR/Tetris.kt -library sdl.kt.bc -linkerArgs "$LINKER_ARGS" -o Tetris.kexe || exit 1 #strip Tetris.kexe