[Gradle, JS] Extension for outputFileProperty
This commit is contained in:
+17
@@ -56,6 +56,10 @@ abstract class KotlinJsIrLink @Inject constructor(
|
|||||||
return !entryModule.get().asFile.exists()
|
return !entryModule.get().asFile.exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val platformType by lazy {
|
||||||
|
compilation.platformType
|
||||||
|
}
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
@get:Internal
|
@get:Internal
|
||||||
internal lateinit var compilation: KotlinCompilationData<*>
|
internal lateinit var compilation: KotlinCompilationData<*>
|
||||||
@@ -147,3 +151,16 @@ abstract class KotlinJsIrLink @Inject constructor(
|
|||||||
.filterNot { it.isEmpty() }
|
.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(
|
testJs.inputFileProperty.set(
|
||||||
project.layout.file(
|
project.layout.file(
|
||||||
binary.linkSyncTask.flatMap { copyTask ->
|
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
|
binary.linkTask
|
||||||
.flatMap { linkTask -> linkTask.compilerOptions.moduleName }
|
.flatMap { linkTask -> linkTask.compilerOptions.moduleName }
|
||||||
.map { outputName ->
|
.map { outputName ->
|
||||||
copyTask.destinationDir
|
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)
|
(compilerOptions as CompilerJsOptionsDefault).fillDefaultValues(args)
|
||||||
super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors)
|
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()) {
|
if (isIrBackendEnabled()) {
|
||||||
val outputFilePath: String? = compilerOptions.outputFile.orNull
|
val outputFilePath: String? = compilerOptions.outputFile.orNull
|
||||||
if (outputFilePath != null) {
|
if (outputFilePath != null) {
|
||||||
@@ -1019,15 +1025,6 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
|||||||
} else {
|
} else {
|
||||||
args.outputFile = outputFileProperty.get().absoluteFile.normalize().absolutePath
|
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
|
// Overriding freeArgs from compilerOptions with enhanced one + additional one set on execution phase
|
||||||
// containing additional arguments based on the js compilation configuration
|
// containing additional arguments based on the js compilation configuration
|
||||||
args.freeArgs = enhancedFreeCompilerArgs.get().union(additionalFreeCompilerArgs).toList()
|
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.targets.js.ir.PRODUCE_ZIPPED_KLIB
|
||||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||||
import org.jetbrains.kotlin.gradle.utils.klibModuleName
|
import org.jetbrains.kotlin.gradle.utils.klibModuleName
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
internal typealias Kotlin2JsCompileConfig = BaseKotlin2JsCompileConfig<Kotlin2JsCompile>
|
internal typealias Kotlin2JsCompileConfig = BaseKotlin2JsCompileConfig<Kotlin2JsCompile>
|
||||||
|
|
||||||
@@ -39,8 +40,12 @@ internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
|||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
task.outputFileProperty.value(
|
task.outputFileProperty.value(
|
||||||
task.destinationDirectory.flatMap { dir ->
|
task.destinationDirectory.flatMap { dir ->
|
||||||
task.compilerOptions.moduleName.map { name ->
|
if (task.compilerOptions.outputFile.orNull != null) {
|
||||||
dir.file(name).asFile
|
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