Skip to content

Commit 7ff4e2f

Browse files
authored
Do not rename original destination directory of the compile task. (#312)
For targets that require IR transformation modification of compilation tasks output directories is not required. Classes from the original directories are transformed by the compiler plugin in place. Fixes #311
1 parent 88a5e14 commit 7ff4e2f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ private fun Project.needsJsIrTransformation(target: KotlinTarget): Boolean =
159159
(rootProject.getBooleanProperty(ENABLE_JS_IR_TRANSFORMATION) || rootProject.getBooleanProperty(ENABLE_JS_IR_TRANSFORMATION_LEGACY))
160160
&& target.isJsIrTarget()
161161

162+
private fun Project.needsJvmIrTransformation(target: KotlinTarget): Boolean =
163+
rootProject.getBooleanProperty(ENABLE_JVM_IR_TRANSFORMATION) &&
164+
(target.platformType == KotlinPlatformType.jvm || target.platformType == KotlinPlatformType.androidJvm)
165+
162166
private fun KotlinTarget.isJsIrTarget() = (this is KotlinJsTarget && this.irTarget != null) || this is KotlinJsIrTarget
163167

164168
private fun Project.addCompilerPluginDependency() {
@@ -263,6 +267,8 @@ private fun Project.configureTransformationForTarget(target: KotlinTarget) {
263267
val originalDirsByCompilation = hashMapOf<KotlinCompilation<*>, FileCollection>()
264268
val config = config
265269
target.compilations.all compilations@{ compilation ->
270+
// do not modify directories if compiler plugin is applied
271+
if (needsJvmIrTransformation(target) || needsJsIrTransformation(target)) return@compilations
266272
val compilationType = compilation.name.compilationNameToType()
267273
?: return@compilations // skip unknown compilations
268274
val classesDirs = compilation.output.classesDirs

atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/JvmProjectTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ class JvmIrTransformationTest : BaseKotlinGradleTest("jvm-simple") {
103103
@Test
104104
fun testAtomicfuReferences() {
105105
runner.build()
106-
checkBytecode("build/classes/atomicfu-orig/main/IntArithmetic.class")
106+
checkBytecode("build/classes/kotlin/main/IntArithmetic.class")
107107
}
108108
}

atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/MppProjectTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class MppJvmIrTransformationTest : BaseKotlinGradleTest("mpp-simple") {
112112
@Test
113113
fun testAtomicfuReferences() {
114114
runner.build()
115-
checkBytecode("build/classes/atomicfu-orig/jvm/main/IntArithmetic.class")
115+
checkBytecode("build/classes/kotlin/jvm/main/IntArithmetic.class")
116116
}
117117
}
118118

@@ -217,6 +217,6 @@ class MppBothIrTransformationTest : BaseKotlinGradleTest("mpp-simple") {
217217
@Test
218218
fun testAtomicfuReferences() {
219219
runner.build()
220-
checkBytecode("build/classes/atomicfu-orig/jvm/main/IntArithmetic.class")
220+
checkBytecode("build/classes/kotlin/jvm/main/IntArithmetic.class")
221221
}
222222
}

0 commit comments

Comments
 (0)