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