@@ -287,45 +287,47 @@ private fun Project.configureTransformationForTarget(target: KotlinTarget) {
287
287
.dir(" classes/atomicfu/${target.name} /${compilation.name} " )
288
288
val transformTask = when (target.platformType) {
289
289
KotlinPlatformType .jvm, KotlinPlatformType .androidJvm -> {
290
- // skip transformation task if transformation is turned off or ir transformation is enabled
291
- if (! config.transformJvm || rootProject.getBooleanProperty(ENABLE_JVM_IR_TRANSFORMATION )) return @compilations
292
- project.registerJvmTransformTask(compilation)
293
- .configureJvmTask(
294
- compilation.compileDependencyFiles,
295
- compilation.compileAllTaskName,
296
- transformedClassesDir,
297
- originalClassesDirs,
298
- config
299
- )
300
- .also {
301
- compilation.defaultSourceSet.kotlin.compiledBy(it, AtomicFUTransformTask ::destinationDirectory)
302
- }
290
+ // create transformation task only if transformation is required and JVM IR compiler transformation is not enabled
291
+ if (config.transformJvm && ! rootProject.getBooleanProperty(ENABLE_JVM_IR_TRANSFORMATION )) {
292
+ project.registerJvmTransformTask(compilation)
293
+ .configureJvmTask(
294
+ compilation.compileDependencyFiles,
295
+ compilation.compileAllTaskName,
296
+ transformedClassesDir,
297
+ originalClassesDirs,
298
+ config
299
+ )
300
+ .also {
301
+ compilation.defaultSourceSet.kotlin.compiledBy(it, AtomicFUTransformTask ::destinationDirectory)
302
+ }
303
+ } else null
303
304
}
304
305
KotlinPlatformType .js -> {
305
- // skip when js transformation is not needed or when IR is transformed
306
- if (! config.transformJs || (needsJsIrTransformation(target))) {
307
- return @compilations
308
- }
309
- project.registerJsTransformTask(compilation)
310
- .configureJsTask(
311
- compilation.compileAllTaskName,
312
- transformedClassesDir,
313
- originalClassesDirs,
314
- config
315
- )
316
- .also {
317
- compilation.defaultSourceSet.kotlin.compiledBy(it, AtomicFUTransformJsTask ::destinationDirectory)
318
- }
306
+ // create transformation task only if transformation is required and JS IR compiler transformation is not enabled
307
+ if (config.transformJs && ! needsJsIrTransformation(target)) {
308
+ project.registerJsTransformTask(compilation)
309
+ .configureJsTask(
310
+ compilation.compileAllTaskName,
311
+ transformedClassesDir,
312
+ originalClassesDirs,
313
+ config
314
+ )
315
+ .also {
316
+ compilation.defaultSourceSet.kotlin.compiledBy(it, AtomicFUTransformJsTask ::destinationDirectory)
317
+ }
318
+ } else null
319
319
}
320
320
else -> error(" Unsupported transformation platform '${target.platformType} '" )
321
321
}
322
- // now transformTask is responsible for compiling this source set into the classes directory
323
- compilation.defaultSourceSet.kotlin.destinationDirectory.value(transformedClassesDir)
324
- classesDirs.setFrom(transformedClassesDir)
325
- classesDirs.setBuiltBy(listOf (transformTask))
326
- tasks.withType(Jar ::class .java).configureEach {
327
- if (name == target.artifactsTaskName) {
328
- it.setupJarManifest(multiRelease = config.jvmVariant.toJvmVariant() == JvmVariant .BOTH )
322
+ if (transformTask != null ) {
323
+ // now transformTask is responsible for compiling this source set into the classes directory
324
+ compilation.defaultSourceSet.kotlin.destinationDirectory.value(transformedClassesDir)
325
+ classesDirs.setFrom(transformedClassesDir)
326
+ classesDirs.setBuiltBy(listOf (transformTask))
327
+ tasks.withType(Jar ::class .java).configureEach {
328
+ if (name == target.artifactsTaskName) {
329
+ it.setupJarManifest(multiRelease = config.jvmVariant.toJvmVariant() == JvmVariant .BOTH )
330
+ }
329
331
}
330
332
}
331
333
// test should compile and run against original production binaries
@@ -335,15 +337,18 @@ private fun Project.configureTransformationForTarget(target: KotlinTarget) {
335
337
val originalMainClassesDirs = project.objects.fileCollection().from(
336
338
mainCompilation.compileTaskProvider.flatMap { (it as KotlinCompileTool ).destinationDirectory }
337
339
)
340
+ // compilationTask.destinationDirectory was changed from build/classes/kotlin/main to build/classes/atomicfu-orig/main,
341
+ // so we need to update libraries
338
342
(tasks.findByName(compilation.compileKotlinTaskName) as ? AbstractKotlinCompileTool <* >)
339
343
?.libraries
340
344
?.setFrom(
341
345
originalMainClassesDirs + compilation.compileDependencyFiles
342
346
)
343
-
344
- (tasks.findByName(" ${target.name}${compilation.name.capitalize()} " ) as ? Test )?.classpath =
345
- originalMainClassesDirs + (compilation as KotlinCompilationToRunnableFiles ).runtimeDependencyFiles - mainCompilation.output.classesDirs
346
-
347
+ if (transformTask != null ) {
348
+ // if transform task was not created, then originalMainClassesDirs == mainCompilation.output.classesDirs
349
+ (tasks.findByName(" ${target.name}${compilation.name.capitalize()} " ) as ? Test )?.classpath =
350
+ originalMainClassesDirs + (compilation as KotlinCompilationToRunnableFiles ).runtimeDependencyFiles - mainCompilation.output.classesDirs
351
+ }
347
352
compilation.compileKotlinTask.setFriendPaths(originalMainClassesDirs)
348
353
}
349
354
}
0 commit comments