diff --git a/ReleaseTooling/Sources/ZipBuilder/FrameworkBuilder.swift b/ReleaseTooling/Sources/ZipBuilder/FrameworkBuilder.swift index 8f6f8f2fbbe..25ac3c7dfe7 100755 --- a/ReleaseTooling/Sources/ZipBuilder/FrameworkBuilder.swift +++ b/ReleaseTooling/Sources/ZipBuilder/FrameworkBuilder.swift @@ -49,11 +49,11 @@ struct FrameworkBuilder { /// - Parameter logsOutputDir: The path to the directory to place build logs. /// - Parameter setCarthage: Set Carthage diagnostics flag in build. /// - Parameter moduleMapContents: Module map contents for all frameworks in this pod. - /// - Returns: A path to the newly compiled frameworks, and Resources. + /// - Returns: A path to the newly compiled frameworks. func compileFrameworkAndResources(withName framework: String, logsOutputDir: URL? = nil, setCarthage: Bool, - podInfo: CocoaPodUtils.PodInfo) -> ([URL], URL?) { + podInfo: CocoaPodUtils.PodInfo) -> [URL] { let fileManager = FileManager.default let outputDir = fileManager.temporaryDirectory(withName: "frameworks_being_built") let logsDir = logsOutputDir ?? fileManager.temporaryDirectory(withName: "build_logs") @@ -74,8 +74,7 @@ struct FrameworkBuilder { } if dynamicFrameworks { - return (buildDynamicFrameworks(withName: framework, logsDir: logsDir, outputDir: outputDir), - nil) + return buildDynamicFrameworks(withName: framework, logsDir: logsDir, outputDir: outputDir) } else { return buildStaticFrameworks( withName: framework, @@ -330,7 +329,7 @@ struct FrameworkBuilder { logsDir: URL, outputDir: URL, setCarthage: Bool, - podInfo: CocoaPodUtils.PodInfo) -> ([URL], URL) { + podInfo: CocoaPodUtils.PodInfo) -> [URL] { // Build every architecture and save the locations in an array to be assembled. let slicedFrameworks = buildFrameworksForAllPlatforms(withName: framework, logsDir: logsDir, setCarthage: setCarthage) @@ -383,15 +382,6 @@ struct FrameworkBuilder { // TODO: copy PrivateHeaders directory as well if it exists. SDWebImage is an example pod. - // Move all the Resources into .bundle directories in the destination Resources dir. The - // Resources live are contained within the folder structure: - // `projectDir/arch/Release-platform/FrameworkName`. - // The Resources are stored at the top-level of the .framework or .xcframework directory. - // For Firebase distributions, they are propagated one level higher in the final distribution. - let resourceContents = projectDir.appendingPathComponents([anyPlatform.buildName, - anyPlatform.buildDirName, - framework]) - guard let moduleMapContentsTemplate = podInfo.moduleMapContents else { fatalError("Module map contents missing for framework \(frameworkName)") } @@ -417,7 +407,7 @@ struct FrameworkBuilder { """) } } - return (frameworks, resourceContents) + return frameworks } /// Parses CocoaPods config files or uses the passed in `moduleMapContents` to write the @@ -656,6 +646,17 @@ struct FrameworkBuilder { fatalError("Could not create framework directory needed to build \(framework): \(error)") } + // Copy resource bundles (if any) + try? fileManager.contentsOfDirectory( + at: frameworkPath.deletingLastPathComponent(), + includingPropertiesForKeys: nil + ) + .filter { $0.pathExtension == "bundle" } + .forEach { try! fileManager.copyItem( + at: $0, + to: platformFrameworkDir.appendingPathComponent($0.lastPathComponent) + ) } + // Copy the binary to the right location. let binaryName = frameworkPath.lastPathComponent.replacingOccurrences(of: ".framework", with: "") @@ -682,11 +683,9 @@ struct FrameworkBuilder { /// - Parameter withName: The framework name. /// - Parameter frameworks: The grouped frameworks. /// - Parameter xcframeworksDir: Location at which to build the xcframework. - /// - Parameter resourceContents: Location of the resources for this xcframework. static func makeXCFramework(withName name: String, frameworks: [URL], - xcframeworksDir: URL, - resourceContents: URL?) -> URL { + xcframeworksDir: URL) -> URL { let xcframework = xcframeworksDir .appendingPathComponent(frameworkBuildName(name) + ".xcframework") @@ -711,16 +710,6 @@ struct FrameworkBuilder { case .success: print("XCFramework for \(name) built successfully at \(xcframework).") } - // xcframework resources are packaged at top of xcframework. - if let resourceContents = resourceContents { - let resourceDir = xcframework.appendingPathComponent("Resources") - do { - try ResourcesManager.moveAllBundles(inDirectory: resourceContents, to: resourceDir) - } catch { - fatalError("Could not move bundles into Resources directory while building \(name): " + - "\(error)") - } - } return xcframework } } diff --git a/ReleaseTooling/Sources/ZipBuilder/ZipBuilder.swift b/ReleaseTooling/Sources/ZipBuilder/ZipBuilder.swift index aeca4a52dc5..aa3bd0e6535 100644 --- a/ReleaseTooling/Sources/ZipBuilder/ZipBuilder.swift +++ b/ReleaseTooling/Sources/ZipBuilder/ZipBuilder.swift @@ -176,14 +176,12 @@ struct ZipBuilder { var carthageGoogleUtilitiesFrameworks: [URL] = [] var podsBuilt: [String: CocoaPodUtils.PodInfo] = [:] var xcframeworks: [String: [URL]] = [:] - var resources: [String: URL] = [:] for platform in platforms { let projectDir = FileManager.default.temporaryDirectory(withName: "project-" + platform.name) CocoaPodUtils.podInstallPrepare(inProjectDir: projectDir, templateDir: paths.templateDir) let platformPods = podsToInstall.filter { $0.platforms.contains(platform.name) } - CocoaPodUtils.installPods(platformPods, inDir: projectDir, platform: platform, @@ -228,7 +226,7 @@ struct ZipBuilder { let builder = FrameworkBuilder(projectDir: projectDir, targetPlatforms: platform.platformTargets, dynamicFrameworks: dynamicFrameworks) - let (frameworks, resourceContents) = + let frameworks = builder.compileFrameworkAndResources(withName: podName, logsOutputDir: paths.logsOutputDir, setCarthage: false, @@ -236,16 +234,13 @@ struct ZipBuilder { groupedFrameworks[podName] = (groupedFrameworks[podName] ?? []) + frameworks if includeCarthage, podName == "GoogleUtilities" { - let (cdFrameworks, _) = builder.compileFrameworkAndResources(withName: podName, - logsOutputDir: paths - .logsOutputDir, - setCarthage: true, - podInfo: podInfo) + let cdFrameworks = builder.compileFrameworkAndResources(withName: podName, + logsOutputDir: paths + .logsOutputDir, + setCarthage: true, + podInfo: podInfo) carthageGoogleUtilitiesFrameworks += cdFrameworks } - if resourceContents != nil { - resources[podName] = resourceContents - } } else if podsBuilt[podName] == nil { // Binary pods need to be collected once, since the platforms should already be merged. let binaryFrameworks = collectBinaryFrameworks(fromPod: podName, podInfo: podInfo) @@ -274,8 +269,7 @@ struct ZipBuilder { let name = groupedFramework.key let xcframework = FrameworkBuilder.makeXCFramework(withName: name, frameworks: groupedFramework.value, - xcframeworksDir: xcframeworksDir, - resourceContents: resources[name]) + xcframeworksDir: xcframeworksDir) xcframeworks[name] = [xcframework] } for (framework, paths) in xcframeworks { @@ -296,8 +290,7 @@ struct ZipBuilder { let carthageGoogleUtilitiesXcframework = FrameworkBuilder.makeXCFramework( withName: "GoogleUtilities", frameworks: carthageGoogleUtilitiesFrameworks, - xcframeworksDir: xcframeworksCarthageDir, - resourceContents: nil + xcframeworksDir: xcframeworksCarthageDir ) return (podsBuilt, xcframeworks, carthageGoogleUtilitiesXcframework) }