Skip to content

Commit 0d24059

Browse files
authored
File reorg after #7212 (#7217)
1 parent 2f28cdf commit 0d24059

File tree

3 files changed

+136
-123
lines changed

3 files changed

+136
-123
lines changed

ReleaseTooling/Sources/ZipBuilder/FrameworkBuilder.swift

Lines changed: 37 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -17,90 +17,6 @@
1717
import Foundation
1818
import Utils
1919

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-
10420
/// A structure to build a .framework in a given project directory.
10521
struct FrameworkBuilder {
10622
/// Platforms to be included in the built frameworks.
@@ -131,7 +47,43 @@ struct FrameworkBuilder {
13147

13248
// MARK: - Public Functions
13349

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+
}
13587

13688
// MARK: - Private Helpers
13789

@@ -333,44 +285,6 @@ struct FrameworkBuilder {
333285
}
334286
}
335287

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-
374288
/// Compiles the specified framework in a temporary directory and writes the build logs to file.
375289
/// This will compile all architectures and use the -create-xcframework command to create a modern
376290
/// "fat" framework.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import Foundation
18+
19+
/// The target platform that the framework is built for.
20+
enum TargetPlatform: CaseIterable {
21+
/// Binaries to target iOS devices.
22+
case iOSDevice
23+
/// Binaries to target iOS simulators.
24+
case iOSSimulator
25+
/// Binaries to target Catalyst.
26+
case catalyst
27+
/// Binaries to target macOS.
28+
case macOS
29+
/// Binaries to target tvOS.
30+
case tvOSDevice
31+
/// Binaries to target tvOS simulators.
32+
case tvOSSimulator
33+
34+
/// Valid architectures to be built for the platform.
35+
var archs: [Architecture] {
36+
switch self {
37+
case .iOSDevice: return [.armv7, .arm64]
38+
// Include arm64 slices in the simulator for Apple silicon Macs.
39+
case .iOSSimulator: return [.i386, .x86_64, .arm64]
40+
// TODO: Evaluate x86_64h slice. Previous builds were limited to x86_64.
41+
case .catalyst: return [.x86_64, .arm64]
42+
case .macOS: return [.x86_64, .arm64]
43+
case .tvOSDevice: return [.arm64]
44+
case .tvOSSimulator: return [.x86_64, .arm64]
45+
}
46+
}
47+
48+
/// Flag to determine if bitcode should be used for the target platform.
49+
var shouldEnableBitcode: Bool {
50+
switch self {
51+
// TODO: Do we need to include bitcode for Catalyst? We weren't before the latest arm64 changes.
52+
case .iOSDevice: return true
53+
case .macOS: return true
54+
case .tvOSDevice: return true
55+
default: return false
56+
}
57+
}
58+
59+
/// Name of the SDK as used by `xcodebuild` for the target platforms.
60+
var sdkName: String {
61+
switch self {
62+
case .iOSDevice: return "iphoneos"
63+
case .iOSSimulator: return "iphonesimulator"
64+
case .catalyst: return "macosx"
65+
case .macOS: return "macosx"
66+
case .tvOSDevice: return "appletvos"
67+
case .tvOSSimulator: return "appletvsimulator"
68+
}
69+
}
70+
71+
/// The build name. Distinguished from sdkName to disambiguate catalyst and macOS.
72+
var buildName: String {
73+
switch self {
74+
case .catalyst: return "catalyst"
75+
default: return sdkName
76+
}
77+
}
78+
79+
/// Name of the directory that builds go into, autogenerated from Xcode.
80+
var buildDirName: String {
81+
switch self {
82+
case .iOSDevice: return "Release-iphoneos"
83+
case .iOSSimulator: return "Release-iphonesimulator"
84+
case .catalyst: return "Release-maccatalyst"
85+
case .macOS: return "Release"
86+
case .tvOSDevice: return "Release-appletvos"
87+
case .tvOSSimulator: return "Release-appletvsimulator"
88+
}
89+
}
90+
}
91+
92+
/// Different architectures to build frameworks for.
93+
enum Architecture: String, CaseIterable {
94+
case arm64
95+
case armv7
96+
case i386
97+
case x86_64
98+
case x86_64h // x86_64h, Haswell, used for Mac Catalyst
99+
}

0 commit comments

Comments
 (0)