Skip to content

Commit

Permalink
Remove JS Legacy Transformer and disable transformJs flag by default. (
Browse files Browse the repository at this point in the history
…#478)

Fixes #425
  • Loading branch information
mvicsokolova authored Oct 17, 2024
1 parent e154909 commit 5119e1a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 900 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ Here are the valid options:

### JS options

To turn off transformation for Kotlin/JS set option `transformJs` to `false`.
> Starting with version `0.26.0` `transformJs` flag does not take any effect and is disabled by default.
> Please ensure that this flag is not used in the atomicfu configuration of your project, you can safely remove it.
Here are all available configuration options (with their defaults):
```groovy
atomicfu {
dependenciesVersion = '0.25.0' // set to null to turn-off auto dependencies
transformJvm = true // set to false to turn off JVM transformation
jvmVariant = "FU" // JVM transformation variant: FU,VH, or BOTH
transformJs = true // set to false to turn off JVM transformation
}
```

Expand Down
13 changes: 0 additions & 13 deletions atomicfu-gradle-plugin/api/atomicfu-gradle-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ public final class kotlinx/atomicfu/plugin/gradle/AtomicFUPluginExtension {
public final fun setVerbose (Z)V
}

public abstract class kotlinx/atomicfu/plugin/gradle/AtomicFUTransformJsTask : org/gradle/api/internal/ConventionTask {
public field inputFiles Lorg/gradle/api/file/FileCollection;
public fun <init> ()V
public abstract fun getDestinationDirectory ()Lorg/gradle/api/file/DirectoryProperty;
public final fun getInputFiles ()Lorg/gradle/api/file/FileCollection;
public final fun getOutputDir ()Ljava/io/File;
public final fun getVerbose ()Z
public final fun setInputFiles (Lorg/gradle/api/file/FileCollection;)V
public final fun setOutputDir (Ljava/io/File;)V
public final fun setVerbose (Z)V
public final fun transform ()V
}

public abstract class kotlinx/atomicfu/plugin/gradle/AtomicFUTransformTask : org/gradle/api/internal/ConventionTask {
public field classPath Lorg/gradle/api/file/FileCollection;
public field inputFiles Lorg/gradle/api/file/FileCollection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import org.gradle.util.*
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.targets.js.*
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
import org.jetbrains.kotlin.gradle.tasks.*
import java.io.*
import java.util.*
Expand Down Expand Up @@ -99,7 +97,7 @@ private fun Project.configureDependencies() {
}
withPluginWhenEvaluatedDependencies("org.jetbrains.kotlin.js") { version ->
dependencies.add(
if (config.transformJs) COMPILE_ONLY_CONFIGURATION else IMPLEMENTATION_CONFIGURATION,
if (needsJsIrTransformation(KotlinPlatformType.js)) COMPILE_ONLY_CONFIGURATION else IMPLEMENTATION_CONFIGURATION,
getAtomicfuDependencyNotation(Platform.JS, version)
)
dependencies.add(TEST_IMPLEMENTATION_CONFIGURATION, getAtomicfuDependencyNotation(Platform.JS, version))
Expand Down Expand Up @@ -176,26 +174,22 @@ private fun String.toBooleanStrict(): Boolean = when (this) {
else -> throw IllegalArgumentException("The string doesn't represent a boolean value: $this")
}

internal fun Project.needsJsIrTransformation(target: KotlinTarget): Boolean =
internal fun Project.needsJsIrTransformation(targetPlatformType: KotlinPlatformType): Boolean =
(rootProject.getBooleanProperty(ENABLE_JS_IR_TRANSFORMATION) || rootProject.getBooleanProperty(ENABLE_JS_IR_TRANSFORMATION_LEGACY))
&& target.isJsIrTarget()
&& targetPlatformType == KotlinPlatformType.js

internal fun Project.needsJvmIrTransformation(target: KotlinTarget): Boolean =
internal fun Project.needsJvmIrTransformation(targetPlatformType: KotlinPlatformType): Boolean =
rootProject.getBooleanProperty(ENABLE_JVM_IR_TRANSFORMATION) &&
(target.platformType == KotlinPlatformType.jvm || target.platformType == KotlinPlatformType.androidJvm)
(targetPlatformType == KotlinPlatformType.jvm || targetPlatformType == KotlinPlatformType.androidJvm)

internal fun Project.needsNativeIrTransformation(target: KotlinTarget): Boolean =
internal fun Project.needsNativeIrTransformation(targetPlatformType: KotlinPlatformType): Boolean =
rootProject.getBooleanProperty(ENABLE_NATIVE_IR_TRANSFORMATION) &&
(target.platformType == KotlinPlatformType.native)

private fun KotlinTarget.isJsIrTarget() =
(this is KotlinJsTarget && this.irTarget != null) ||
(this is KotlinJsIrTarget && this.platformType != KotlinPlatformType.wasm)
(targetPlatformType == KotlinPlatformType.native)

private fun Project.isTransitiveAtomicfuDependencyRequired(target: KotlinTarget): Boolean {
val platformType = target.platformType
return !config.transformJvm && (platformType == KotlinPlatformType.jvm || platformType == KotlinPlatformType.androidJvm) ||
(!config.transformJs && platformType == KotlinPlatformType.js) ||
(!needsJsIrTransformation(platformType) && platformType == KotlinPlatformType.js) ||
platformType == KotlinPlatformType.wasm ||
// Always add the transitive atomicfu dependency for native targets, see #379
platformType == KotlinPlatformType.native
Expand All @@ -206,7 +200,7 @@ private fun Project.isTransitiveAtomicfuDependencyRequired(target: KotlinTarget)
private fun Project.addJsCompilerPluginRuntimeDependency() {
if (isCompilerPluginAvailable()) {
withKotlinTargets { target ->
if (target.isJsIrTarget()) {
if (needsJsIrTransformation(target.platformType)) {
target.compilations.forEach { kotlinCompilation ->
kotlinCompilation.dependencies {
if (getKotlinVersion().atLeast(1, 7, 10)) {
Expand Down Expand Up @@ -287,9 +281,6 @@ private fun Project.configureTasks() {
withPluginWhenEvaluated("kotlin") {
if (config.transformJvm) configureJvmTransformation()
}
withPluginWhenEvaluated("org.jetbrains.kotlin.js") {
if (config.transformJs) configureJsTransformation()
}
withPluginWhenEvaluated("kotlin-multiplatform") {
configureMultiplatformTransformation()
}
Expand All @@ -298,26 +289,20 @@ private fun Project.configureTasks() {
private fun Project.configureJvmTransformation() {
if (kotlinExtension is KotlinJvmProjectExtension || kotlinExtension is KotlinAndroidProjectExtension) {
val target = (kotlinExtension as KotlinSingleTargetExtension<*>).target
if (!needsJvmIrTransformation(target)) {
if (!needsJvmIrTransformation(target.platformType)) {
configureTransformationForTarget(target)
}
}
}

private fun Project.configureJsTransformation() {
val target = (kotlinExtension as KotlinJsProjectExtension).js()
if (!needsJsIrTransformation(target)) {
configureTransformationForTarget(target)
}
}

private fun Project.configureMultiplatformTransformation() =
withKotlinTargets { target ->
// Skip transformation for common, native and wasm targets or in case IR transformation by the compiler plugin is enabled (for JVM or JS targets)
// Skip transformation for common, native and wasm and js targets or in case IR transformation by the compiler plugin is enabled (for JVM or JS targets)
if (target.platformType == KotlinPlatformType.common ||
target.platformType == KotlinPlatformType.native ||
target.platformType == KotlinPlatformType.wasm ||
needsJvmIrTransformation(target) || needsJsIrTransformation(target)
target.platformType == KotlinPlatformType.js ||
needsJvmIrTransformation(target.platformType) || needsJsIrTransformation(target.platformType)
) {
return@withKotlinTargets
}
Expand Down Expand Up @@ -367,21 +352,6 @@ private fun Project.configureTransformationForTarget(target: KotlinTarget) {
}
} else null
}
KotlinPlatformType.js -> {
// create transformation task only if transformation is required and JS IR compiler transformation is not enabled
if (config.transformJs && !needsJsIrTransformation(target)) {
project.registerJsTransformTask(compilation)
.configureJsTask(
compilation.compileAllTaskName,
transformedClassesDir,
originalClassesDirs,
config
)
.also {
compilation.defaultSourceSet.kotlin.compiledBy(it, AtomicFUTransformJsTask::destinationDirectory)
}
} else null
}
else -> error("Unsupported transformation platform '${target.platformType}'")
}
if (transformTask != null) {
Expand Down Expand Up @@ -427,12 +397,6 @@ private fun Project.registerJvmTransformTask(compilation: KotlinCompilation<*>):
AtomicFUTransformTask::class.java
)

private fun Project.registerJsTransformTask(compilation: KotlinCompilation<*>): TaskProvider<AtomicFUTransformJsTask> =
tasks.register(
"transform${compilation.target.name.capitalize()}${compilation.name.capitalize()}Atomicfu",
AtomicFUTransformJsTask::class.java
)

private fun TaskProvider<AtomicFUTransformTask>.configureJvmTask(
classpath: FileCollection,
classesTaskName: String,
Expand All @@ -451,21 +415,6 @@ private fun TaskProvider<AtomicFUTransformTask>.configureJvmTask(
}
}

private fun TaskProvider<AtomicFUTransformJsTask>.configureJsTask(
classesTaskName: String,
transformedClassesDir: Provider<Directory>,
originalClassesDir: FileCollection,
config: AtomicFUPluginExtension
): TaskProvider<AtomicFUTransformJsTask> =
apply {
configure {
it.dependsOn(classesTaskName)
it.inputFiles = originalClassesDir
it.destinationDirectory.value(transformedClassesDir)
it.verbose = config.verbose
}
}

private fun Jar.setupJarManifest(multiRelease: Boolean) {
if (multiRelease) {
manifest.attributes.apply {
Expand All @@ -477,7 +426,11 @@ private fun Jar.setupJarManifest(multiRelease: Boolean) {
class AtomicFUPluginExtension(pluginVersion: String?) {
var dependenciesVersion = pluginVersion
var transformJvm = true
var transformJs = true

@Deprecated("This flag was previously used to enable or disable kotlinx-atomicfu transformations of the final *.js files produced by the JS Legacy backend. " +
"Starting from version 0.26.0 of `kotlinx-atomicfu`, it does not take any effect, is disabled by default and will be removed in the next release. " +
"Please ensure that this flag is not used in the atomicfu configuration of your project, you can safely remove it.")
var transformJs = false
var jvmVariant: String = "FU"
var verbose: Boolean = false
}
Expand Down Expand Up @@ -529,43 +482,3 @@ abstract class AtomicFUTransformTask : ConventionTask() {
}
}
}

@CacheableTask
abstract class AtomicFUTransformJsTask : ConventionTask() {

@get:Inject
internal abstract val providerFactory: ProviderFactory

@get:Inject
internal abstract val projectLayout: ProjectLayout

@PathSensitive(PathSensitivity.RELATIVE)
@InputFiles
lateinit var inputFiles: FileCollection

@Suppress("unused")
@Deprecated(
message = "Replaced with 'destinationDirectory'",
replaceWith = ReplaceWith("destinationDirectory")
)
@get:Internal
var outputDir: File
get() = destinationDirectory.get().asFile
set(value) { destinationDirectory.value(projectLayout.dir(providerFactory.provider { value })) }

@get:OutputDirectory
abstract val destinationDirectory: DirectoryProperty

@Input
var verbose = false

@TaskAction
fun transform() {
inputFiles.files.forEach { inputDir ->
AtomicFUTransformerJS(inputDir, destinationDirectory.get().asFile).let { t ->
t.verbose = verbose
t.transform()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ internal class AtomicfuKotlinCompilerPluginInternal : KotlinCompilerPluginSuppor

override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean {
val target = kotlinCompilation.target
val targetPlatformType = target.platformType
val project = target.project
return project.needsJvmIrTransformation(target) || project.needsJsIrTransformation(target) || project.needsNativeIrTransformation(target)
return project.needsJvmIrTransformation(targetPlatformType) || project.needsJsIrTransformation(targetPlatformType) || project.needsNativeIrTransformation(targetPlatformType)
}

override fun applyToCompilation(
Expand Down
51 changes: 0 additions & 51 deletions atomicfu-transformer/api/atomicfu-transformer.api
Original file line number Diff line number Diff line change
Expand Up @@ -84,57 +84,6 @@ public final class kotlinx/atomicfu/transformer/AtomicFUTransformerBase$SourceIn
public fun toString ()Ljava/lang/String;
}

public final class kotlinx/atomicfu/transformer/AtomicFUTransformerJS : kotlinx/atomicfu/transformer/AtomicFUTransformerBase {
public fun <init> (Ljava/io/File;Ljava/io/File;)V
public fun transform ()V
}

public final class kotlinx/atomicfu/transformer/AtomicFUTransformerJS$AtomicConstructorDetector : org/mozilla/javascript/ast/NodeVisitor {
public fun <init> (Lkotlinx/atomicfu/transformer/AtomicFUTransformerJS;)V
public fun visit (Lorg/mozilla/javascript/ast/AstNode;)Z
}

public final class kotlinx/atomicfu/transformer/AtomicFUTransformerJS$AtomicOperationsInliner : org/mozilla/javascript/ast/NodeVisitor {
public fun <init> (Lkotlinx/atomicfu/transformer/AtomicFUTransformerJS;)V
public fun visit (Lorg/mozilla/javascript/ast/AstNode;)Z
}

public final class kotlinx/atomicfu/transformer/AtomicFUTransformerJS$DelegatedPropertyAccessorsVisitor : org/mozilla/javascript/ast/NodeVisitor {
public fun <init> (Lkotlinx/atomicfu/transformer/AtomicFUTransformerJS;)V
public fun visit (Lorg/mozilla/javascript/ast/AstNode;)Z
}

public final class kotlinx/atomicfu/transformer/AtomicFUTransformerJS$DependencyEraser : org/mozilla/javascript/ast/NodeVisitor {
public fun <init> (Lkotlinx/atomicfu/transformer/AtomicFUTransformerJS;)V
public fun visit (Lorg/mozilla/javascript/ast/AstNode;)Z
}

public final class kotlinx/atomicfu/transformer/AtomicFUTransformerJS$FieldDelegatesVisitor : org/mozilla/javascript/ast/NodeVisitor {
public fun <init> (Lkotlinx/atomicfu/transformer/AtomicFUTransformerJS;)V
public fun visit (Lorg/mozilla/javascript/ast/AstNode;)Z
}

public final class kotlinx/atomicfu/transformer/AtomicFUTransformerJS$ReceiverResolver : org/mozilla/javascript/ast/NodeVisitor {
public fun <init> (Lkotlinx/atomicfu/transformer/AtomicFUTransformerJS;Ljava/lang/String;)V
public final fun getReceiver ()Lorg/mozilla/javascript/ast/AstNode;
public final fun setReceiver (Lorg/mozilla/javascript/ast/AstNode;)V
public fun visit (Lorg/mozilla/javascript/ast/AstNode;)Z
}

public final class kotlinx/atomicfu/transformer/AtomicFUTransformerJS$TopLevelDelegatedFieldsAccessorVisitor : org/mozilla/javascript/ast/NodeVisitor {
public fun <init> (Lkotlinx/atomicfu/transformer/AtomicFUTransformerJS;)V
public fun visit (Lorg/mozilla/javascript/ast/AstNode;)Z
}

public final class kotlinx/atomicfu/transformer/AtomicFUTransformerJS$TransformVisitor : org/mozilla/javascript/ast/NodeVisitor {
public fun <init> (Lkotlinx/atomicfu/transformer/AtomicFUTransformerJS;)V
public fun visit (Lorg/mozilla/javascript/ast/AstNode;)Z
}

public final class kotlinx/atomicfu/transformer/AtomicFUTransformerJSKt {
public static final fun main ([Ljava/lang/String;)V
}

public final class kotlinx/atomicfu/transformer/AtomicFUTransformerKt {
public static final fun main ([Ljava/lang/String;)V
}
Expand Down
Loading

0 comments on commit 5119e1a

Please sign in to comment.