Skip to content

Commit

Permalink
Properly share build outputs between projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Oct 24, 2024
1 parent 7e4d21a commit bf0d42a
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,80 @@ tasks.withType<IncrementalSyncTask>().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<NodeJsExec>().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<File>,
destinationDirectory: Provider<Directory>
) : 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<IncrementalSyncTask>("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<String> =
mutableListOf(
override fun asArguments(): Iterable<String> =
listOf(
input.get().asFile.absolutePath,
output.get().asFile.absolutePath
destinationDirectory.get().asFile.absolutePath
)
}
argumentProviders.add(objects.newInstance<ArgumentProvider>(rootProject))

argumentProviders.add(
objects.newInstance<ArgumentProvider>(
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<Directory> by it.extra
output.get()
}
)
}
45 changes: 44 additions & 1 deletion gradle/build-logic/src/main/kotlin/net/kautler/node.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,49 @@ configure<NodeJsRootExtension> {
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)
}

0 comments on commit bf0d42a

Please sign in to comment.