Skip to content

Commit 09ce6f1

Browse files
committed
[Release Tooling] Add resources, if any, to bundle within xcframework platform slices
1 parent d9bcd14 commit 09ce6f1

File tree

2 files changed

+25
-43
lines changed

2 files changed

+25
-43
lines changed

ReleaseTooling/Sources/ZipBuilder/FrameworkBuilder.swift

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ struct FrameworkBuilder {
4949
/// - Parameter logsOutputDir: The path to the directory to place build logs.
5050
/// - Parameter setCarthage: Set Carthage diagnostics flag in build.
5151
/// - Parameter moduleMapContents: Module map contents for all frameworks in this pod.
52-
/// - Returns: A path to the newly compiled frameworks, and Resources.
52+
/// - Returns: A path to the newly compiled frameworks.
5353
func compileFrameworkAndResources(withName framework: String,
5454
logsOutputDir: URL? = nil,
5555
setCarthage: Bool,
56-
podInfo: CocoaPodUtils.PodInfo) -> ([URL], URL?) {
56+
podInfo: CocoaPodUtils.PodInfo) -> [URL] {
5757
let fileManager = FileManager.default
5858
let outputDir = fileManager.temporaryDirectory(withName: "frameworks_being_built")
5959
let logsDir = logsOutputDir ?? fileManager.temporaryDirectory(withName: "build_logs")
@@ -74,8 +74,7 @@ struct FrameworkBuilder {
7474
}
7575

7676
if dynamicFrameworks {
77-
return (buildDynamicFrameworks(withName: framework, logsDir: logsDir, outputDir: outputDir),
78-
nil)
77+
return buildDynamicFrameworks(withName: framework, logsDir: logsDir, outputDir: outputDir)
7978
} else {
8079
return buildStaticFrameworks(
8180
withName: framework,
@@ -330,7 +329,7 @@ struct FrameworkBuilder {
330329
logsDir: URL,
331330
outputDir: URL,
332331
setCarthage: Bool,
333-
podInfo: CocoaPodUtils.PodInfo) -> ([URL], URL) {
332+
podInfo: CocoaPodUtils.PodInfo) -> [URL] {
334333
// Build every architecture and save the locations in an array to be assembled.
335334
let slicedFrameworks = buildFrameworksForAllPlatforms(withName: framework, logsDir: logsDir,
336335
setCarthage: setCarthage)
@@ -387,15 +386,6 @@ struct FrameworkBuilder {
387386

388387
// TODO: copy PrivateHeaders directory as well if it exists. SDWebImage is an example pod.
389388

390-
// Move all the Resources into .bundle directories in the destination Resources dir. The
391-
// Resources live are contained within the folder structure:
392-
// `projectDir/arch/Release-platform/FrameworkName`.
393-
// The Resources are stored at the top-level of the .framework or .xcframework directory.
394-
// For Firebase distributions, they are propagated one level higher in the final distribution.
395-
let resourceContents = projectDir.appendingPathComponents([anyPlatform.buildName,
396-
anyPlatform.buildDirName,
397-
framework])
398-
399389
guard let moduleMapContentsTemplate = podInfo.moduleMapContents else {
400390
fatalError("Module map contents missing for framework \(frameworkName)")
401391
}
@@ -421,7 +411,7 @@ struct FrameworkBuilder {
421411
""")
422412
}
423413
}
424-
return (frameworks, resourceContents)
414+
return frameworks
425415
}
426416

427417
/// Parses CocoaPods config files or uses the passed in `moduleMapContents` to write the
@@ -669,6 +659,17 @@ struct FrameworkBuilder {
669659
fatalError("Could not create framework directory needed to build \(framework): \(error)")
670660
}
671661

662+
// Copy resource bundles (if any)
663+
try? fileManager.contentsOfDirectory(
664+
at: frameworkPath.deletingLastPathComponent(),
665+
includingPropertiesForKeys: nil
666+
)
667+
.filter { $0.pathExtension == "bundle" }
668+
.forEach { try! fileManager.copyItem(
669+
at: $0,
670+
to: platformFrameworkDir.appendingPathComponent($0.lastPathComponent)
671+
) }
672+
672673
// Copy the binary to the right location.
673674
let binaryName = frameworkPath.lastPathComponent.replacingOccurrences(of: ".framework",
674675
with: "")
@@ -695,11 +696,9 @@ struct FrameworkBuilder {
695696
/// - Parameter withName: The framework name.
696697
/// - Parameter frameworks: The grouped frameworks.
697698
/// - Parameter xcframeworksDir: Location at which to build the xcframework.
698-
/// - Parameter resourceContents: Location of the resources for this xcframework.
699699
static func makeXCFramework(withName name: String,
700700
frameworks: [URL],
701-
xcframeworksDir: URL,
702-
resourceContents: URL?) -> URL {
701+
xcframeworksDir: URL) -> URL {
703702
let xcframework = xcframeworksDir
704703
.appendingPathComponent(frameworkBuildName(name) + ".xcframework")
705704

@@ -724,16 +723,6 @@ struct FrameworkBuilder {
724723
case .success:
725724
print("XCFramework for \(name) built successfully at \(xcframework).")
726725
}
727-
// xcframework resources are packaged at top of xcframework.
728-
if let resourceContents = resourceContents {
729-
let resourceDir = xcframework.appendingPathComponent("Resources")
730-
do {
731-
try ResourcesManager.moveAllBundles(inDirectory: resourceContents, to: resourceDir)
732-
} catch {
733-
fatalError("Could not move bundles into Resources directory while building \(name): " +
734-
"\(error)")
735-
}
736-
}
737726
return xcframework
738727
}
739728
}

ReleaseTooling/Sources/ZipBuilder/ZipBuilder.swift

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,12 @@ struct ZipBuilder {
176176
var carthageGoogleUtilitiesFrameworks: [URL] = []
177177
var podsBuilt: [String: CocoaPodUtils.PodInfo] = [:]
178178
var xcframeworks: [String: [URL]] = [:]
179-
var resources: [String: URL] = [:]
180179

181180
for platform in platforms {
182181
let projectDir = FileManager.default.temporaryDirectory(withName: "project-" + platform.name)
183182
CocoaPodUtils.podInstallPrepare(inProjectDir: projectDir, templateDir: paths.templateDir)
184183

185184
let platformPods = podsToInstall.filter { $0.platforms.contains(platform.name) }
186-
187185
CocoaPodUtils.installPods(platformPods,
188186
inDir: projectDir,
189187
platform: platform,
@@ -228,24 +226,21 @@ struct ZipBuilder {
228226
let builder = FrameworkBuilder(projectDir: projectDir,
229227
targetPlatforms: platform.platformTargets,
230228
dynamicFrameworks: dynamicFrameworks)
231-
let (frameworks, resourceContents) =
229+
let frameworks =
232230
builder.compileFrameworkAndResources(withName: podName,
233231
logsOutputDir: paths.logsOutputDir,
234232
setCarthage: false,
235233
podInfo: podInfo)
236234
groupedFrameworks[podName] = (groupedFrameworks[podName] ?? []) + frameworks
237235

238236
if includeCarthage, podName == "GoogleUtilities" {
239-
let (cdFrameworks, _) = builder.compileFrameworkAndResources(withName: podName,
240-
logsOutputDir: paths
241-
.logsOutputDir,
242-
setCarthage: true,
243-
podInfo: podInfo)
237+
let cdFrameworks = builder.compileFrameworkAndResources(withName: podName,
238+
logsOutputDir: paths
239+
.logsOutputDir,
240+
setCarthage: true,
241+
podInfo: podInfo)
244242
carthageGoogleUtilitiesFrameworks += cdFrameworks
245243
}
246-
if resourceContents != nil {
247-
resources[podName] = resourceContents
248-
}
249244
} else if podsBuilt[podName] == nil {
250245
// Binary pods need to be collected once, since the platforms should already be merged.
251246
let binaryFrameworks = collectBinaryFrameworks(fromPod: podName, podInfo: podInfo)
@@ -274,8 +269,7 @@ struct ZipBuilder {
274269
let name = groupedFramework.key
275270
let xcframework = FrameworkBuilder.makeXCFramework(withName: name,
276271
frameworks: groupedFramework.value,
277-
xcframeworksDir: xcframeworksDir,
278-
resourceContents: resources[name])
272+
xcframeworksDir: xcframeworksDir)
279273
xcframeworks[name] = [xcframework]
280274
}
281275
for (framework, paths) in xcframeworks {
@@ -296,8 +290,7 @@ struct ZipBuilder {
296290
let carthageGoogleUtilitiesXcframework = FrameworkBuilder.makeXCFramework(
297291
withName: "GoogleUtilities",
298292
frameworks: carthageGoogleUtilitiesFrameworks,
299-
xcframeworksDir: xcframeworksCarthageDir,
300-
resourceContents: nil
293+
xcframeworksDir: xcframeworksCarthageDir
301294
)
302295
return (podsBuilt, xcframeworks, carthageGoogleUtilitiesXcframework)
303296
}

0 commit comments

Comments
 (0)