Gradle, native: Escape spaces in K/N compiler args

We use an argument file to pass arguments to the K/N compiler.
Earlier each line of such a file was treated by the compiler
as a separate argument. But this logic was updated some time
ago and now content for this file is treated as a space separated
list of arguments.

This patch takes this into account at the Gradle side and quotes
arguments written to the arg file.

Issue #KT-35934 Fixed
This commit is contained in:
Ilya Matveev
2020-01-15 18:16:05 +07:00
parent a2a3ca0558
commit 8158d34bda
2 changed files with 21 additions and 2 deletions
@@ -2249,4 +2249,20 @@ class NewMultiplatformIT : BaseGradleIT() {
}
}
}
@Test
fun testNativeArgsWithSpaces() = with(Project("sample-lib", directoryPrefix = "new-mpp-lib-and-app")) {
setupWorkingDir()
val fileWithSpacesInPath = projectDir.resolve("src/commonMain/kotlin/path with spaces and special symbols like \"")
.apply { mkdirs() }
.resolve("B.kt")
fileWithSpacesInPath.writeText("fun foo() = 42")
build("compileKotlin${nativeHostTargetName.capitalize()}") {
assertSuccessful()
checkNativeCommandLineFor(":compileKotlin${nativeHostTargetName.capitalize()}") {
it.contains(fileWithSpacesInPath.absolutePath)
}
}
}
}
@@ -227,8 +227,11 @@ internal class KonanCompilerRunner(
deleteOnExit()
}
argFile.printWriter().use { writer ->
args.forEach {
writer.println(it)
args.forEach { arg ->
val escapedArg = arg
.replace("\\", "\\\\")
.replace("\"", "\\\"")
writer.println("\"$escapedArg\"")
}
}