[Gradle, JS] Extension for outputFileProperty
This commit is contained in:
+18
-1
@@ -56,6 +56,10 @@ abstract class KotlinJsIrLink @Inject constructor(
|
||||
return !entryModule.get().asFile.exists()
|
||||
}
|
||||
|
||||
val platformType by lazy {
|
||||
compilation.platformType
|
||||
}
|
||||
|
||||
@Transient
|
||||
@get:Internal
|
||||
internal lateinit var compilation: KotlinCompilationData<*>
|
||||
@@ -146,4 +150,17 @@ abstract class KotlinJsIrLink @Inject constructor(
|
||||
.toTypedArray()
|
||||
.filterNot { it.isEmpty() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val KotlinPlatformType.fileExtension
|
||||
get() = when (this) {
|
||||
KotlinPlatformType.wasm -> {
|
||||
".mjs"
|
||||
}
|
||||
|
||||
KotlinPlatformType.js -> {
|
||||
".js"
|
||||
}
|
||||
|
||||
else -> error("Only JS and WASM supported for KotlinJsTest")
|
||||
}
|
||||
+1
-12
@@ -124,22 +124,11 @@ abstract class KotlinJsIrSubTarget(
|
||||
testJs.inputFileProperty.set(
|
||||
project.layout.file(
|
||||
binary.linkSyncTask.flatMap { copyTask ->
|
||||
val extension = when (compilation.platformType) {
|
||||
KotlinPlatformType.wasm -> {
|
||||
".mjs"
|
||||
}
|
||||
|
||||
KotlinPlatformType.js -> {
|
||||
".js"
|
||||
}
|
||||
|
||||
else -> error("Only JS and WASM supported for KotlinJsTest")
|
||||
}
|
||||
binary.linkTask
|
||||
.flatMap { linkTask -> linkTask.compilerOptions.moduleName }
|
||||
.map { outputName ->
|
||||
copyTask.destinationDir
|
||||
.resolve(outputName + extension)
|
||||
.resolve(outputName + compilation.platformType.fileExtension)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
+6
-9
@@ -1006,6 +1006,12 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
(compilerOptions as CompilerJsOptionsDefault).fillDefaultValues(args)
|
||||
super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors)
|
||||
|
||||
if (defaultsOnly) return
|
||||
|
||||
(compilerOptions as CompilerJsOptionsDefault).fillCompilerArguments(args)
|
||||
if (!args.sourceMapPrefix.isNullOrEmpty()) {
|
||||
args.sourceMapBaseDirs = sourceMapBaseDir.get().asFile.absolutePath
|
||||
}
|
||||
if (isIrBackendEnabled()) {
|
||||
val outputFilePath: String? = compilerOptions.outputFile.orNull
|
||||
if (outputFilePath != null) {
|
||||
@@ -1019,15 +1025,6 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
} else {
|
||||
args.outputFile = outputFileProperty.get().absoluteFile.normalize().absolutePath
|
||||
}
|
||||
|
||||
if (defaultsOnly) return
|
||||
|
||||
(compilerOptions as CompilerJsOptionsDefault).fillCompilerArguments(args)
|
||||
if (!args.sourceMapPrefix.isNullOrEmpty()) {
|
||||
args.sourceMapBaseDirs = sourceMapBaseDir.get().asFile.absolutePath
|
||||
}
|
||||
// Rewriting default outputFile property back to outputFilePropertyValue
|
||||
args.outputFile = outputFileProperty.get().absoluteFile.normalize().absolutePath
|
||||
// Overriding freeArgs from compilerOptions with enhanced one + additional one set on execution phase
|
||||
// containing additional arguments based on the js compilation configuration
|
||||
args.freeArgs = enhancedFreeCompilerArgs.get().union(additionalFreeCompilerArgs).toList()
|
||||
|
||||
+7
-2
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.PRODUCE_UNZIPPED_KLIB
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.PRODUCE_ZIPPED_KLIB
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.utils.klibModuleName
|
||||
import java.io.File
|
||||
|
||||
internal typealias Kotlin2JsCompileConfig = BaseKotlin2JsCompileConfig<Kotlin2JsCompile>
|
||||
|
||||
@@ -39,8 +40,12 @@ internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
||||
@Suppress("DEPRECATION")
|
||||
task.outputFileProperty.value(
|
||||
task.destinationDirectory.flatMap { dir ->
|
||||
task.compilerOptions.moduleName.map { name ->
|
||||
dir.file(name).asFile
|
||||
if (task.compilerOptions.outputFile.orNull != null) {
|
||||
task.compilerOptions.outputFile.map { File(it) }
|
||||
} else {
|
||||
task.compilerOptions.moduleName.map { name ->
|
||||
dir.file(name + compilation.platformType.fileExtension).asFile
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user