From ff05a7d85ad68c01ba32c8316d79ea3024c3882a Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Thu, 7 Nov 2019 10:13:11 +0300 Subject: [PATCH] https://github.com/JetBrains/kotlin-native/pull/3538 followup. (#3547) --- build.gradle | 4 +- .../utilities/GeneratePlatformLibraries.kt | 42 +++++++++++-------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index 8b3e9c8de68..87d2b229385 100644 --- a/build.gradle +++ b/build.gradle @@ -360,7 +360,8 @@ task distDef(type: Copy) { destinationDir distDir from(project("platformLibs").file("src/platform")) { - into('klib/platformDef') + into('konan/platformDef') + include '**/*.def' } } @@ -465,6 +466,7 @@ task crossDist { } task bundle(type: (isWindows()) ? Zip : Tar) { + dependsOn("distDef") if (isMac()) { dependsOn('bundleRestricted') } diff --git a/utilities/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/GeneratePlatformLibraries.kt b/utilities/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/GeneratePlatformLibraries.kt index fd055608ec1..e83e8ee00da 100644 --- a/utilities/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/GeneratePlatformLibraries.kt +++ b/utilities/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/GeneratePlatformLibraries.kt @@ -34,14 +34,6 @@ fun generatePlatformLibraries(args: Array) { } private class DefFile(val name: String, val depends: MutableList) { - - override fun hashCode(): Int { - return name.hashCode() - } - - override fun equals(other: Any?): Boolean { - return other is DefFile && other.name == name - } override fun toString(): String = "$name: [${depends.joinToString(separator = ", ") { it.name }}]" } @@ -83,13 +75,16 @@ private fun generatePlatformLibraries(target: String, inputDirectory: File, outp "-no-default-libs", "-no-endorsed-libs", "-Xpurge-user-libs", *def.depends.flatMap { listOf("-l", "$outputDirectory/${it.name}") }.toTypedArray()) println("Processing ${def.name}...") - invokeInterop("native", args)?.let { K2Native.mainNoExit(it) } - org.jetbrains.kotlin.cli.klib.main(arrayOf("install", outKlib, - "-target", target, - "-repository", "${outputDirectory.absolutePath}" - )) - if (!saveTemps) { - File("$outputDirectory/build-${def.name}").deleteRecursively() + try { + invokeInterop("native", args)?.let { K2Native.mainNoExit(it) } + org.jetbrains.kotlin.cli.klib.main(arrayOf("install", outKlib, + "-target", target, + "-repository", "${outputDirectory.absolutePath}" + )) + } finally { + if (!saveTemps) { + File("$outputDirectory/build-${def.name}").deleteRecursively() + } } } println("generate platform libraries from $inputDirectory to $outputDirectory for $target") @@ -116,7 +111,7 @@ private fun generatePlatformLibraries(target: String, inputDirectory: File, outp val numCores = Runtime.getRuntime().availableProcessors() val executorPool = ThreadPoolExecutor(numCores, numCores, 10, TimeUnit.SECONDS, ArrayBlockingQueue(1000), - Executors.defaultThreadFactory(), RejectedExecutionHandler { r, executor -> + Executors.defaultThreadFactory(), RejectedExecutionHandler { r, _ -> println("Execution rejected: $r") throw Error("Must not happen!") }) @@ -128,9 +123,20 @@ private fun generatePlatformLibraries(target: String, inputDirectory: File, outp while (def.depends.any { built[it] == 0 }) { Thread.sleep(100) } - buildKlib(def) - built[def] = 1 + try { + if (def.depends.any { built[it] == 2 }) { + throw Error("There are failed dependencies for $def") + } + buildKlib(def) + built[def] = 1 + } catch(e: Throwable) { + built[def] = 2 + throw e + } } } executorPool.shutdown() + if (!saveTemps) { + File("$outputDirectory/clangModulesCache").deleteRecursively() + } } \ No newline at end of file