[JS Gradle] Pass incremental cache root dir to K2JS compiler
This commit is contained in:
committed by
Space Team
parent
693258ae91
commit
9dab8637a8
+3
-3
@@ -252,11 +252,11 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
var includes: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@Argument(
|
||||
value = "-Xcache-directories",
|
||||
value = "-Xcache-directory",
|
||||
valueDescription = "<path>",
|
||||
description = "A path to cache directories"
|
||||
description = "A path to cache directory"
|
||||
)
|
||||
var cacheDirectories: String? by NullableStringFreezableVar(null)
|
||||
var cacheDirectory: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@Argument(value = "-Xir-build-cache", description = "Use compiler to build cache")
|
||||
var irBuildCache: Boolean by FreezableVar(false)
|
||||
|
||||
@@ -295,7 +295,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
|
||||
if (arguments.irProduceJs) {
|
||||
messageCollector.report(INFO, "Produce executable: $outputDirPath")
|
||||
messageCollector.report(INFO, arguments.cacheDirectories ?: "")
|
||||
messageCollector.report(INFO, "Cache directory: ${arguments.cacheDirectory}")
|
||||
|
||||
if (icCaches.isNotEmpty()) {
|
||||
val beforeIc2Js = System.currentTimeMillis()
|
||||
@@ -635,14 +635,14 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
configurationJs: CompilerConfiguration,
|
||||
mainCallArguments: List<String>?
|
||||
): List<ModuleArtifact> {
|
||||
val cacheDirectories = configureLibraries(arguments.cacheDirectories)
|
||||
val cacheDirectory = arguments.cacheDirectory
|
||||
|
||||
// TODO: Use JS IR IC infrastructure for WASM?
|
||||
val icCaches = if (!arguments.wasm && cacheDirectories.isNotEmpty()) {
|
||||
val icCaches = if (!arguments.wasm && cacheDirectory != null) {
|
||||
messageCollector.report(INFO, "")
|
||||
messageCollector.report(INFO, "Building cache:")
|
||||
messageCollector.report(INFO, "to: ${outputDir}")
|
||||
messageCollector.report(INFO, arguments.cacheDirectories ?: "")
|
||||
messageCollector.report(INFO, "to: $outputDir")
|
||||
messageCollector.report(INFO, "cache directory: $cacheDirectory")
|
||||
messageCollector.report(INFO, libraries.toString())
|
||||
|
||||
val start = System.currentTimeMillis()
|
||||
@@ -650,7 +650,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
val cacheUpdater = CacheUpdater(
|
||||
mainModule = arguments.includes!!,
|
||||
allModules = libraries,
|
||||
cacheDir = cacheDirectories.last(),
|
||||
cacheDir = cacheDirectory,
|
||||
compilerConfiguration = configurationJs,
|
||||
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
||||
mainArguments = mainCallArguments,
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
Usage: kotlinc-js <options> <source files>
|
||||
where advanced options include:
|
||||
-Xcache-directories=<path> A path to cache directories
|
||||
-Xcache-directory=<path> A path to cache directory
|
||||
-Xenable-js-scripting Enable experimental support of .kts files using K/JS (with -Xir only)
|
||||
-Xerror-tolerance-policy Set up error tolerance policy (NONE, SEMANTIC, SYNTAX, ALL)
|
||||
-Xenable-extension-functions-in-externals
|
||||
|
||||
+2
-31
@@ -23,12 +23,8 @@ import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode.DEVELOPMENT
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.utils.toHexString
|
||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||
import java.io.File
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.security.MessageDigest
|
||||
import javax.inject.Inject
|
||||
|
||||
@CacheableTask
|
||||
@@ -120,34 +116,9 @@ abstract class KotlinJsIrLink @Inject constructor(
|
||||
args.includes = entryModule.get().asFile.canonicalPath
|
||||
|
||||
if (incrementalJsIr && mode == DEVELOPMENT) {
|
||||
val digest = MessageDigest.getInstance("SHA-256")
|
||||
args.cacheDirectories = args.libraries?.splitByPathSeparator()
|
||||
?.map {
|
||||
val file = File(it)
|
||||
val hash = digest.digest(file.normalize().absolutePath.toByteArray(StandardCharsets.UTF_8)).toHexString()
|
||||
rootCacheDirectory
|
||||
.resolve(file.nameWithoutExtension)
|
||||
.resolve(hash)
|
||||
.also {
|
||||
it.mkdirs()
|
||||
}
|
||||
}
|
||||
?.plus(rootCacheDirectory.resolve(entryModule.get().asFile.name))
|
||||
?.let {
|
||||
if (it.isNotEmpty())
|
||||
it.joinToString(File.pathSeparator)
|
||||
else
|
||||
null
|
||||
}
|
||||
args.cacheDirectory = rootCacheDirectory.also { it.mkdirs() }.absolutePath
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.splitByPathSeparator(): List<String> {
|
||||
return this.split(File.pathSeparator.toRegex())
|
||||
.dropLastWhile { it.isEmpty() }
|
||||
.toTypedArray()
|
||||
.filterNot { it.isEmpty() }
|
||||
}
|
||||
}
|
||||
|
||||
val KotlinPlatformType.fileExtension
|
||||
@@ -161,4 +132,4 @@ val KotlinPlatformType.fileExtension
|
||||
}
|
||||
|
||||
else -> error("Only JS and WASM supported for KotlinJsTest")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user