From 8dcc860a6dde07b40bd98ff83810a4a0d5997a5c Mon Sep 17 00:00:00 2001 From: Tadeas Kriz Date: Thu, 2 Jan 2025 12:09:34 -0500 Subject: [PATCH] Fix unpacked klib Swift bundling. --- .../co/touchlab/skie/util/file/FileIsSwift.kt | 6 ++++ .../switflink/SwiftUnpackingConfigurator.kt | 8 ++--- .../switflink/UnpackSwiftSourcesTask.kt | 31 +++++++++++++++++-- 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 SKIE/common/util/src/commonMain/kotlin/co/touchlab/skie/util/file/FileIsSwift.kt diff --git a/SKIE/common/util/src/commonMain/kotlin/co/touchlab/skie/util/file/FileIsSwift.kt b/SKIE/common/util/src/commonMain/kotlin/co/touchlab/skie/util/file/FileIsSwift.kt new file mode 100644 index 00000000..4592d94f --- /dev/null +++ b/SKIE/common/util/src/commonMain/kotlin/co/touchlab/skie/util/file/FileIsSwift.kt @@ -0,0 +1,6 @@ +package co.touchlab.skie.util.file + +import java.io.File + +val File.isSwift: Boolean + get() = extension == "swift" diff --git a/SKIE/skie-gradle/plugin-impl/src/main/kotlin/co/touchlab/skie/plugin/switflink/SwiftUnpackingConfigurator.kt b/SKIE/skie-gradle/plugin-impl/src/main/kotlin/co/touchlab/skie/plugin/switflink/SwiftUnpackingConfigurator.kt index 0470f012..286c44c0 100644 --- a/SKIE/skie-gradle/plugin-impl/src/main/kotlin/co/touchlab/skie/plugin/switflink/SwiftUnpackingConfigurator.kt +++ b/SKIE/skie-gradle/plugin-impl/src/main/kotlin/co/touchlab/skie/plugin/switflink/SwiftUnpackingConfigurator.kt @@ -9,13 +9,13 @@ object SwiftUnpackingConfigurator { fun configureCustomSwiftUnpacking(target: SkieTarget) { val unpackTask = target.registerSkieTargetBasedTask("unpackSwiftSources") { - val linkerKlibs = target.linkerConfiguration.fileCollection { true }.filter { it.isKlib } - klibs.from(linkerKlibs) + val linkerKlibs = target.linkerConfiguration.fileCollection { true }.filter { it.isKlib || it.isDirectory } + dependencies.addAll(linkerKlibs) if (target is SkieTarget.Binary) { - val currentModuleKlib = target.compilationProvider.map { it.compileTaskOutputFileProvider } + val currentModuleKlib = target.compilationProvider.flatMap { it.compileTaskOutputFileProvider } + dependencies.add(currentModuleKlib) - klibs.from(currentModuleKlib) // Needed because the klib is a plain Java file dependsOn(target.compilationProvider.flatMap { it.compileTaskProvider }) } diff --git a/SKIE/skie-gradle/plugin-impl/src/main/kotlin/co/touchlab/skie/plugin/switflink/UnpackSwiftSourcesTask.kt b/SKIE/skie-gradle/plugin-impl/src/main/kotlin/co/touchlab/skie/plugin/switflink/UnpackSwiftSourcesTask.kt index 27fbaca6..e3d55daa 100644 --- a/SKIE/skie-gradle/plugin-impl/src/main/kotlin/co/touchlab/skie/plugin/switflink/UnpackSwiftSourcesTask.kt +++ b/SKIE/skie-gradle/plugin-impl/src/main/kotlin/co/touchlab/skie/plugin/switflink/UnpackSwiftSourcesTask.kt @@ -4,12 +4,16 @@ import co.touchlab.skie.util.cache.syncDirectoryContentIfDifferent import co.touchlab.skie.util.collisionFreeIdentifier import co.touchlab.skie.util.file.deleteEmptyDirectoriesRecursively import co.touchlab.skie.util.file.isKlib +import co.touchlab.skie.util.file.isSwift import org.gradle.api.DefaultTask import org.gradle.api.file.ArchiveOperations -import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.file.FileCollection import org.gradle.api.file.FileSystemOperations import org.gradle.api.file.RelativePath +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction @@ -18,12 +22,33 @@ import javax.inject.Inject abstract class UnpackSwiftSourcesTask : DefaultTask() { + @get:Input + abstract val dependencies: ListProperty + @get:InputFiles - abstract val klibs: ConfigurableFileCollection + protected val klibs: FileCollection + get() = objects.fileCollection().also { files -> + dependencies.get().filter { it.isKlib }.forEach { + files.from(it) + } + } + + @get:InputFiles + protected val unpackedKlibSwiftFiles: FileCollection + get() = objects.fileCollection().also { files -> + dependencies.get().filter { it.isDirectory }.forEach { + files.from( + objects.fileTree().from(it).filter { it.isSwift } + ) + } + } @get:OutputDirectory abstract val output: Property + @get:Inject + abstract val objects: ObjectFactory + @get:Inject abstract val fileSystemOperations: FileSystemOperations @@ -57,7 +82,7 @@ abstract class UnpackSwiftSourcesTask : DefaultTask() { return uniqueName } - return klibs.map { it to it.getUniqueName() } + return dependencies.get().map { it to it.getUniqueName() } } private fun unpackKlib(klib: File, uniqueName: String, temporaryDirectory: File) {