[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)
|
var includes: String? by NullableStringFreezableVar(null)
|
||||||
|
|
||||||
@Argument(
|
@Argument(
|
||||||
value = "-Xcache-directories",
|
value = "-Xcache-directory",
|
||||||
valueDescription = "<path>",
|
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")
|
@Argument(value = "-Xir-build-cache", description = "Use compiler to build cache")
|
||||||
var irBuildCache: Boolean by FreezableVar(false)
|
var irBuildCache: Boolean by FreezableVar(false)
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
|
|
||||||
if (arguments.irProduceJs) {
|
if (arguments.irProduceJs) {
|
||||||
messageCollector.report(INFO, "Produce executable: $outputDirPath")
|
messageCollector.report(INFO, "Produce executable: $outputDirPath")
|
||||||
messageCollector.report(INFO, arguments.cacheDirectories ?: "")
|
messageCollector.report(INFO, "Cache directory: ${arguments.cacheDirectory}")
|
||||||
|
|
||||||
if (icCaches.isNotEmpty()) {
|
if (icCaches.isNotEmpty()) {
|
||||||
val beforeIc2Js = System.currentTimeMillis()
|
val beforeIc2Js = System.currentTimeMillis()
|
||||||
@@ -635,14 +635,14 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
configurationJs: CompilerConfiguration,
|
configurationJs: CompilerConfiguration,
|
||||||
mainCallArguments: List<String>?
|
mainCallArguments: List<String>?
|
||||||
): List<ModuleArtifact> {
|
): List<ModuleArtifact> {
|
||||||
val cacheDirectories = configureLibraries(arguments.cacheDirectories)
|
val cacheDirectory = arguments.cacheDirectory
|
||||||
|
|
||||||
// TODO: Use JS IR IC infrastructure for WASM?
|
// 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, "")
|
||||||
messageCollector.report(INFO, "Building cache:")
|
messageCollector.report(INFO, "Building cache:")
|
||||||
messageCollector.report(INFO, "to: ${outputDir}")
|
messageCollector.report(INFO, "to: $outputDir")
|
||||||
messageCollector.report(INFO, arguments.cacheDirectories ?: "")
|
messageCollector.report(INFO, "cache directory: $cacheDirectory")
|
||||||
messageCollector.report(INFO, libraries.toString())
|
messageCollector.report(INFO, libraries.toString())
|
||||||
|
|
||||||
val start = System.currentTimeMillis()
|
val start = System.currentTimeMillis()
|
||||||
@@ -650,7 +650,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
val cacheUpdater = CacheUpdater(
|
val cacheUpdater = CacheUpdater(
|
||||||
mainModule = arguments.includes!!,
|
mainModule = arguments.includes!!,
|
||||||
allModules = libraries,
|
allModules = libraries,
|
||||||
cacheDir = cacheDirectories.last(),
|
cacheDir = cacheDirectory,
|
||||||
compilerConfiguration = configurationJs,
|
compilerConfiguration = configurationJs,
|
||||||
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
||||||
mainArguments = mainCallArguments,
|
mainArguments = mainCallArguments,
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
Usage: kotlinc-js <options> <source files>
|
Usage: kotlinc-js <options> <source files>
|
||||||
where advanced options include:
|
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)
|
-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)
|
-Xerror-tolerance-policy Set up error tolerance policy (NONE, SEMANTIC, SYNTAX, ALL)
|
||||||
-Xenable-extension-functions-in-externals
|
-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
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode.DEVELOPMENT
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode.DEVELOPMENT
|
||||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
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.BooleanMetrics
|
||||||
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||||
import java.io.File
|
|
||||||
import java.nio.charset.StandardCharsets
|
|
||||||
import java.security.MessageDigest
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@CacheableTask
|
@CacheableTask
|
||||||
@@ -120,34 +116,9 @@ abstract class KotlinJsIrLink @Inject constructor(
|
|||||||
args.includes = entryModule.get().asFile.canonicalPath
|
args.includes = entryModule.get().asFile.canonicalPath
|
||||||
|
|
||||||
if (incrementalJsIr && mode == DEVELOPMENT) {
|
if (incrementalJsIr && mode == DEVELOPMENT) {
|
||||||
val digest = MessageDigest.getInstance("SHA-256")
|
args.cacheDirectory = rootCacheDirectory.also { it.mkdirs() }.absolutePath
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.splitByPathSeparator(): List<String> {
|
|
||||||
return this.split(File.pathSeparator.toRegex())
|
|
||||||
.dropLastWhile { it.isEmpty() }
|
|
||||||
.toTypedArray()
|
|
||||||
.filterNot { it.isEmpty() }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val KotlinPlatformType.fileExtension
|
val KotlinPlatformType.fileExtension
|
||||||
@@ -161,4 +132,4 @@ val KotlinPlatformType.fileExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
else -> error("Only JS and WASM supported for KotlinJsTest")
|
else -> error("Only JS and WASM supported for KotlinJsTest")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user