Skip to content

Commit

Permalink
New CLI tool (JetBrains#3085)
Browse files Browse the repository at this point in the history
  • Loading branch information
LepilkinaElena authored Jul 22, 2019
1 parent e881ebd commit 3c2a5b0
Show file tree
Hide file tree
Showing 42 changed files with 1,852 additions and 614 deletions.
6 changes: 3 additions & 3 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ To update the blackbox compiler tests set TeamCity build number in `gradle.prope
cd tools/benchmarksAnalyzer/build/bin/<target>/benchmarksAnalyzerReleaseExecutable/
./benchmarksAnalyzer.kexe <file1> <file2>

Tool has several renders which allow produce output report in different forms (text, html, etc.). To set up render use flag `-render/-r`.
Output can be redirected to file with flag `-output/-o`.
To get detailed information about supported options, please use `-help/-h`.
Tool has several renders which allow produce output report in different forms (text, html, etc.). To set up render use flag `--render/-r`.
Output can be redirected to file with flag `--output/-o`.
To get detailed information about supported options, please use `--help/-h`.

Analyzer tool can compare both local files and files placed on Bintray/TeamCity.

Expand Down
5 changes: 1 addition & 4 deletions Interop/StubGenerator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,15 @@ repositories {
}
}


dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$buildKotlinVersion"
compile "org.jetbrains.kotlin:kotlin-compiler:$buildKotlinVersion"
compile project(':Interop:Indexer')
compile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
compile project(':endorsedLibraries:kliopt')
}

compileKotlin {
sourceSets {
main.kotlin.srcDirs += "$rootDir/tools/kliopt"
}
kotlinOptions {
freeCompilerArgs = ['-Xuse-experimental=kotlin.ExperimentalUnsignedTypes']
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.jetbrains.kotlin.native.interop.gen.jvm.buildNativeLibrary
import org.jetbrains.kotlin.native.interop.gen.jvm.prepareTool
import org.jetbrains.kotlin.native.interop.indexer.NativeLibraryHeaders
import org.jetbrains.kotlin.native.interop.indexer.getHeaderPaths
import org.jetbrains.kotlin.native.interop.tool.getCInteropArguments
import org.jetbrains.kotlin.native.interop.tool.CInteropArguments
import org.jetbrains.kliopt.ArgParser
import java.io.File

Expand Down Expand Up @@ -39,13 +39,13 @@ private fun makeDependencyAssigner(targets: List<String>, defFiles: List<File>)

private fun makeDependencyAssignerForTarget(target: String, defFiles: List<File>): SingleTargetDependencyAssigner {
val tool = prepareTool(target, KotlinPlatform.NATIVE)
val argParser = ArgParser(getCInteropArguments(), useDefaultHelpShortName = false)
argParser.parse(arrayOf<String>())
val cinteropArguments = CInteropArguments()
cinteropArguments.argParser.parse(arrayOf<String>())
val libraries = defFiles.associateWith {
buildNativeLibrary(
tool,
DefFile(it, tool.substitutions),
argParser,
cinteropArguments,
ImportsImpl(emptyMap())
).getHeaderPaths()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,75 +25,78 @@ const val TEMP_DIR = "Xtemporary-files-dir"

// TODO: unify camel and snake cases.
// Possible solution is to accept both cases
fun getCommonInteropArguments() = listOf(
OptionDescriptor(ArgType.Boolean(), "verbose", description = "Enable verbose logging output", defaultValue = "false"),
OptionDescriptor(ArgType.Choice(listOf("jvm", "native", "wasm")),
"flavor", description = "Interop target", defaultValue = "jvm"),
OptionDescriptor(ArgType.String(), "pkg", description = "place generated bindings to the package"),
OptionDescriptor(ArgType.String(), "output", "o", "specifies the resulting library file", defaultValue = "nativelib"),
OptionDescriptor(ArgType.String(), "libraryPath", description = "add a library search path",
isMultiple = true, delimiter = ","),
OptionDescriptor(ArgType.String(), "staticLibrary", description = "embed static library to the result",
isMultiple = true, delimiter = ","),
OptionDescriptor(ArgType.String(), "generated", description = "place generated bindings to the directory",
defaultValue = System.getProperty("user.dir")),
OptionDescriptor(ArgType.String(), "natives", description = "where to put the built native files",
defaultValue = System.getProperty("user.dir")),
OptionDescriptor(ArgType.String(), "library", "l", "library to use for building", isMultiple = true),
OptionDescriptor(ArgType.String(), "repo", "r",
"repository to resolve dependencies", isMultiple = true),
OptionDescriptor(ArgType.Boolean(), NODEFAULTLIBS, description = "don't link the libraries from dist/klib automatically",
defaultValue = "false"),
OptionDescriptor(ArgType.Boolean(), PURGE_USER_LIBS, description = "don't link unused libraries even explicitly specified",
defaultValue = "false"),
OptionDescriptor(ArgType.String(), TEMP_DIR, description = "save temporary files to the given directory")
)
open class CommonInteropArguments(val argParser: ArgParser) {
val verbose by argParser.option(ArgType.Boolean, description = "Enable verbose logging output", defaultValue = false)
val flavor by argParser.option(ArgType.Choice(listOf("jvm", "native", "wasm")), description = "Interop target",
defaultValue = "jvm")
val pkg by argParser.option(ArgType.String, description = "place generated bindings to the package")
val output by argParser.option(ArgType.String, shortName = "o", description = "specifies the resulting library file",
defaultValue = "nativelib")
val libraryPath by argParser.options(ArgType.String, description = "add a library search path",
multiple = true, delimiter = ",")
val staticLibrary by argParser.options(ArgType.String, description = "embed static library to the result",
multiple = true, delimiter = ",")
val generated by argParser.option(ArgType.String, description = "place generated bindings to the directory",
defaultValue = System.getProperty("user.dir"))
val natives by argParser.option(ArgType.String, description = "where to put the built native files",
defaultValue = System.getProperty("user.dir"))
val library by argParser.options(ArgType.String, shortName = "l", description = "library to use for building",
multiple = true)
val repo by argParser.options(ArgType.String, shortName = "r", description = "repository to resolve dependencies",
multiple = true)
val nodefaultlibs by argParser.option(ArgType.Boolean, NODEFAULTLIBS,
description = "don't link the libraries from dist/klib automatically",
defaultValue = false)
val purgeUserLibs by argParser.option(ArgType.Boolean, PURGE_USER_LIBS,
description = "don't link unused libraries even explicitly specified", defaultValue = false)
val tempDir by argParser.option(ArgType.String, TEMP_DIR,
description = "save temporary files to the given directory")
}

fun getCInteropArguments(): List<OptionDescriptor> {
val options = listOf(
OptionDescriptor(ArgType.String(), "target", description = "native target to compile to", defaultValue = "host"),
OptionDescriptor(ArgType.String(), "def", description = "the library definition file"),
OptionDescriptor(ArgType.String(), "header", description = "header file to produce kotlin bindings for",
isMultiple = true, delimiter = ","),
OptionDescriptor(ArgType.String(), "h", description = "header file to produce kotlin bindings for",
isMultiple = true, delimiter = ",", deprecatedWarning = "Option -h is deprecated. Please use -header."),
OptionDescriptor(ArgType.String(), HEADER_FILTER_ADDITIONAL_SEARCH_PREFIX, "hfasp",
"header file to produce kotlin bindings for", isMultiple = true, delimiter = ","),
OptionDescriptor(ArgType.String(), "compilerOpts",
description = "additional compiler options (allows to add several options separated by spaces)",
isMultiple = true, delimiter = " "),
OptionDescriptor(ArgType.String(), "compiler-options",
description = "additional compiler options (allows to add several options separated by spaces)",
isMultiple = true, delimiter = " "),
OptionDescriptor(ArgType.String(), "linkerOpts",
description = "additional linker options (allows to add several options separated by spaces)",
isMultiple = true, delimiter = " "),
OptionDescriptor(ArgType.String(), "linker-options",
description = "additional linker options (allows to add several options separated by spaces)",
isMultiple = true, delimiter = " "),
OptionDescriptor(ArgType.String(), "compiler-option",
description = "additional compiler option", isMultiple = true),
OptionDescriptor(ArgType.String(), "linker-option",
description = "additional linker option", isMultiple = true),
OptionDescriptor(ArgType.String(), "copt", description = "additional compiler options (allows to add several options separated by spaces)",
isMultiple = true, delimiter = " ", deprecatedWarning = "Option -copt is deprecated. Please use -compiler-options."),
OptionDescriptor(ArgType.String(), "lopt", description = "additional linker options (allows to add several options separated by spaces)",
isMultiple = true, delimiter = " ", deprecatedWarning = "Option -lopt is deprecated. Please use -linker-options."),
OptionDescriptor(ArgType.String(), "linker", description = "use specified linker")
)
return (options + getCommonInteropArguments())
class CInteropArguments(argParser: ArgParser =
ArgParser("cinterop", useDefaultHelpShortName = false,
prefixStyle = ArgParser.OPTION_PREFIX_STYLE.JVM)): CommonInteropArguments(argParser) {
val target by argParser.option(ArgType.String, description = "native target to compile to", defaultValue = "host")
val def by argParser.option(ArgType.String, description = "the library definition file")
val header by argParser.options(ArgType.String, description = "header file to produce kotlin bindings for",
multiple = true, delimiter = ",")
val shortHeaderForm by argParser.options(ArgType.String, "h", description = "header file to produce kotlin bindings for",
multiple = true, delimiter = ",", deprecatedWarning = "Option -h is deprecated. Please use -header.")
val headerFilterPrefix by argParser.options(ArgType.String, HEADER_FILTER_ADDITIONAL_SEARCH_PREFIX, "hfasp",
"header file to produce kotlin bindings for", multiple = true, delimiter = ",")
val compilerOpts by argParser.options(ArgType.String,
description = "additional compiler options (allows to add several options separated by spaces)",
multiple = true, delimiter = " ")
val compilerOptions by argParser.options(ArgType.String, "compiler-options",
description = "additional compiler options (allows to add several options separated by spaces)",
multiple = true, delimiter = " ")
val linkerOpts by argParser.options(ArgType.String, "linkerOpts",
description = "additional linker options (allows to add several options separated by spaces)",
multiple = true, delimiter = " ")
val linkerOptions by argParser.options(ArgType.String, "linker-options",
description = "additional linker options (allows to add several options separated by spaces)",
multiple = true, delimiter = " ")
val compilerOption by argParser.options(ArgType.String, "compiler-option",
description = "additional compiler option", multiple = true)
val linkerOption by argParser.options(ArgType.String, "linker-option",
description = "additional linker option", multiple = true)
val copt by argParser.options(ArgType.String,
description = "additional compiler options (allows to add several options separated by spaces)",
multiple = true, delimiter = " ",
deprecatedWarning = "Option -copt is deprecated. Please use -compiler-options.")
val lopt by argParser.options(ArgType.String,
description = "additional linker options (allows to add several options separated by spaces)",
multiple = true, delimiter = " ",
deprecatedWarning = "Option -lopt is deprecated. Please use -linker-options.")
val linker by argParser.option(ArgType.String, description = "use specified linker")
}

fun getJSInteropArguments(): List<OptionDescriptor> {
val options = listOf(
OptionDescriptor(ArgType.Choice(listOf("wasm32")), "target", description = "wasm target to compile to", defaultValue = "wasm32")
)
return (options + getCommonInteropArguments())
class JSInteropArguments(argParser: ArgParser = ArgParser("jsinterop", useDefaultHelpShortName = false,
prefixStyle = ArgParser.OPTION_PREFIX_STYLE.JVM)): CommonInteropArguments(argParser) {
val target by argParser.option(ArgType.Choice(listOf("wasm32")),
description = "wasm target to compile to", defaultValue = "wasm32")
}

internal fun warn(msg: String) {
println("warning: $msg")
}

fun ArgParser.getValuesAsArray(propertyName: String) =
(getAll<String>(propertyName) ?: listOf<String>()).toTypedArray()
Loading

0 comments on commit 3c2a5b0

Please sign in to comment.