Native build: don't read klib files in KonanCacheTask.cacheFile
It is `@OutputDirectory`, so Gradle can invoke it early, even before the klib itself is built. Instead of reading `uniqName` from klib files, require specifying it explicitly.
This commit is contained in:
committed by
Space
parent
dea149ab47
commit
7470aaf06c
@@ -126,6 +126,7 @@ targetList.forEach { targetName ->
|
||||
tasks.register("${targetName}${library.taskName}Cache", KonanCacheTask::class.java) {
|
||||
target = targetName
|
||||
originalKlib = project.buildDir.resolve("$targetName${library.name}")
|
||||
klibUniqName = library.name
|
||||
cacheRoot = project.buildDir.resolve("cache/$targetName").absolutePath
|
||||
|
||||
cachedLibraries = mapOf(distDir.resolve("klib/common/stdlib") to
|
||||
|
||||
@@ -58,6 +58,7 @@ konanTargetList.forEach { target ->
|
||||
target.defFiles().forEach { df ->
|
||||
val libName = defFileToLibName(targetName, df.name)
|
||||
val fileNamePrefix = PlatformLibsInfo.namePrefix
|
||||
val artifactName = "${fileNamePrefix}${df.name}"
|
||||
|
||||
konanArtifacts {
|
||||
interop(
|
||||
@@ -65,7 +66,7 @@ konanTargetList.forEach { target ->
|
||||
name = libName
|
||||
) {
|
||||
df.file?.let { defFile(it) }
|
||||
artifactName("${fileNamePrefix}${df.name}")
|
||||
artifactName(artifactName)
|
||||
noDefaultLibs(true)
|
||||
noEndorsedLibs(true)
|
||||
libraries {
|
||||
@@ -101,6 +102,7 @@ konanTargetList.forEach { target ->
|
||||
val cacheTask = tasks.register("${libName}Cache", KonanCacheTask::class.java) {
|
||||
this.target = targetName
|
||||
originalKlib = klibInstallTask.get().installDir.get()
|
||||
klibUniqName = artifactName
|
||||
cacheRoot = file("$konanHome/klib/cache").absolutePath
|
||||
|
||||
dependsOn(":kotlin-native:${targetName}StdlibCache")
|
||||
|
||||
@@ -512,6 +512,7 @@ targetList.forEach { targetName ->
|
||||
tasks.register("${targetName}StdlibCache", KonanCacheTask::class.java) {
|
||||
target = targetName
|
||||
originalKlib = project.buildDir.resolve("${targetName}Stdlib")
|
||||
klibUniqName = "stdlib"
|
||||
cacheRoot = project.buildDir.resolve("cache/$targetName").absolutePath
|
||||
|
||||
dependsOn("${targetName}Stdlib")
|
||||
|
||||
+23
-10
@@ -23,6 +23,9 @@ open class KonanCacheTask: DefaultTask() {
|
||||
@get:InputDirectory
|
||||
var originalKlib: File? = null
|
||||
|
||||
@get:Input
|
||||
lateinit var klibUniqName: String
|
||||
|
||||
@get:Input
|
||||
lateinit var cacheRoot: String
|
||||
|
||||
@@ -36,16 +39,22 @@ open class KonanCacheTask: DefaultTask() {
|
||||
|
||||
@get:OutputDirectory
|
||||
val cacheFile: File
|
||||
get() {
|
||||
val konanHome = compilerDistributionPath.get().absolutePath
|
||||
val resolver = defaultResolver(
|
||||
emptyList(),
|
||||
PlatformManager(konanHome).targetByName(target),
|
||||
Distribution(konanHome)
|
||||
)
|
||||
val klibName = resolver.resolve(originalKlib!!.absolutePath).uniqueName
|
||||
return cacheDirectory.resolve("${klibName}-cache")
|
||||
}
|
||||
get() = cacheDirectory.resolve("${klibUniqName}-cache")
|
||||
|
||||
/**
|
||||
* Note: we can't use this function instead of [klibUniqName] in [cacheFile],
|
||||
* because the latter is `@OutputDirectory`, so Gradle can call it even before
|
||||
* the task dependencies are finished, and [originalKlib] might be not build yet.
|
||||
*/
|
||||
private fun readKlibUniqNameFromManifest(): String {
|
||||
val konanHome = compilerDistributionPath.get().absolutePath
|
||||
val resolver = defaultResolver(
|
||||
emptyList(),
|
||||
PlatformManager(konanHome).targetByName(target),
|
||||
Distribution(konanHome)
|
||||
)
|
||||
return resolver.resolve(originalKlib!!.absolutePath).uniqueName
|
||||
}
|
||||
|
||||
@get:Input
|
||||
var cacheKind: KonanCacheKind = KonanCacheKind.STATIC
|
||||
@@ -61,6 +70,10 @@ open class KonanCacheTask: DefaultTask() {
|
||||
|
||||
@TaskAction
|
||||
fun compile() {
|
||||
check(klibUniqName == readKlibUniqNameFromManifest()) {
|
||||
"klibUniqName mismatch: configured '$klibUniqName', resolved '${readKlibUniqNameFromManifest()}'"
|
||||
}
|
||||
|
||||
// Compiler doesn't create a cache if the cacheFile already exists. So we need to remove it manually.
|
||||
if (cacheFile.exists()) {
|
||||
val deleted = cacheFile.deleteRecursively()
|
||||
|
||||
Reference in New Issue
Block a user