Skip to content

Commit

Permalink
Merge pull request #21 from evandcoleman/release/0.1.22
Browse files Browse the repository at this point in the history
copy pod resources
  • Loading branch information
github-actions[bot] authored Sep 20, 2021
2 parents e82f053 + 1af2667 commit 625a164
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Sources/Scipio/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension Command {
.init(
commandName: "Scipio",
abstract: "A program to pre-build and cache Swift packages",
version: "0.1.21",
version: "0.1.22",
subcommands: [
Command.Build.self,
Command.Upload.self,
Expand Down
28 changes: 24 additions & 4 deletions Sources/ScipioKit/Dependency Processors/CocoaPodProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public final class CocoaPodProcessor: DependencyProcessor {
return Future.try {
let path = Config.current.cachePath + Config.current.name

_ = try self.writePodfile(in: path)
let (_, projectPath) = try self.writePodfile(in: path)

return try self.installPods(in: path)
return try self.installPods(in: path, projectPath: projectPath)
}
.eraseToAnyPublisher()
}
Expand Down Expand Up @@ -83,6 +83,18 @@ public final class CocoaPodProcessor: DependencyProcessor {

if !targetPath.exists {
try path.copy(targetPath)

if !resolvedDependency.resourceBundles.isEmpty {
let resourcesPath = targetPath + "Resources"

if !resourcesPath.exists {
try resourcesPath.mkdir()
}

for bundlePath in resolvedDependency.resourceBundles {
try bundlePath.copy(resourcesPath + bundlePath.lastComponent)
}
}
}

return targetPath
Expand Down Expand Up @@ -149,7 +161,7 @@ project '\(projectPath.string)'
return (podfilePath, projectPath)
}

private func installPods(in path: Path) throws -> [CocoaPodDescriptor] {
private func installPods(in path: Path, projectPath: Path) throws -> [CocoaPodDescriptor] {
let podCommandPath = try which("pod")

do {
Expand All @@ -166,6 +178,7 @@ project '\(projectPath.string)'
let manifestPath = path + "Pods/Manifest.lock"
let podsProjectPath = sandboxPath + "Pods.xcodeproj"
let project = try XcodeProj(path: podsProjectPath)
let parentProject = try XcodeProj(path: projectPath)
let lockFile: String = try manifestPath.read()

return try dependencies.map { dependency in
Expand All @@ -192,12 +205,18 @@ project '\(projectPath.string)'
return path
}
}
let resourceBundles = vendoredFrameworks.isEmpty ? [] : parentProject.resourceBundles(
for: "\(dependency.name)-\(options.platforms[0].rawValue)",
podsRoot: sandboxPath,
notIn: projectProducts
)

return CocoaPodDescriptor(
name: dependency.name,
resolvedVersions: versions,
productNames: filteredProductNames,
vendoredFrameworks: vendoredFrameworks
vendoredFrameworks: vendoredFrameworks,
resourceBundles: resourceBundles
)
}
}
Expand All @@ -208,6 +227,7 @@ public struct CocoaPodDescriptor: DependencyProducts {
public let resolvedVersions: [String: String]
public let productNames: [String]?
public let vendoredFrameworks: [Path]
public let resourceBundles: [Path]

public func version(for productName: String) -> String {
return resolvedVersions[productName]!
Expand Down
50 changes: 50 additions & 0 deletions Sources/ScipioKit/Extensions/XcodeProj+Products.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ extension XcodeProj {
.filter { !$0.name.isEmpty }
.uniqued()
}

func resourceBundles(for targetName: String, podsRoot: Path, notIn notInProjectProducts: [ProjectProduct]) -> [Path] {
return pbxproj
.targets(named: targetName)
.flatMap { $0.resourceBundles(podsRoot: podsRoot, notIn: notInProjectProducts) }
.uniqued()
}
}

extension PBXTarget {
Expand Down Expand Up @@ -79,4 +86,47 @@ extension PBXTarget {

return names
}

func resourceBundles(podsRoot: Path, notIn notInProjectProducts: [ProjectProduct]) -> [Path] {
var paths: [Path] = []

let resourceBundlePaths = buildPhases
.flatMap { $0.inputFileListPaths ?? [] }
.flatMap { path -> [Path] in
let fixedPath = path
.replacingOccurrences(of: "${PODS_ROOT}/", with: "")
.replacingOccurrences(of: "$PODS_ROOT/", with: "")
.replacingOccurrences(of: "${CONFIGURATION}", with: "Release")
.replacingOccurrences(of: "$CONFIGURATION", with: "Release")
let contents = (try? (podsRoot + Path(fixedPath)).read()) ?? ""

return contents
.components(separatedBy: "\n")
.compactMap { pathString -> Path? in
let path = podsRoot + Path(
pathString
.replacingOccurrences(of: "${PODS_ROOT}/", with: "")
.replacingOccurrences(of: "$PODS_ROOT/", with: "")
.replacingOccurrences(of: "${CONFIGURATION}", with: "Release")
.replacingOccurrences(of: "$CONFIGURATION", with: "Release")
)

return path.extension == "bundle" ? path : nil
}
.filter { path in
return !notInProjectProducts
.contains { path.components.contains("\($0.name).xcframework") }
}
}

paths <<< resourceBundlePaths

for dependency in dependencies {
if let target = dependency.target {
paths <<< target.resourceBundles(podsRoot: podsRoot, notIn: notInProjectProducts)
}
}

return paths
}
}

0 comments on commit 625a164

Please sign in to comment.