Reduce interop stub generation verbosity

This commit is contained in:
Svyatoslav Scherbina
2017-03-30 12:04:19 +03:00
committed by SvyatoslavScherbina
parent 4a1b2721d8
commit bdd5ec83e1
2 changed files with 45 additions and 16 deletions
@@ -31,8 +31,15 @@ class StubGenerator(
val configuration: InteropConfiguration,
val libName: String,
val dumpShims: Boolean,
val verbose: Boolean = false,
val platform: KotlinPlatform = KotlinPlatform.JVM) {
private fun log(message: String) {
if (verbose) {
println(message)
}
}
val pkgName: String
get() = configuration.pkgName
@@ -620,7 +627,7 @@ class StubGenerator(
}
out("")
} catch (e: Throwable) {
println("Warning: cannot generate definition for field ${decl.kotlinName}.${field.name}")
log("Warning: cannot generate definition for field ${decl.kotlinName}.${field.name}")
}
}
}
@@ -1028,7 +1035,7 @@ class StubGenerator(
type.parameterTypes.map { getArgFfiType(it) }
} catch (e: Throwable) {
println("Warning: cannot generate definition for function type $name")
log("Warning: cannot generate definition for function type $name")
out("object $name : CFunctionType {}")
return
}
@@ -1210,7 +1217,7 @@ class StubGenerator(
out("")
}
} catch (e: Throwable) {
println("Warning: cannot generate binding definition for function ${it.name}")
log("Warning: cannot generate binding definition for function ${it.name}")
}
}
@@ -1226,7 +1233,7 @@ class StubGenerator(
out("")
}
} catch (e: Throwable) {
println("Warning: cannot generate definition for struct ${s.kotlinName}")
log("Warning: cannot generate definition for struct ${s.kotlinName}")
}
}
@@ -1242,7 +1249,7 @@ class StubGenerator(
out("")
}
} catch (e: Throwable) {
println("Warning: cannot generate typedef ${t.name}")
log("Warning: cannot generate typedef ${t.name}")
}
}
@@ -1264,7 +1271,7 @@ class StubGenerator(
out("")
}
} catch (e: Throwable) {
println("Warning: cannot generate external definition for function ${it.name}")
log("Warning: cannot generate external definition for function ${it.name}")
}
}
}
@@ -1278,7 +1285,7 @@ class StubGenerator(
}
}
} catch (e: Throwable) {
println("Warning: cannot generate external definition for function ${it.name}")
log("Warning: cannot generate external definition for function ${it.name}")
}
}
}
@@ -1338,7 +1345,7 @@ class StubGenerator(
generateCJniFunction(func)
}
} catch (e: Throwable) {
System.err.println("Warning: cannot generate C JNI function definition ${func.name}")
log("Warning: cannot generate C JNI function definition ${func.name}")
}
}
@@ -102,8 +102,6 @@ private fun dropPrefix(arg: String): String {
}
private fun ProcessBuilder.runExpectingSuccess() {
println(this.command().joinToString(" "))
val res = this.start().waitFor()
if (res != 0) {
throw Error("Process finished with non-zero exit code: $res")
@@ -126,11 +124,35 @@ private fun List<String>?.isTrue(): Boolean {
}
private fun runCmd(command: Array<String>, workDir: File, verbose: Boolean = false) {
if (verbose) println(command)
ProcessBuilder(*command)
.directory(workDir)
.inheritIO()
.runExpectingSuccess()
val builder = ProcessBuilder(*command)
.directory(workDir)
val logFile: File?
if (verbose) {
println(command.joinToString(" "))
builder.inheritIO()
logFile = null
} else {
logFile = createTempFile(suffix = ".log")
logFile.deleteOnExit()
builder.redirectOutput(ProcessBuilder.Redirect.to(logFile))
.redirectErrorStream(true)
}
try {
builder.runExpectingSuccess()
} catch (e: Throwable) {
if (!verbose) {
println(command.joinToString(" "))
logFile!!.useLines {
it.forEach { println(it) }
}
}
throw e
}
}
private fun maybeExecuteHelper(dependenciesRoot: String, properties: Properties, dependencies: List<String>) {
@@ -314,7 +336,7 @@ private fun processLib(konanHome: String,
val nativeIndex = buildNativeIndex(library)
val gen = StubGenerator(nativeIndex, configuration, libName, generateShims, flavor)
val gen = StubGenerator(nativeIndex, configuration, libName, generateShims, verbose, flavor)
outKtFile.parentFile.mkdirs()
outKtFile.bufferedWriter().use { out ->