|
1 | 1 | package com.chromaticnoise.multiplatformswiftpackage.task
|
2 | 2 |
|
3 | 3 | import com.chromaticnoise.multiplatformswiftpackage.domain.*
|
4 |
| -import com.chromaticnoise.multiplatformswiftpackage.domain.PluginConfiguration |
5 |
| -import com.chromaticnoise.multiplatformswiftpackage.domain.getConfigurationOrThrow |
6 | 4 | import org.gradle.api.Project
|
7 | 5 | import org.gradle.api.tasks.Exec
|
8 | 6 | import org.gradle.kotlin.dsl.task
|
@@ -41,62 +39,18 @@ internal fun getTvosSimulatorFrameworks(configuration: PluginConfiguration): Lis
|
41 | 39 | }
|
42 | 40 |
|
43 | 41 | internal fun Project.registerCreateUniversalMacosFrameworkTask() =
|
44 |
| - task("createUniversalMacosFramework") { |
45 |
| - // Can't use FatFrameworkTask 🙃 |
46 |
| - // https://youtrack.jetbrains.com/issue/KT-47355/Support-macos-target-for-FatFramework-task |
47 |
| - // workaround: |
48 |
| - // https://gist.github.com/JUSTINMKAUFMAN/6627c3c8571563b36efc9c832f6fa2b1 |
| 42 | + task<FatFrameworkTask>("createUniversalMacosSimulatorFramework") { |
49 | 43 | group = "multiplatform-swift-package"
|
50 | 44 | description = "Creates a universal (fat) macos framework"
|
51 | 45 | val configuration = getConfigurationOrThrow()
|
52 | 46 | onlyIf { getMacosFrameworks(configuration).size > 1 }
|
53 | 47 | val targets = getMacosFrameworks(configuration)
|
54 | 48 | dependsOn(targets.map { it.linkTask.name })
|
55 |
| - doLast { |
56 |
| - if (targets.isNotEmpty()) { |
57 |
| - delete(buildDir.resolve("bin/macosUniversal")) |
58 |
| - val buildType = if (targets[0].linkTask.name.contains("Release")) "release" else "debug" |
59 |
| - val frameworkName = targets[0].name.value |
60 |
| - val destinationDir = buildDir.resolve("bin/macosUniversal/${buildType}Framework") |
61 |
| - mkdir(destinationDir.parent) |
62 |
| - mkdir(destinationDir) |
63 |
| - val tempUniversalBinaryLocation = File(destinationDir, frameworkName) |
64 |
| - exec { |
65 |
| - commandLine( |
66 |
| - "lipo", |
67 |
| - "-create", |
68 |
| - "${targets[0].outputFile.path}/Versions/A/${frameworkName}", |
69 |
| - "${targets[1].outputFile.path}/Versions/A/${frameworkName}", |
70 |
| - "-output", |
71 |
| - tempUniversalBinaryLocation.path |
72 |
| - ) |
73 |
| - } |
74 |
| - val aFramework = targets[0].outputFile.path |
75 |
| - copy { |
76 |
| - from(aFramework) |
77 |
| - into(File(destinationDir, "$frameworkName.framework")) |
78 |
| - } |
79 |
| - // delete the old mono framework binary we copied here |
80 |
| - val binaryFinalLocation = File(destinationDir, "${frameworkName}.framework/Versions/A/$frameworkName") |
81 |
| - val binaryFinalSymlinkLocation = File(destinationDir, "${frameworkName}.framework/$frameworkName") |
82 |
| - delete(binaryFinalLocation) |
83 |
| - delete(binaryFinalSymlinkLocation) |
84 |
| - // copy new universal binary to binaryFinalSymlinkLocation |
85 |
| - copy { |
86 |
| - from(tempUniversalBinaryLocation) |
87 |
| - into(File(destinationDir, "$frameworkName.framework/Versions/A")) |
88 |
| - } |
89 |
| - delete(tempUniversalBinaryLocation) |
90 |
| - exec { |
91 |
| - //recreate the symlink normally to the binary normally in framework folder |
92 |
| - commandLine( |
93 |
| - "ln", |
94 |
| - "-s", |
95 |
| - binaryFinalLocation.toPath(), |
96 |
| - binaryFinalSymlinkLocation.toPath() |
97 |
| - ) |
98 |
| - } |
99 |
| - } |
| 49 | + if (targets.isNotEmpty()) { |
| 50 | + val buildType = if (targets[0].linkTask.name.contains("Release")) "release" else "debug" |
| 51 | + baseName = checkNotNull(targets.first().name.value) |
| 52 | + destinationDir = buildDir.resolve("bin/macosUniversal/${buildType}Framework") |
| 53 | + from(targets.mapNotNull { it.framework }) |
100 | 54 | }
|
101 | 55 | }
|
102 | 56 |
|
|
0 commit comments