From bf0d42a2f09a7e2930de0db7afa7c4fb61573685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Sat, 14 Sep 2024 16:04:36 +0200 Subject: [PATCH] Properly share build outputs between projects --- .../kotlin/net/kautler/ncc_packer.gradle.kts | 85 ++++++++++++++----- .../main/kotlin/net/kautler/node.gradle.kts | 45 +++++++++- 2 files changed, 107 insertions(+), 23 deletions(-) diff --git a/gradle/build-logic/src/main/kotlin/net/kautler/ncc_packer.gradle.kts b/gradle/build-logic/src/main/kotlin/net/kautler/ncc_packer.gradle.kts index c60911c..967cd9d 100644 --- a/gradle/build-logic/src/main/kotlin/net/kautler/ncc_packer.gradle.kts +++ b/gradle/build-logic/src/main/kotlin/net/kautler/ncc_packer.gradle.kts @@ -54,39 +54,80 @@ tasks.withType().configureEach { } } +// work-around for missing feature in dependencies block added in Gradle 8.3 +//val setupWsl by configurations.registering { +val setupWslExecutable by configurations.creating { + isCanBeConsumed = false + isCanBeResolved = false + isVisible = false +} + +val setupWslExecutableFile by configurations.registering { + isCanBeConsumed = false + isCanBeResolved = true + isVisible = false + extendsFrom(setupWslExecutable) +} + +dependencies { + setupWslExecutable(project(path = ":", configuration = "executable")) +} + // work-around for https://youtrack.jetbrains.com/issue/KT-56305 tasks.withType().configureEach { - abstract class ArgumentProvider @Inject constructor(rootProject: Project) : CommandLineArgumentProvider { + val output by extra { + layout.buildDirectory.dir("distributions/$name") + } + + abstract class ArgumentProvider @Inject constructor( + setupWslExecutableFile: Provider, + destinationDirectory: Provider + ) : CommandLineArgumentProvider { @get:InputFile - @get:SkipWhenEmpty abstract val input: RegularFileProperty @get:OutputDirectory - abstract val output: DirectoryProperty + abstract val destinationDirectory: DirectoryProperty init { - input.fileProvider( - rootProject - .tasks - .named("jsProductionExecutableCompileSync") - .map { - it - .outputs - .files - .asFileTree - .matching { include("${rootProject.name}.js") } - .singleFile - } - ) - - output.set(rootProject.layout.buildDirectory.dir("distributions")) + input.fileProvider(setupWslExecutableFile) + this.destinationDirectory.set(destinationDirectory) } - override fun asArguments(): MutableIterable = - mutableListOf( + override fun asArguments(): Iterable = + listOf( input.get().asFile.absolutePath, - output.get().asFile.absolutePath + destinationDirectory.get().asFile.absolutePath ) } - argumentProviders.add(objects.newInstance(rootProject)) + + argumentProviders.add( + objects.newInstance( + setupWslExecutableFile + .flatMap { it.elements } + .map { it.single().asFile }, + output + ) + ) + + doFirst { + output.get().asFile.deleteRecursively() + } +} + +val setupWslDistribution by configurations.registering { + isCanBeConsumed = true + isCanBeResolved = false + isVisible = false +} + +artifacts { + val jsNodeProductionRun by tasks.existing + add( + setupWslDistribution.name, + jsNodeProductionRun.map { + val output: Provider by it.extra + output.get() + } + ) } diff --git a/gradle/build-logic/src/main/kotlin/net/kautler/node.gradle.kts b/gradle/build-logic/src/main/kotlin/net/kautler/node.gradle.kts index 739c64b..668df89 100644 --- a/gradle/build-logic/src/main/kotlin/net/kautler/node.gradle.kts +++ b/gradle/build-logic/src/main/kotlin/net/kautler/node.gradle.kts @@ -95,6 +95,49 @@ configure { version = libs.versions.build.node.get() } +val executable by configurations.registering { + isCanBeConsumed = true + isCanBeResolved = false + isVisible = false +} + +artifacts { + val jsProductionExecutableCompileSync by tasks.existing(IncrementalSyncTask::class) + add( + executable.name, + jsProductionExecutableCompileSync.map { + it + .destinationDirectory + .get() + .resolve("${project.name}.js") + } + ) +} + +// work-around for missing feature in dependencies block added in Gradle 8.3 +//val setupWsl by configurations.registering { +val setupWslDistribution by configurations.creating { + isCanBeConsumed = false + isCanBeResolved = false + isVisible = false +} + +val setupWslDistributionFiles by configurations.registering { + isCanBeConsumed = false + isCanBeResolved = true + isVisible = false + extendsFrom(setupWslDistribution) +} + +dependencies { + setupWslDistribution(project(path = ":ncc-packer", configuration = "setupWslDistribution")) +} + +val syncDistribution by tasks.registering(Sync::class) { + from(setupWslDistributionFiles) + into(layout.buildDirectory.dir("distributions")) +} + tasks.assemble { - dependsOn(project(":ncc-packer").tasks.named("jsNodeProductionRun")) + dependsOn(syncDistribution) }