[Gradle, JS] Adopt changes about compilerOptions
This commit is contained in:
+1
-10
@@ -17,16 +17,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
}
|
||||
|
||||
@GradleDeprecatedOption(
|
||||
"Only for legacy backend. For IR backend please use task.destinationDirectory and moduleName",
|
||||
"1.10",
|
||||
DeprecationLevel.WARNING
|
||||
)
|
||||
@GradleOption(
|
||||
value = DefaultValues.StringNullDefault::class,
|
||||
gradleInputType = GradleInputTypes.INTERNAL // handled by task 'outputFileProperty'
|
||||
)
|
||||
@GradleDeprecatedOption(
|
||||
message = "Use task 'outputFileProperty' to specify location",
|
||||
message = "Only for legacy backend. For IR backend please use task.destinationDirectory and moduleName",
|
||||
level = DeprecationLevel.WARNING,
|
||||
removeAfter = "1.9.0"
|
||||
)
|
||||
|
||||
+4
-1
@@ -50,7 +50,10 @@ interface CompilerJsOptions : org.jetbrains.kotlin.gradle.dsl.CompilerCommonOpti
|
||||
*/
|
||||
@Deprecated(message = "Use task 'outputFileProperty' to specify location", level = DeprecationLevel.WARNING)
|
||||
@get:org.gradle.api.tasks.Internal
|
||||
val outputFile: org.gradle.api.provider.Property<kotlin.String>
|
||||
val outputFile: org.gradle.api.provider.Property<kotlin.String?>
|
||||
|
||||
@get:org.gradle.api.tasks.Input
|
||||
val outputName: org.gradle.api.provider.Property<kotlin.String>
|
||||
|
||||
/**
|
||||
* Generate source map
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ internal abstract class CompilerJsOptionsDefault @javax.inject.Inject constructo
|
||||
objectFactory.property(kotlin.Boolean::class.java).convention(true)
|
||||
|
||||
@Deprecated(message = "Use task 'outputFileProperty' to specify location", level = DeprecationLevel.WARNING)
|
||||
override val outputFile: org.gradle.api.provider.Property<kotlin.String> =
|
||||
override val outputFile: org.gradle.api.provider.Property<kotlin.String?> =
|
||||
objectFactory.property(kotlin.String::class.java)
|
||||
|
||||
override val sourceMap: org.gradle.api.provider.Property<kotlin.Boolean> =
|
||||
|
||||
+8
-7
@@ -52,6 +52,7 @@ internal const val COMPILER_CLASSPATH_CONFIGURATION_NAME = "kotlinCompilerClassp
|
||||
internal const val KLIB_COMMONIZER_CLASSPATH_CONFIGURATION_NAME = "kotlinKlibCommonizerClasspath"
|
||||
|
||||
val KOTLIN_DSL_NAME = "kotlin"
|
||||
|
||||
@Deprecated("Should be removed with 'platform.js' plugin removal")
|
||||
val KOTLIN_JS_DSL_NAME = "kotlin2js"
|
||||
val KOTLIN_OPTIONS_DSL_NAME = "kotlinOptions"
|
||||
@@ -156,11 +157,7 @@ internal abstract class KotlinSourceSetProcessor<T : AbstractKotlinCompile<*>>(
|
||||
protected fun applyStandardTaskConfiguration(taskConfiguration: AbstractKotlinCompileConfig<*>) {
|
||||
taskConfiguration.configureTask {
|
||||
it.description = taskDescription
|
||||
if (it is Kotlin2JsCompile) {
|
||||
it.defaultDestinationDirectory.convention(defaultKotlinDestinationDir)
|
||||
} else {
|
||||
it.destinationDirectory.convention(defaultKotlinDestinationDir)
|
||||
}
|
||||
it.destinationDirectory.convention(defaultKotlinDestinationDir)
|
||||
it.libraries.from({ kotlinCompilation.compileDependencyFiles })
|
||||
}
|
||||
}
|
||||
@@ -294,8 +291,11 @@ internal class KotlinJsIrSourceSetProcessor(
|
||||
compilation.binaries
|
||||
.withType(JsIrBinary::class.java)
|
||||
.all { binary ->
|
||||
val configAction = KotlinJsIrLinkConfig(compilation)
|
||||
applyStandardTaskConfiguration(configAction)
|
||||
val configAction = KotlinJsIrLinkConfig(binary)
|
||||
configAction.configureTask {
|
||||
it.description = taskDescription
|
||||
it.libraries.from({ kotlinCompilation.compileDependencyFiles })
|
||||
}
|
||||
configAction.configureTask { task ->
|
||||
task.modeProperty.set(binary.mode)
|
||||
task.dependsOn(kotlinTask)
|
||||
@@ -887,6 +887,7 @@ internal fun Project.forEachVariant(action: (BaseVariant) -> Unit) {
|
||||
androidExtension.featureVariants.all(action)
|
||||
}
|
||||
}
|
||||
|
||||
is TestExtension -> androidExtension.applicationVariants.all(action)
|
||||
}
|
||||
if (androidExtension is TestedExtension) {
|
||||
|
||||
+3
-3
@@ -205,9 +205,9 @@ abstract class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
),
|
||||
listOf(compilation)
|
||||
) { task ->
|
||||
val entryFileProvider = binary.linkSyncTask.map {
|
||||
it.destinationDir
|
||||
.resolve(binary.linkTask.get().outputName.get() + ".js")
|
||||
val entryFileProvider = binary.linkSyncTask.zip(binary.linkTask) { sync, link ->
|
||||
sync.destinationDir
|
||||
.resolve(link.compilerOptions.outputName.get() + ".js")
|
||||
}
|
||||
|
||||
task.description = "build webpack ${mode.name.toLowerCase()} bundle"
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ constructor(
|
||||
val linkTask = binary.linkTask
|
||||
|
||||
val compiledWasmFile = linkTask.map { link ->
|
||||
link.destinationDirectory.asFile.get().resolve(link.outputName.get() + ".wasm")
|
||||
link.destinationDirectory.asFile.get().resolve(link.compilerOptions.outputName.get() + ".wasm")
|
||||
}
|
||||
|
||||
//TODO This is temporary solution that overrides compiled files that triggers recompile and reoptimize wasm every time (when binaryen is enabled)
|
||||
|
||||
+2
-57
@@ -15,8 +15,8 @@ import org.gradle.workers.WorkerExecutor
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
|
||||
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
|
||||
import org.jetbrains.kotlin.gradle.dsl.CompilerJsOptionsDefault
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptionsImpl
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinCompilationData
|
||||
@@ -37,8 +37,7 @@ import javax.inject.Inject
|
||||
@CacheableTask
|
||||
abstract class KotlinJsIrLink @Inject constructor(
|
||||
objectFactory: ObjectFactory,
|
||||
workerExecutor: WorkerExecutor,
|
||||
private val projectLayout: ProjectLayout
|
||||
workerExecutor: WorkerExecutor
|
||||
) : Kotlin2JsCompile(
|
||||
objectFactory.newInstance(CompilerJsOptionsDefault::class.java),
|
||||
objectFactory,
|
||||
@@ -61,11 +60,6 @@ abstract class KotlinJsIrLink @Inject constructor(
|
||||
@get:Internal
|
||||
internal lateinit var compilation: KotlinCompilationData<*>
|
||||
|
||||
@get:Internal
|
||||
val platformType by project.provider {
|
||||
compilation.platformType
|
||||
}
|
||||
|
||||
@Transient
|
||||
@get:Internal
|
||||
internal val propertiesProvider = PropertiesProvider(project)
|
||||
@@ -152,53 +146,4 @@ abstract class KotlinJsIrLink @Inject constructor(
|
||||
.toTypedArray()
|
||||
.filterNot { it.isEmpty() }
|
||||
}
|
||||
|
||||
override fun setupCompilerArgs(args: K2JSCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
when (mode) {
|
||||
PRODUCTION -> {
|
||||
kotlinOptions.configureOptions(ENABLE_DCE, GENERATE_D_TS, MINIMIZED_MEMBER_NAMES)
|
||||
}
|
||||
|
||||
DEVELOPMENT -> {
|
||||
kotlinOptions.configureOptions(GENERATE_D_TS)
|
||||
}
|
||||
}
|
||||
val alreadyDefinedOutputMode = kotlinOptions.freeCompilerArgs
|
||||
.any { it.startsWith(PER_MODULE) }
|
||||
if (!alreadyDefinedOutputMode) {
|
||||
kotlinOptions.freeCompilerArgs += outputGranularity.toCompilerArgument()
|
||||
}
|
||||
super.setupCompilerArgs(args, defaultsOnly, ignoreClasspathResolutionErrors)
|
||||
}
|
||||
|
||||
private fun KotlinJsOptions.configureOptions(vararg additionalCompilerArgs: String) {
|
||||
freeCompilerArgs += (additionalCompilerArgs.toList() + PRODUCE_JS + "$ENTRY_IR_MODULE=${entryModule.get().asFile.canonicalPath}")
|
||||
.mapNotNull { arg ->
|
||||
if (kotlinOptions.freeCompilerArgs
|
||||
.any { it.startsWith(arg) }
|
||||
) null else arg
|
||||
}
|
||||
|
||||
if (platformType == KotlinPlatformType.wasm) {
|
||||
freeCompilerArgs += WASM_BACKEND
|
||||
}
|
||||
}
|
||||
|
||||
@get:Input
|
||||
override val filteredArgumentsMap: Map<String, String>
|
||||
get() {
|
||||
val superFiltered = super.filteredArgumentsMap
|
||||
return superFiltered.mapValues { (key, value) ->
|
||||
if (key != K2JSCompilerArguments::freeArgs.name) {
|
||||
value
|
||||
} else {
|
||||
value
|
||||
.removePrefix("[")
|
||||
.removeSuffix("]")
|
||||
.split(", ")
|
||||
.filter { !it.contains(ENTRY_IR_MODULE) }
|
||||
.joinToString()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-5
@@ -123,9 +123,8 @@ abstract class KotlinJsIrSubTarget(
|
||||
|
||||
testJs.inputFileProperty.set(
|
||||
project.layout.file(
|
||||
binary.linkSyncTask.map {
|
||||
val linkTask = binary.linkTask.get()
|
||||
val extension = when (linkTask.platformType) {
|
||||
binary.linkSyncTask.flatMap { copyTask ->
|
||||
val extension = when (compilation.platformType) {
|
||||
KotlinPlatformType.wasm -> {
|
||||
".mjs"
|
||||
}
|
||||
@@ -136,8 +135,12 @@ abstract class KotlinJsIrSubTarget(
|
||||
|
||||
else -> error("Only JS and WASM supported for KotlinJsTest")
|
||||
}
|
||||
it.destinationDir
|
||||
.resolve(linkTask.outputName.get() + extension)
|
||||
binary.linkTask
|
||||
.flatMap { linkTask -> linkTask.compilerOptions.outputName }
|
||||
.map { outputName ->
|
||||
copyTask.destinationDir
|
||||
.resolve(outputName + extension)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
-11
@@ -11,7 +11,6 @@ import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.Copy
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptionsImpl
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator.Companion.runTaskNameSuffix
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
|
||||
@@ -114,7 +113,6 @@ constructor(
|
||||
|
||||
private val commonLazy by lazy {
|
||||
compilations.all { compilation ->
|
||||
val npmProject = compilation.npmProject
|
||||
compilation.binaries
|
||||
.withType(JsIrBinary::class.java)
|
||||
.all { binary ->
|
||||
@@ -122,15 +120,6 @@ constructor(
|
||||
val tsValidationTask = registerTypeScriptCheckTask(binary)
|
||||
|
||||
binary.linkTask.configure {
|
||||
it.destinationDirectory.set(
|
||||
project.buildDir
|
||||
.resolve(COMPILE_SYNC)
|
||||
.resolve(if (compilation.platformType == KotlinPlatformType.wasm) "wasm" else "js")
|
||||
.resolve(compilation.name)
|
||||
.resolve(binary.name)
|
||||
.resolve(NpmProject.DIST_FOLDER)
|
||||
)
|
||||
(it.kotlinOptions as KotlinJsOptionsImpl).outputName = npmProject.name
|
||||
|
||||
it.finalizedBy(syncTask)
|
||||
|
||||
|
||||
+8
-12
@@ -908,6 +908,7 @@ abstract class KotlinCompile @Inject constructor(
|
||||
!classpathSnapshotFiles.shrunkPreviousClasspathSnapshotFile.exists() -> {
|
||||
NotAvailableDueToMissingClasspathSnapshot(classpathSnapshotFiles)
|
||||
}
|
||||
|
||||
inputChanges.getFileChanges(classpathSnapshotProperties.classpathSnapshot).none() -> NoChanges(classpathSnapshotFiles)
|
||||
else -> ToBeComputedByIncrementalCompiler(classpathSnapshotFiles)
|
||||
}
|
||||
@@ -976,17 +977,10 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
// Workaround to be able to use default value and change it later based on external input
|
||||
@get:Internal
|
||||
internal abstract val defaultDestinationDirectory: DirectoryProperty
|
||||
|
||||
@Deprecated("Use destinationDirectory and moduleName instead")
|
||||
@get:Internal
|
||||
abstract val outputFileProperty: Property<File>
|
||||
|
||||
@get:Input
|
||||
abstract val outputName: Property<String>
|
||||
|
||||
// Workaround to add additional compiler args based on the exising one
|
||||
// Currently there is a logic to add additional compiler arguments based on already existing one.
|
||||
// And it is not possible to update compilerOptions.freeCompilerArgs using some kind of .map
|
||||
@@ -1012,13 +1006,15 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
(compilerOptions as CompilerJsOptionsDefault).fillDefaultValues(args)
|
||||
super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors)
|
||||
|
||||
if (kotlinOptions.isIrBackendEnabled()) {
|
||||
if (kotlinOptions.outputFile != null) {
|
||||
args.outputDir = (kotlinOptions as KotlinJsOptionsImpl).destDir
|
||||
kotlinOptions.outputFile?.let { args.outputName = File(it).nameWithoutExtension }
|
||||
if (isIrBackendEnabled()) {
|
||||
val outputFilePath: String? = compilerOptions.outputFile.orNull
|
||||
if (outputFilePath != null) {
|
||||
val outputFile = File(outputFilePath)
|
||||
args.outputDir = (if (outputFile.extension == "") outputFile else outputFile.parentFile).normalize().absolutePath
|
||||
args.outputName = outputFile.nameWithoutExtension
|
||||
} else {
|
||||
args.outputDir = destinationDirectory.get().asFile.normalize().absolutePath
|
||||
args.outputName = outputName.get()
|
||||
args.outputName = compilerOptions.outputName.get()
|
||||
}
|
||||
} else {
|
||||
args.outputFile = outputFileProperty.get().absoluteFile.normalize().absolutePath
|
||||
|
||||
+7
-49
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.tasks.configuration
|
||||
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptionsImpl
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinCompilationData
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.isMainCompilationData
|
||||
@@ -35,60 +34,19 @@ internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
||||
|
||||
configureAdditionalFreeCompilerArguments(task, compilation)
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
task.compilerOptions.outputFile.convention(
|
||||
task.defaultDestinationDirectory.zip(task.enhancedFreeCompilerArgs) { destDir, freeArgs ->
|
||||
val baseName = if (compilation.isMainCompilationData()) {
|
||||
project.name
|
||||
} else {
|
||||
"${project.name}_${compilation.compilationPurpose}"
|
||||
}
|
||||
|
||||
if (freeArgs.contains(PRODUCE_UNZIPPED_KLIB)) {
|
||||
destDir.asFile.absoluteFile.normalize().absolutePath
|
||||
} else {
|
||||
if (compilation is KotlinJsIrCompilation) {
|
||||
destDir.asFile.resolve("$baseName.$KLIB_TYPE").absoluteFile.normalize().absolutePath
|
||||
} else {
|
||||
val extensionName = if (compilation.platformType == KotlinPlatformType.wasm) ".mjs" else ".js"
|
||||
destDir.asFile.resolve("${compilation.ownModuleName}$extensionName").absolutePath
|
||||
}
|
||||
}
|
||||
}
|
||||
task.compilerOptions.outputName.convention(
|
||||
compilation.ownModuleName
|
||||
)
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
task.outputFileProperty.value(
|
||||
task.compilerOptions.outputFile.map { File(it) }
|
||||
)
|
||||
|
||||
task.destinationDirectory
|
||||
.fileProvider(
|
||||
task.outputFileProperty.zip(task.enhancedFreeCompilerArgs) { outputFile, freeArgs ->
|
||||
if (freeArgs.contains(PRODUCE_UNZIPPED_KLIB)) {
|
||||
outputFile
|
||||
} else {
|
||||
outputFile.parentFile
|
||||
}
|
||||
}
|
||||
)
|
||||
.disallowChanges()
|
||||
|
||||
task.outputName.value(task.project.provider {
|
||||
(task.kotlinOptions as KotlinJsOptionsImpl).outputName ?: compilation.ownModuleName
|
||||
}).disallowChanges()
|
||||
|
||||
task.optionalOutputFile.fileProvider(
|
||||
task.outputFileProperty.flatMap { outputFile ->
|
||||
task.enhancedFreeCompilerArgs.flatMap { freeArgs ->
|
||||
task.project.providers.provider {
|
||||
outputFile.takeUnless {
|
||||
freeArgs.contains(PRODUCE_UNZIPPED_KLIB)
|
||||
}
|
||||
}
|
||||
task.destinationDirectory.flatMap { dir ->
|
||||
task.compilerOptions.outputName.map { name ->
|
||||
dir.file(name).asFile
|
||||
}
|
||||
}
|
||||
).disallowChanges()
|
||||
)
|
||||
|
||||
task.libraryCache.set(libraryCacheService).also { task.libraryCache.disallowChanges() }
|
||||
}
|
||||
}
|
||||
|
||||
+16
-5
@@ -5,18 +5,20 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.tasks.configuration
|
||||
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
|
||||
import java.io.File
|
||||
import org.gradle.api.InvalidUserDataException
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinCompilationData
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
|
||||
internal open class KotlinJsIrLinkConfig(
|
||||
compilation: KotlinJsIrCompilation
|
||||
) : BaseKotlin2JsCompileConfig<KotlinJsIrLink>(compilation) {
|
||||
private val binary: JsIrBinary
|
||||
) : BaseKotlin2JsCompileConfig<KotlinJsIrLink>(binary.compilation) {
|
||||
|
||||
private val compilation
|
||||
get() = binary.compilation
|
||||
|
||||
init {
|
||||
configureTask { task ->
|
||||
@@ -33,6 +35,15 @@ internal open class KotlinJsIrLinkConfig(
|
||||
}
|
||||
).disallowChanges()
|
||||
task.compilation = compilation
|
||||
task.destinationDirectory.convention(
|
||||
project.layout.buildDirectory
|
||||
.dir(COMPILE_SYNC)
|
||||
.map { it.dir(if (compilation.platformType == KotlinPlatformType.wasm) "wasm" else "js") }
|
||||
.map { it.dir(compilation.name) }
|
||||
.map { it.dir(binary.name) }
|
||||
.map { it.dir(NpmProject.DIST_FOLDER) }
|
||||
)
|
||||
task.compilerOptions.outputName.convention(project.provider { compilation.npmProject.name })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user