Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow copying of resource files from targets #95

Merged
merged 1 commit into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/ProjectSpec/ProjectExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ extension PBXProductType {
}
}

public var isFramework: Bool {
return fileExtension == "framework"
}

public var isExtension: Bool {
return fileExtension == "appex"
}
Expand Down
17 changes: 10 additions & 7 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ public class PBXProjGenerator {

var dependencies: [String] = []
var targetFrameworkBuildFiles: [String] = []
var copyFiles: [String] = []
var copyFrameworksReferences: [String] = []
var copyResourcesReferences: [String] = []
var copyWatchReferences: [String] = []
var extensions: [String] = []

Expand Down Expand Up @@ -261,10 +262,12 @@ public class PBXProjGenerator {
if dependencyTarget.type.isExtension {
// embed app extension
extensions.append(embedFile.reference)
} else if dependencyTarget.type.isFramework {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd need a bit more check here since the extension is not the only one determining if the framework needs to be copied. Only the dynamic ones need to. You can use lipo for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I thought about that case, we actually have that case and I'm currently setting embed: False on it since we don't currently have a reference to the actual binary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also use file which might be easier than lipo for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was at least an improvement since that's now the only case we're not handling correctly after this and my other PRs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this could be the second iteration to make it more concrete 👍. I didn't know it was possible to get that info using file.

copyFrameworksReferences.append(embedFile.reference)
} else if dependencyTarget.type.isApp && dependencyTarget.platform == .watchOS {
copyWatchReferences.append(embedFile.reference)
} else {
copyFiles.append(embedFile.reference)
copyResourcesReferences.append(embedFile.reference)
}
}

Expand All @@ -283,7 +286,7 @@ public class PBXProjGenerator {
if embed {
let embedFile = PBXBuildFile(reference: generateUUID(PBXBuildFile.self, fileReference + target.name), fileRef: fileReference, settings: dependency.buildSettings)
addObject(embedFile)
copyFiles.append(embedFile.reference)
copyFrameworksReferences.append(embedFile.reference)
}
case .carthage:
if carthageFrameworksByPlatform[target.platform.carthageDirectoryName] == nil {
Expand All @@ -304,7 +307,7 @@ public class PBXProjGenerator {
if target.platform == .macOS && target.type.isApp {
let embedFile = PBXBuildFile(reference: generateUUID(PBXBuildFile.self, fileReference + target.name), fileRef: fileReference, settings: dependency.buildSettings)
addObject(embedFile)
copyFiles.append(embedFile.reference)
copyFrameworksReferences.append(embedFile.reference)
}
}
}
Expand Down Expand Up @@ -348,7 +351,7 @@ public class PBXProjGenerator {
addObject(sourcesBuildPhase)
buildPhases.append(sourcesBuildPhase.reference)

let resourcesBuildPhase = PBXResourcesBuildPhase(reference: generateUUID(PBXResourcesBuildPhase.self, target.name), files: getBuildFilesForPhase(.resources))
let resourcesBuildPhase = PBXResourcesBuildPhase(reference: generateUUID(PBXResourcesBuildPhase.self, target.name), files: getBuildFilesForPhase(.resources) + copyResourcesReferences)
addObject(resourcesBuildPhase)
buildPhases.append(resourcesBuildPhase.reference)

Expand Down Expand Up @@ -379,13 +382,13 @@ public class PBXProjGenerator {
buildPhases.append(copyFilesPhase.reference)
}

if !copyFiles.isEmpty {
if !copyFrameworksReferences.isEmpty {

let copyFilesPhase = PBXCopyFilesBuildPhase(
reference: generateUUID(PBXCopyFilesBuildPhase.self, "embed frameworks" + target.name),
dstPath: "",
dstSubfolderSpec: .frameworks,
files: copyFiles)
files: copyFrameworksReferences)

addObject(copyFilesPhase)
buildPhases.append(copyFilesPhase.reference)
Expand Down