Skip to content

Commit

Permalink
Unify compiler and cinterop flags names (JetBrains#2915)
Browse files Browse the repository at this point in the history
  • Loading branch information
LepilkinaElena authored Apr 30, 2019
1 parent 474fc4e commit dbc1078
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 26 deletions.
4 changes: 2 additions & 2 deletions INTEROP.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Install libgit2 and prepare stubs for the git library:

cd samples/gitchurn
../../dist/bin/cinterop -def src/main/c_interop/libgit2.def \
-compilerOpts -I/usr/local/include -o libgit2
-compiler-option -I/usr/local/include -o libgit2
```

</div>
Expand Down Expand Up @@ -86,7 +86,7 @@ in the sysroot search paths, headers may be needed):
<div class="sample" markdown="1" theme="idea" mode="shell">

```bash
cinterop -def png.def -compilerOpts -I/usr/local/include -o png
cinterop -def png.def -compiler-option -I/usr/local/include -o png
```

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,23 @@ fun getCInteropArguments(): List<OptionDescriptor> {
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(), "compilerOpt",
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(), "linkerOpt",
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 -compilerOpts."),
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 -linkerOpts."),
isMultiple = true, delimiter = " ", deprecatedWarning = "Option -lopt is deprecated. Please use -linker-options."),
OptionDescriptor(ArgType.String(), "linker", description = "use specified linker")
)
return (options + getCommonInteropArguments())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun interop(flavor: String, args: Array<String>, additionalArgs: Map<String, Any
}

// Options, whose values are space-separated and can be escaped.
val escapedOptions = setOf("-compilerOpts", "-linkerOpts")
val escapedOptions = setOf("-compilerOpts", "-linkerOpts", "-compiler-options", "-linker-options")

private fun String.asArgList(key: String) =
if (escapedOptions.contains(key))
Expand Down Expand Up @@ -177,14 +177,15 @@ private fun processCLib(args: Array<String>, additionalArgs: Map<String, Any> =

val def = DefFile(defFile, tool.substitutions)
val isLinkerOptsSetByUser = (argParser.getOrigin("linkerOpts") == ArgParser.ValueOrigin.SET_BY_USER) ||
(argParser.getOrigin("linkerOpt") == ArgParser.ValueOrigin.SET_BY_USER) ||
(argParser.getOrigin("linker-option") == ArgParser.ValueOrigin.SET_BY_USER) ||
(argParser.getOrigin("linker-options") == ArgParser.ValueOrigin.SET_BY_USER) ||
(argParser.getOrigin("lopt") == ArgParser.ValueOrigin.SET_BY_USER)
if (flavorName == "native" && isLinkerOptsSetByUser) {
warn("-linkerOpt(s)/-lopt option is not supported by cinterop. Please add linker options to .def file or binary compilation instead.")
warn("-linker-option(s)/-linkerOpts/-lopt option is not supported by cinterop. Please add linker options to .def file or binary compilation instead.")
}

val additionalLinkerOpts = argParser.getValuesAsArray("linkerOpts") + argParser.getValuesAsArray("linkerOpt") +
argParser.getValuesAsArray("lopt")
val additionalLinkerOpts = argParser.getValuesAsArray("linkerOpts") + argParser.getValuesAsArray("linker-option") +
argParser.getValuesAsArray("linker-options") + argParser.getValuesAsArray("lopt")
val verbose = argParser.get<Boolean>("verbose")!!

val language = selectNativeLanguage(def.config)
Expand Down Expand Up @@ -305,7 +306,8 @@ internal fun buildNativeLibrary(
imports: ImportsImpl
): NativeLibrary {
val additionalHeaders = arguments.getValuesAsArray("header") + arguments.getValuesAsArray("h")
val additionalCompilerOpts = arguments.getValuesAsArray("compilerOpts") + arguments.getValuesAsArray("compilerOpt") +
val additionalCompilerOpts = arguments.getValuesAsArray("compilerOpts") +
arguments.getValuesAsArray("compiler-options") + arguments.getValuesAsArray("compiler-option") +
arguments.getValuesAsArray("copt")

val headerFiles = def.config.headers + additionalHeaders
Expand Down
2 changes: 1 addition & 1 deletion LIBRARIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ For example, using the simple `libgit2.def` native library definition file provi
<div class="sample" markdown="1" theme="idea" mode="shell">

```bash
$ cinterop -def samples/gitchurn/src/nativeInterop/cinterop/libgit2.def -compilerOpts -I/usr/local/include -o libgit2
$ cinterop -def samples/gitchurn/src/nativeInterop/cinterop/libgit2.def -compiler-option -I/usr/local/include -o libgit2
```

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ class NamedNativeInteropConfig implements Named {
environment['PATH'] = project.files(project.hostPlatform.clang.clangPaths).asPath +
File.pathSeparator + environment['PATH']

args compilerOpts.collectMany { ['-compilerOpt', it] }
args linkerOpts.collectMany { ['-linkerOpt', it] }
args compilerOpts.collectMany { ['-compiler-option', it] }
args linkerOpts.collectMany { ['-linker-option', it] }

headers.each {
args '-header', it
Expand Down
10 changes: 5 additions & 5 deletions performance/videoplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ if (MPPTools.isMacos()) {
'-headerFilterAdditionalSearchPrefix', '/usr/include/x86_64-linux-gnu',
'-headerFilterAdditionalSearchPrefix', '/usr/include/ffmpeg']
} else if (MPPTools.isWindows()) {
includeDirsFfmpeg += ['-compilerOpt', "-I${MPPTools.mingwPath()}/include"]
includeDirsFfmpeg += ['-compiler-option', "-I${MPPTools.mingwPath()}/include"]
}

def includeDirsSdl = []
if (MPPTools.isMacos()) {
includeDirsSdl += ['-compilerOpt', '-I/opt/local/include/SDL2',
'-compilerOpt', '-I/usr/local/include/SDL2']
includeDirsSdl += ['-compiler-option', '-I/opt/local/include/SDL2',
'-compiler-option', '-I/usr/local/include/SDL2']
} else if (MPPTools.isLinux()) {
includeDirsSdl += ['-compilerOpt', '-I/usr/include/SDL2']
includeDirsSdl += ['-compiler-option', '-I/usr/include/SDL2']
} else if (MPPTools.isWindows()) {
includeDirsSdl += ['-compilerOpt', "-I${MPPTools.mingwPath()}/include/SDL2"]
includeDirsSdl += ['-compiler-option', "-I${MPPTools.mingwPath()}/include/SDL2"]
}

project.ext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ open class CInteropTask @Inject constructor(val settings: CInteropSettingsImpl):
addFileArgs("-header", headers)

compilerOpts.forEach {
addArg("-compilerOpt", it)
addArg("-compiler-option", it)
}

linkerOpts.forEach {
addArg("-linkerOpt", it)
addArg("-linker-option", it)
}

addArgs("-compilerOpt", allHeadersDirs.map { "-I${it.absolutePath}" })
addArgs("-compiler-option", allHeadersDirs.map { "-I${it.absolutePath}" })
addArgs("-headerFilterAdditionalSearchPrefix", headerFilterDirs.map { it.absolutePath })

libraries.files.filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ open class KonanInteropTask @Inject constructor(val workerExecutor: WorkerExecut
addFileArgs("-header", headers)

compilerOpts.forEach {
addArg("-copt", it)
addArg("-compiler-option", it)
}

val linkerOpts = mutableListOf<String>().apply { addAll(linkerOpts) }
linkFiles.forEach {
linkerOpts.addAll(it.files.map { it.canonicalPath })
}
linkerOpts.forEach {
addArg("-linkerOpt", it)
addArg("-linker-option", it)
}

addArgs("-compilerOpt", includeDirs.allHeadersDirs.map { "-I${it.absolutePath}" })
addArgs("-compiler-option", includeDirs.allHeadersDirs.map { "-I${it.absolutePath}" })
addArgs("-headerFilterAdditionalSearchPrefix", includeDirs.headerFilterDirs.map { it.absolutePath })

addArgs("-repo", libraries.repos.map { it.canonicalPath })
Expand Down

0 comments on commit dbc1078

Please sign in to comment.