Skip to content

Commit

Permalink
Fix unpacked klib Swift bundling.
Browse files Browse the repository at this point in the history
  • Loading branch information
TadeasKriz committed Jan 2, 2025
1 parent e498c10 commit 8dcc860
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package co.touchlab.skie.util.file

import java.io.File

val File.isSwift: Boolean
get() = extension == "swift"
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ object SwiftUnpackingConfigurator {

fun configureCustomSwiftUnpacking(target: SkieTarget) {
val unpackTask = target.registerSkieTargetBasedTask<UnpackSwiftSourcesTask>("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 })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,12 +22,33 @@ import javax.inject.Inject

abstract class UnpackSwiftSourcesTask : DefaultTask() {

@get:Input
abstract val dependencies: ListProperty<File>

@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<File>

@get:Inject
abstract val objects: ObjectFactory

@get:Inject
abstract val fileSystemOperations: FileSystemOperations

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8dcc860

Please sign in to comment.