-
Notifications
You must be signed in to change notification settings - Fork 823
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
Add directlyEmbedCarthageDependencies to Target #361
Changes from 5 commits
30d7195
8ebf27a
b18cd55
0ec3b1d
ba6f3d0
b1f8045
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -432,25 +432,28 @@ public class PBXProjGenerator { | |
var copyResourcesReferences: [String] = [] | ||
var copyWatchReferences: [String] = [] | ||
var extensions: [String] = [] | ||
var carthageFrameworksToEmbed: [String] = [] | ||
|
||
let targetDependencies = (target.transitivelyLinkDependencies ?? project.options.transitivelyLinkDependencies) ? | ||
getAllDependenciesPlusTransitiveNeedingEmbedding(target: target) : target.dependencies | ||
|
||
let directlyEmbedCarthage = target.directlyEmbedCarthageDependencies ?? !(target.platform.requiresSimulatorStripping && target.type.isApp) | ||
|
||
func getEmbedSettings(dependency: Dependency, codeSign: Bool) -> [String: Any] { | ||
var embedAttributes: [String] = [] | ||
if codeSign { | ||
embedAttributes.append("CodeSignOnCopy") | ||
} | ||
if dependency.removeHeaders { | ||
embedAttributes.append("RemoveHeadersOnCopy") | ||
} | ||
return ["ATTRIBUTES": embedAttributes] | ||
} | ||
|
||
for dependency in targetDependencies { | ||
|
||
let embed = dependency.embed ?? target.shouldEmbedDependencies | ||
|
||
func getEmbedSettings(codeSign: Bool) -> [String: Any] { | ||
var embedAttributes: [String] = [] | ||
if codeSign { | ||
embedAttributes.append("CodeSignOnCopy") | ||
} | ||
if dependency.removeHeaders { | ||
embedAttributes.append("RemoveHeadersOnCopy") | ||
} | ||
return ["ATTRIBUTES": embedAttributes] | ||
} | ||
|
||
switch dependency.type { | ||
case .target: | ||
let dependencyTargetName = dependency.reference | ||
|
@@ -485,7 +488,7 @@ public class PBXProjGenerator { | |
id: dependencyFileReference + target.name, | ||
PBXBuildFile( | ||
fileRef: dependencyFileReference, | ||
settings: getEmbedSettings(codeSign: dependency.codeSign ?? !dependencyTarget.type.isExecutable) | ||
settings: getEmbedSettings(dependency: dependency, codeSign: dependency.codeSign ?? !dependencyTarget.type.isExecutable) | ||
) | ||
) | ||
|
||
|
@@ -531,7 +534,7 @@ public class PBXProjGenerator { | |
if embed { | ||
let embedFile = createObject( | ||
id: fileReference + target.name, | ||
PBXBuildFile(fileRef: fileReference, settings: getEmbedSettings(codeSign: dependency.codeSign ?? true)) | ||
PBXBuildFile(fileRef: fileReference, settings: getEmbedSettings(dependency: dependency, codeSign: dependency.codeSign ?? true)) | ||
) | ||
copyFrameworksReferences.append(embedFile.reference) | ||
} | ||
|
@@ -554,12 +557,32 @@ public class PBXProjGenerator { | |
carthageFrameworksByPlatform[target.platform.carthageDirectoryName, default: []].insert(fileReference) | ||
|
||
targetFrameworkBuildFiles.append(buildFile.reference) | ||
if target.platform == .macOS && embed { | ||
|
||
// Embedding handled by iterating over `carthageDependencies` below | ||
} | ||
} | ||
|
||
for dependency in carthageDependencies { | ||
guard target.type != .staticLibrary else { break } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nits: I prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the target type is non dependant on the dependencies, could the if go outside this loop? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to merge after this |
||
|
||
let embed = dependency.embed ?? target.shouldEmbedDependencies | ||
|
||
var platformPath = Path(getCarthageBuildPath(platform: target.platform)) | ||
var frameworkPath = platformPath + dependency.reference | ||
if frameworkPath.extension == nil { | ||
frameworkPath = Path(frameworkPath.string + ".framework") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can always add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can list extension as part of a |
||
let fileReference = sourceGenerator.getFileReference(path: frameworkPath, inPath: platformPath) | ||
|
||
if embed { | ||
if directlyEmbedCarthage { | ||
let embedFile = createObject( | ||
id: fileReference + target.name, | ||
PBXBuildFile(fileRef: fileReference, settings: getEmbedSettings(codeSign: dependency.codeSign ?? true)) | ||
PBXBuildFile(fileRef: fileReference, settings: getEmbedSettings(dependency: dependency, codeSign: dependency.codeSign ?? true)) | ||
) | ||
copyFrameworksReferences.append(embedFile.reference) | ||
} else { | ||
carthageFrameworksToEmbed.append(dependency.reference) | ||
} | ||
} | ||
} | ||
|
@@ -652,15 +675,8 @@ public class PBXProjGenerator { | |
|
||
buildPhases.append(copyFilesPhase.reference) | ||
} | ||
|
||
let carthageFrameworksToEmbed = Array(Set( | ||
carthageDependencies | ||
.filter { $0.embed ?? target.shouldEmbedDependencies } | ||
.map { $0.reference } | ||
)) | ||
.sorted() | ||
|
||
if !carthageFrameworksToEmbed.isEmpty && target.platform != .macOS { | ||
|
||
if !carthageFrameworksToEmbed.isEmpty { | ||
|
||
let inputPaths = carthageFrameworksToEmbed | ||
.map { "$(SRCROOT)/\(carthageBuildPath)/\(target.platform)/\($0)\($0.contains(".") ? "" : ".framework")" } | ||
|
@@ -820,7 +836,7 @@ public class PBXProjGenerator { | |
func getAllCarthageDependencies(target: Target) -> [Dependency] { | ||
// this is used to resolve cyclical target dependencies | ||
var visitedTargets: Set<String> = [] | ||
var frameworks: [Dependency] = [] | ||
var frameworks: [String: Dependency] = [:] | ||
|
||
var queue: [Target] = [target] | ||
while !queue.isEmpty { | ||
|
@@ -830,9 +846,14 @@ public class PBXProjGenerator { | |
} | ||
|
||
for dependency in target.dependencies { | ||
// don't overwrite frameworks, to allow top level ones to rule | ||
if frameworks.contains(reference: dependency.reference) { | ||
continue | ||
} | ||
|
||
switch dependency.type { | ||
case .carthage: | ||
frameworks.append(dependency) | ||
frameworks[dependency.reference] = dependency | ||
case .target: | ||
if let target = project.getTarget(dependency.reference) { | ||
queue.append(target) | ||
|
@@ -845,7 +866,7 @@ public class PBXProjGenerator { | |
visitedTargets.update(with: target.name) | ||
} | ||
|
||
return frameworks | ||
return frameworks.sorted(by: { $0.key < $1.key }).map { $0.value } | ||
} | ||
|
||
func getAllDependenciesPlusTransitiveNeedingEmbedding(target topLevelTarget: Target) -> [Dependency] { | ||
|
@@ -901,6 +922,18 @@ extension Target { | |
} | ||
} | ||
|
||
extension Platform { | ||
/// - returns: `true` for platforms that the app store requires simulator slices to be stripped. | ||
public var requiresSimulatorStripping: Bool { | ||
switch self { | ||
case .iOS, .tvOS, .watchOS: | ||
return true | ||
case .macOS: | ||
return false | ||
} | ||
} | ||
} | ||
|
||
extension PBXFileElement { | ||
|
||
public func getSortOrder(groupSortPosition: SpecOptions.GroupSortPosition) -> Int { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type.isApp
actually includes tests as well. Is that on purpose?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Tests have an extension of
.xctests
.isApp
checks for.app
correct?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the getter, it includes test targets 👍
isApp
is used in other places. It's ok if you want to create new property and rename the usages to be more explicit about what they are checkingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I take all that back. I was thinking of
isExecutable