|
17 | 17 | import Foundation
|
18 | 18 | import Utils
|
19 | 19 |
|
20 |
| -// TODO: Move TargetPlatform to Platforms.swift in subsequent PR |
21 |
| - |
22 |
| -/// The target platform that the framework is built for. |
23 |
| -enum TargetPlatform: CaseIterable { |
24 |
| - /// Binaries to target iOS devices. |
25 |
| - case iOSDevice |
26 |
| - /// Binaries to target iOS simulators. |
27 |
| - case iOSSimulator |
28 |
| - /// Binaries to target Catalyst. |
29 |
| - case catalyst |
30 |
| - /// Binaries to target macOS. |
31 |
| - case macOS |
32 |
| - /// Binaries to target tvOS. |
33 |
| - case tvOSDevice |
34 |
| - /// Binaries to target tvOS simulators. |
35 |
| - case tvOSSimulator |
36 |
| - |
37 |
| - /// Valid architectures to be built for the platform. |
38 |
| - var archs: [Architecture] { |
39 |
| - switch self { |
40 |
| - case .iOSDevice: return [.armv7, .arm64] |
41 |
| - // Include arm64 slices in the simulator for Apple silicon Macs. |
42 |
| - case .iOSSimulator: return [.i386, .x86_64, .arm64] |
43 |
| - // TODO: Evaluate x86_64h slice. Previous builds were limited to x86_64. |
44 |
| - case .catalyst: return [.x86_64, .arm64] |
45 |
| - case .macOS: return [.x86_64, .arm64] |
46 |
| - case .tvOSDevice: return [.arm64] |
47 |
| - case .tvOSSimulator: return [.x86_64, .arm64] |
48 |
| - } |
49 |
| - } |
50 |
| - |
51 |
| - /// Flag to determine if bitcode should be used for the target platform. |
52 |
| - var shouldEnableBitcode: Bool { |
53 |
| - switch self { |
54 |
| - // TODO: Do we need to include bitcode for Catalyst? We weren't before the latest arm64 changes. |
55 |
| - case .iOSDevice: return true |
56 |
| - case .macOS: return true |
57 |
| - case .tvOSDevice: return true |
58 |
| - default: return false |
59 |
| - } |
60 |
| - } |
61 |
| - |
62 |
| - /// Name of the SDK as used by `xcodebuild` for the target platforms. |
63 |
| - var sdkName: String { |
64 |
| - switch self { |
65 |
| - case .iOSDevice: return "iphoneos" |
66 |
| - case .iOSSimulator: return "iphonesimulator" |
67 |
| - case .catalyst: return "macosx" |
68 |
| - case .macOS: return "macosx" |
69 |
| - case .tvOSDevice: return "appletvos" |
70 |
| - case .tvOSSimulator: return "appletvsimulator" |
71 |
| - } |
72 |
| - } |
73 |
| - |
74 |
| - /// The build name. Distinguished from sdkName to disambiguate catalyst and macOS. |
75 |
| - var buildName: String { |
76 |
| - switch self { |
77 |
| - case .catalyst: return "catalyst" |
78 |
| - default: return sdkName |
79 |
| - } |
80 |
| - } |
81 |
| - |
82 |
| - /// Name of the directory that builds go into, autogenerated from Xcode. |
83 |
| - var buildDirName: String { |
84 |
| - switch self { |
85 |
| - case .iOSDevice: return "Release-iphoneos" |
86 |
| - case .iOSSimulator: return "Release-iphonesimulator" |
87 |
| - case .catalyst: return "Release-maccatalyst" |
88 |
| - case .macOS: return "Release" |
89 |
| - case .tvOSDevice: return "Release-appletvos" |
90 |
| - case .tvOSSimulator: return "Release-appletvsimulator" |
91 |
| - } |
92 |
| - } |
93 |
| -} |
94 |
| - |
95 |
| -/// Different architectures to build frameworks for. |
96 |
| -enum Architecture: String, CaseIterable { |
97 |
| - case arm64 |
98 |
| - case armv7 |
99 |
| - case i386 |
100 |
| - case x86_64 |
101 |
| - case x86_64h // x86_64h, Haswell, used for Mac Catalyst |
102 |
| -} |
103 |
| - |
104 | 20 | /// A structure to build a .framework in a given project directory.
|
105 | 21 | struct FrameworkBuilder {
|
106 | 22 | /// Platforms to be included in the built frameworks.
|
@@ -131,7 +47,43 @@ struct FrameworkBuilder {
|
131 | 47 |
|
132 | 48 | // MARK: - Public Functions
|
133 | 49 |
|
134 |
| - // TODO: The new public function `compileFrameworkAndResources` is left below for ease of review. |
| 50 | + /// Compiles the specified framework in a temporary directory and writes the build logs to file. |
| 51 | + /// This will compile all architectures for a single platform at a time. |
| 52 | + /// |
| 53 | + /// - Parameter framework: The name of the framework to be built. |
| 54 | + /// - Parameter logsOutputDir: The path to the directory to place build logs. |
| 55 | + /// - Parameter moduleMapContents: Module map contents for all frameworks in this pod. |
| 56 | + /// - Returns: A path to the newly compiled frameworks, the Carthage frameworks, and Resources. |
| 57 | + func compileFrameworkAndResources(withName framework: String, |
| 58 | + logsOutputDir: URL? = nil, |
| 59 | + podInfo: CocoaPodUtils.PodInfo) -> ([URL], URL?, URL?) { |
| 60 | + let fileManager = FileManager.default |
| 61 | + let outputDir = fileManager.temporaryDirectory(withName: "frameworks_being_built") |
| 62 | + let logsDir = logsOutputDir ?? fileManager.temporaryDirectory(withName: "build_logs") |
| 63 | + do { |
| 64 | + // Remove the compiled frameworks directory, this isn't the cache we're using. |
| 65 | + if fileManager.directoryExists(at: outputDir) { |
| 66 | + try fileManager.removeItem(at: outputDir) |
| 67 | + } |
| 68 | + |
| 69 | + try fileManager.createDirectory(at: outputDir, withIntermediateDirectories: true) |
| 70 | + |
| 71 | + // Create our logs directory if it doesn't exist. |
| 72 | + if !fileManager.directoryExists(at: logsDir) { |
| 73 | + try fileManager.createDirectory(at: logsDir, withIntermediateDirectories: true) |
| 74 | + } |
| 75 | + } catch { |
| 76 | + fatalError("Failure creating temporary directory while building \(framework): \(error)") |
| 77 | + } |
| 78 | + |
| 79 | + if dynamicFrameworks { |
| 80 | + return (buildDynamicFrameworks(withName: framework, logsDir: logsDir, outputDir: outputDir), |
| 81 | + nil, nil) |
| 82 | + } else { |
| 83 | + return buildStaticFrameworks(withName: framework, logsDir: logsDir, outputDir: outputDir, |
| 84 | + podInfo: podInfo) |
| 85 | + } |
| 86 | + } |
135 | 87 |
|
136 | 88 | // MARK: - Private Helpers
|
137 | 89 |
|
@@ -333,44 +285,6 @@ struct FrameworkBuilder {
|
333 | 285 | }
|
334 | 286 | }
|
335 | 287 |
|
336 |
| - /// Compiles the specified framework in a temporary directory and writes the build logs to file. |
337 |
| - /// This will compile all architectures for a single platform at a time. |
338 |
| - /// |
339 |
| - /// - Parameter framework: The name of the framework to be built. |
340 |
| - /// - Parameter logsOutputDir: The path to the directory to place build logs. |
341 |
| - /// - Parameter moduleMapContents: Module map contents for all frameworks in this pod. |
342 |
| - /// - Returns: A path to the newly compiled frameworks, the Carthage frameworks, and Resources. |
343 |
| - func compileFrameworkAndResources(withName framework: String, |
344 |
| - logsOutputDir: URL? = nil, |
345 |
| - podInfo: CocoaPodUtils.PodInfo) -> ([URL], URL?, URL?) { |
346 |
| - let fileManager = FileManager.default |
347 |
| - let outputDir = fileManager.temporaryDirectory(withName: "frameworks_being_built") |
348 |
| - let logsDir = logsOutputDir ?? fileManager.temporaryDirectory(withName: "build_logs") |
349 |
| - do { |
350 |
| - // Remove the compiled frameworks directory, this isn't the cache we're using. |
351 |
| - if fileManager.directoryExists(at: outputDir) { |
352 |
| - try fileManager.removeItem(at: outputDir) |
353 |
| - } |
354 |
| - |
355 |
| - try fileManager.createDirectory(at: outputDir, withIntermediateDirectories: true) |
356 |
| - |
357 |
| - // Create our logs directory if it doesn't exist. |
358 |
| - if !fileManager.directoryExists(at: logsDir) { |
359 |
| - try fileManager.createDirectory(at: logsDir, withIntermediateDirectories: true) |
360 |
| - } |
361 |
| - } catch { |
362 |
| - fatalError("Failure creating temporary directory while building \(framework): \(error)") |
363 |
| - } |
364 |
| - |
365 |
| - if dynamicFrameworks { |
366 |
| - return (buildDynamicFrameworks(withName: framework, logsDir: logsDir, outputDir: outputDir), |
367 |
| - nil, nil) |
368 |
| - } else { |
369 |
| - return buildStaticFrameworks(withName: framework, logsDir: logsDir, outputDir: outputDir, |
370 |
| - podInfo: podInfo) |
371 |
| - } |
372 |
| - } |
373 |
| - |
374 | 288 | /// Compiles the specified framework in a temporary directory and writes the build logs to file.
|
375 | 289 | /// This will compile all architectures and use the -create-xcframework command to create a modern
|
376 | 290 | /// "fat" framework.
|
|
0 commit comments