Skip to content

Commit 7589498

Browse files
author
Karim Alweheshy
committed
Show al transitive deps in Link Binary With Libraries build phase
1 parent 7d183c2 commit 7589498

File tree

12 files changed

+251
-10
lines changed

12 files changed

+251
-10
lines changed

tools/generators/files_and_groups/src/Generator/CreateBuildFileObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension Generator.CreateBuildFileObject {
4242
settings = #"settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; "#
4343
case .compileStub, .source:
4444
settings = ""
45-
case .product, .watchKitExtension:
45+
case .product, .watchKitExtension, .framework:
4646
// Handled in `CreateProductBuildFileObject` and
4747
// `CreateProductObject`
4848
preconditionFailure()

tools/generators/lib/PBXProj/src/BuildPhase.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public enum BuildPhase {
55
case sources
66
case copySwiftGeneratedHeader
77
case embedAppExtensions
8+
case linkBinaryWithLibraries
89

910
public var name: String {
1011
switch self {
@@ -16,6 +17,7 @@ Copy Bazel Outputs / Generate Bazel Dependencies (Index Build)
1617
case .sources: return "Sources"
1718
case .copySwiftGeneratedHeader: return "Copy Swift Generated Header"
1819
case .embedAppExtensions: return "Embed App Extensions"
20+
case .linkBinaryWithLibraries: return "Frameworks"
1921
}
2022
}
2123
}

tools/generators/lib/PBXProj/src/Identifiers.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ FF01000000000000000001\#(byteHexStrings[index]!) \#
8989
/// The product reference for a target.
9090
case product = "P"
9191

92+
/// The framework reference for a target in libraries to link build phase.
93+
case framework = "f"
94+
9295
/// A normal file referenced in a `BuildPhase.sources` build phase.
9396
case source = "0"
9497

@@ -186,6 +189,14 @@ FF01000000000000000001\#(byteHexStrings[index]!) \#
186189
return #"""
187190
\#(subIdentifier.shard)00\#(subIdentifier.hash)0000000000FF \#
188191
/* \#(subIdentifier.path.path) */
192+
"""#
193+
194+
case .framework:
195+
let basename = subIdentifier.path.path
196+
.split(separator: "/").last!
197+
return #"""
198+
\#(subIdentifier.shard)A8\#(subIdentifier.hash) \#
199+
/* \#(basename) in Frameworks */
189200
"""#
190201

191202
case .compileStub:
@@ -535,6 +546,7 @@ private extension Identifiers.BuildFiles.FileType {
535546
var buildPhase: BuildPhase {
536547
switch self {
537548
case .product: preconditionFailure() // product reference used as build file
549+
case .framework: return .linkBinaryWithLibraries
538550
case .source: return .sources
539551
case .nonArcSource: return .sources
540552
case .compileStub: return .sources
@@ -566,6 +578,7 @@ extension BuildPhase {
566578
case .sources: return "06"
567579
case .copySwiftGeneratedHeader: return "07"
568580
case .embedAppExtensions: return "08"
581+
case .linkBinaryWithLibraries: return "09"
569582
}
570583
}
571584
}

tools/generators/pbxnativetargets/src/Generator/CalculatePlatformVariantBuildSettings.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ extension Generator.CalculatePlatformVariantBuildSettings {
188188
key: "LIBRARY_SEARCH_PATHS",
189189
value: platformVariant.librarySearchPaths
190190
.map { $0.path.quoteIfNeeded }
191-
// TODO: See if we can not sort, or sort earlier
192191
.sorted()
193192
.joined(separator: " ")
194193
.pbxProjEscaped

tools/generators/pbxnativetargets/src/Generator/CalculatePlatformVariants.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extension Generator.CalculatePlatformVariants {
5959
) {
6060
var srcs: [[BazelPath]] = []
6161
var nonArcSrcs: [[BazelPath]] = []
62+
var librariesToLinkPaths: [[BazelPath]] = []
6263
var excludableFilesKeysWithValues: [(TargetID, Set<BazelPath>)] = []
6364
for id in ids {
6465
let targetArguments = try targetArguments.value(
@@ -68,6 +69,7 @@ extension Generator.CalculatePlatformVariants {
6869

6970
srcs.append(targetArguments.srcs)
7071
nonArcSrcs.append(targetArguments.nonArcSrcs)
72+
librariesToLinkPaths.append(targetArguments.librariesToLinkPaths)
7173

7274
excludableFilesKeysWithValues.append(
7375
(
@@ -142,7 +144,8 @@ extension Generator.CalculatePlatformVariants {
142144

143145
let consolidatedInputs = Target.ConsolidatedInputs(
144146
srcs: consolidatePaths(srcs),
145-
nonArcSrcs: consolidatePaths(nonArcSrcs)
147+
nonArcSrcs: consolidatePaths(nonArcSrcs),
148+
librariesToLinkPaths: consolidatePaths(librariesToLinkPaths)
146149
)
147150

148151
return (platformVariants, allConditionalFiles, consolidatedInputs)

tools/generators/pbxnativetargets/src/Generator/CreateBuildPhases.swift

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ extension Generator {
1313
CreateEmbedAppExtensionsBuildPhaseObject
1414
private let createProductBuildFileObject: CreateProductBuildFileObject
1515
private let createSourcesBuildPhaseObject: CreateSourcesBuildPhaseObject
16+
private let createLinkBinaryWithLibrariesBuildPhaseObject:
17+
CreateLinkBinaryWithLibrariesBuildPhaseObject
18+
private let createFrameworkObject: CreateFrameworkObject
19+
private let createFrameworkBuildFileObject: CreateFrameworkBuildFileObject
1620

1721
private let callable: Callable
1822

@@ -31,6 +35,10 @@ extension Generator {
3135
CreateEmbedAppExtensionsBuildPhaseObject,
3236
createProductBuildFileObject: CreateProductBuildFileObject,
3337
createSourcesBuildPhaseObject: CreateSourcesBuildPhaseObject,
38+
createLinkBinaryWithLibrariesBuildPhaseObject:
39+
CreateLinkBinaryWithLibrariesBuildPhaseObject,
40+
createFrameworkObject: CreateFrameworkObject,
41+
createFrameworkBuildFileObject: CreateFrameworkBuildFileObject,
3442
callable: @escaping Callable = Self.defaultCallable
3543
) {
3644
self.createBazelIntegrationBuildPhaseObject =
@@ -44,6 +52,9 @@ extension Generator {
4452
createEmbedAppExtensionsBuildPhaseObject
4553
self.createProductBuildFileObject = createProductBuildFileObject
4654
self.createSourcesBuildPhaseObject = createSourcesBuildPhaseObject
55+
self.createLinkBinaryWithLibrariesBuildPhaseObject = createLinkBinaryWithLibrariesBuildPhaseObject
56+
self.createFrameworkObject = createFrameworkObject
57+
self.createFrameworkBuildFileObject = createFrameworkBuildFileObject
4758

4859
self.callable = callable
4960
}
@@ -86,7 +97,10 @@ extension Generator {
8697
/*createEmbedAppExtensionsBuildPhaseObject:*/
8798
createEmbedAppExtensionsBuildPhaseObject,
8899
/*createProductBuildFileObject:*/ createProductBuildFileObject,
89-
/*createSourcesBuildPhaseObject:*/ createSourcesBuildPhaseObject
100+
/*createSourcesBuildPhaseObject:*/ createSourcesBuildPhaseObject,
101+
/*createLinkBinaryWithLibrariesBuildPhaseObject:*/ createLinkBinaryWithLibrariesBuildPhaseObject,
102+
/*createFrameworkObject:*/ createFrameworkObject,
103+
/*createFrameworkBuildFileObject:*/ createFrameworkBuildFileObject
90104
)
91105
}
92106
}
@@ -116,7 +130,11 @@ extension Generator.CreateBuildPhases {
116130
_ createEmbedAppExtensionsBuildPhaseObject:
117131
Generator.CreateEmbedAppExtensionsBuildPhaseObject,
118132
_ createProductBuildFileObject: Generator.CreateProductBuildFileObject,
119-
_ createSourcesBuildPhaseObject: Generator.CreateSourcesBuildPhaseObject
133+
_ createSourcesBuildPhaseObject: Generator.CreateSourcesBuildPhaseObject,
134+
_ createLinkBinaryWithLibrariesBuildPhaseObject:
135+
Generator.CreateLinkBinaryWithLibrariesBuildPhaseObject,
136+
_ createFrameworkObject: Generator.CreateFrameworkObject,
137+
_ createFrameworkBuildFileObject: Generator.CreateFrameworkBuildFileObject
120138
) -> (
121139
buildPhases: [Object],
122140
buildFileObjects: [Object],
@@ -144,7 +162,11 @@ extension Generator.CreateBuildPhases {
144162
createEmbedAppExtensionsBuildPhaseObject:
145163
Generator.CreateEmbedAppExtensionsBuildPhaseObject,
146164
createProductBuildFileObject: Generator.CreateProductBuildFileObject,
147-
createSourcesBuildPhaseObject: Generator.CreateSourcesBuildPhaseObject
165+
createSourcesBuildPhaseObject: Generator.CreateSourcesBuildPhaseObject,
166+
createLinkBinaryWithLibrariesBuildPhaseObject:
167+
Generator.CreateLinkBinaryWithLibrariesBuildPhaseObject,
168+
createFrameworkObject: Generator.CreateFrameworkObject,
169+
createFrameworkBuildFileObject: Generator.CreateFrameworkBuildFileObject
148170
) -> (
149171
buildPhases: [Object],
150172
buildFileObjects: [Object],
@@ -259,6 +281,45 @@ extension Generator.CreateBuildPhases {
259281
)
260282
}
261283

284+
let librariesToLinkSubIdentifiers = consolidatedInputs.librariesToLinkPaths.map { bazelPath in
285+
return (
286+
bazelPath,
287+
createBuildFileSubIdentifier(
288+
BazelPath(bazelPath.path.split(separator: "/").last.map(String.init)!),
289+
type: .framework,
290+
shard: shard
291+
),
292+
createBuildFileSubIdentifier(
293+
bazelPath,
294+
type: .framework,
295+
shard: shard
296+
)
297+
)
298+
}
299+
librariesToLinkSubIdentifiers
300+
.forEach { bazelPath, buildSubIdentifier, frameworkSubIdentifier in
301+
buildFileObjects.append(
302+
createFrameworkBuildFileObject(
303+
frameworkSubIdentifier: frameworkSubIdentifier,
304+
subIdentifier: buildSubIdentifier
305+
)
306+
)
307+
buildFileObjects.append(
308+
createFrameworkObject(
309+
frameworkPath: bazelPath,
310+
subIdentifier: frameworkSubIdentifier
311+
)
312+
)
313+
}
314+
buildPhases.append(
315+
createLinkBinaryWithLibrariesBuildPhaseObject(
316+
subIdentifier: identifier.subIdentifier,
317+
librariesToLinkIdentifiers: librariesToLinkSubIdentifiers
318+
.map { $0.1 }
319+
.map { Identifiers.BuildFiles.id(subIdentifier: $0) }
320+
)
321+
)
322+
262323
return (buildPhases, buildFileObjects, buildFileSubIdentifiers)
263324
}
264325
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import PBXProj
2+
3+
extension Generator {
4+
struct CreateFrameworkBuildFileObject {
5+
private let callable: Callable
6+
7+
/// - Parameters:
8+
/// - callable: The function that will be called in
9+
/// `callAsFunction()`.
10+
init(callable: @escaping Callable = Self.defaultCallable) {
11+
self.callable = callable
12+
}
13+
14+
/// Creates a `PBXBuildFile` element.
15+
func callAsFunction(
16+
frameworkSubIdentifier: Identifiers.BuildFiles.SubIdentifier,
17+
subIdentifier: Identifiers.BuildFiles.SubIdentifier
18+
) -> Object {
19+
return callable(
20+
/*frameworkSubIdentifier:*/ frameworkSubIdentifier,
21+
/*subIdentifier:*/ subIdentifier
22+
)
23+
}
24+
}
25+
}
26+
27+
// MARK: - CreateFrameworkBuildFileObject.Callable
28+
29+
extension Generator.CreateFrameworkBuildFileObject {
30+
typealias Callable = (
31+
_ frameworkSubIdentifier: Identifiers.BuildFiles.SubIdentifier,
32+
_ subIdentifier: Identifiers.BuildFiles.SubIdentifier
33+
) -> Object
34+
35+
static func defaultCallable(
36+
frameworkSubIdentifier: Identifiers.BuildFiles.SubIdentifier,
37+
subIdentifier: Identifiers.BuildFiles.SubIdentifier
38+
) -> Object {
39+
let fileRef = Identifiers.BuildFiles
40+
.id(subIdentifier: frameworkSubIdentifier)
41+
let content = #"""
42+
{isa = PBXBuildFile; fileRef = \#(fileRef); }
43+
"""#
44+
45+
return Object(
46+
identifier: Identifiers.BuildFiles.id(subIdentifier: subIdentifier),
47+
content: content
48+
)
49+
}
50+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import PBXProj
2+
3+
extension Generator {
4+
struct CreateFrameworkObject {
5+
private let callable: Callable
6+
private static var existingFrameworkPaths = [BazelPath]()
7+
8+
/// - Parameters:
9+
/// - callable: The function that will be called in
10+
/// `callAsFunction()`.
11+
init(callable: @escaping Callable = Self.defaultCallable) {
12+
self.callable = callable
13+
}
14+
15+
/// Creates a `PBXBuildFile` element.
16+
func callAsFunction(
17+
frameworkPath: BazelPath,
18+
subIdentifier: Identifiers.BuildFiles.SubIdentifier
19+
) -> Object {
20+
return callable(
21+
/*frameworkPath:*/ frameworkPath,
22+
/*subIdentifier:*/ subIdentifier
23+
)
24+
}
25+
}
26+
}
27+
28+
// MARK: - CreateProductObject.Callable
29+
30+
extension Generator.CreateFrameworkObject {
31+
typealias Callable = (
32+
_ frameworkPath: BazelPath,
33+
_ subIdentifier: Identifiers.BuildFiles.SubIdentifier
34+
) -> Object
35+
36+
static func defaultCallable(
37+
frameworkPath: BazelPath,
38+
subIdentifier: Identifiers.BuildFiles.SubIdentifier
39+
) -> Object {
40+
let content = #"""
41+
{isa = PBXFileReference; lastKnownFileType = archive.ar; name = "\#(frameworkPath.path.split(separator: "/").last!)"; path = "\#(frameworkPath.path)"; sourceTree = "<group>"; }
42+
"""#
43+
44+
return Object(
45+
identifier: Identifiers.BuildFiles.id(subIdentifier: subIdentifier),
46+
content: content
47+
)
48+
}
49+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import PBXProj
2+
3+
extension Generator {
4+
struct CreateLinkBinaryWithLibrariesBuildPhaseObject {
5+
private let callable: Callable
6+
7+
/// - Parameters:
8+
/// - callable: The function that will be called in
9+
/// `callAsFunction()`.
10+
init(callable: @escaping Callable = Self.defaultCallable) {
11+
self.callable = callable
12+
}
13+
14+
/// Creates the `PBXSourcesBuildPhase` object for a target.
15+
func callAsFunction(
16+
subIdentifier: Identifiers.Targets.SubIdentifier,
17+
librariesToLinkIdentifiers: [String]
18+
) -> Object {
19+
return callable(
20+
/*subIdentifier:*/ subIdentifier,
21+
/*buildFileIdentifiers:*/ librariesToLinkIdentifiers
22+
)
23+
}
24+
}
25+
}
26+
27+
// MARK: - CreateSourcesBuildPhaseObject.Callable
28+
29+
extension Generator.CreateLinkBinaryWithLibrariesBuildPhaseObject {
30+
typealias Callable = (
31+
_ subIdentifier: Identifiers.Targets.SubIdentifier,
32+
_ librariesToLinkIdentifiers: [String]
33+
) -> Object
34+
35+
static func defaultCallable(
36+
subIdentifier: Identifiers.Targets.SubIdentifier,
37+
librariesToLinkIdentifiers: [String]
38+
) -> Object {
39+
// The tabs for indenting are intentional
40+
let content = #"""
41+
{
42+
isa = PBXFrameworksBuildPhase;
43+
buildActionMask = 2147483647;
44+
files = (
45+
\#(librariesToLinkIdentifiers.map { "\t\t\t\t\($0),\n" }.joined())\#
46+
);
47+
runOnlyForDeploymentPostprocessing = 0;
48+
}
49+
"""#
50+
51+
return Object(
52+
identifier: Identifiers.Targets.buildPhase(
53+
.linkBinaryWithLibraries,
54+
subIdentifier: subIdentifier
55+
),
56+
content: content
57+
)
58+
}
59+
}

tools/generators/pbxnativetargets/src/Generator/Environment.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ extension Generator.Environment {
3232
createProductBuildFileObject:
3333
Generator.CreateProductBuildFileObject(),
3434
createSourcesBuildPhaseObject:
35-
Generator.CreateSourcesBuildPhaseObject()
35+
Generator.CreateSourcesBuildPhaseObject(),
36+
createLinkBinaryWithLibrariesBuildPhaseObject:
37+
Generator.CreateLinkBinaryWithLibrariesBuildPhaseObject(),
38+
createFrameworkObject: Generator.CreateFrameworkObject(),
39+
createFrameworkBuildFileObject:
40+
Generator.CreateFrameworkBuildFileObject()
3641
),
3742
createProductObject: Generator.CreateProductObject(),
3843
createTargetObject: Generator.CreateTargetObject(),

0 commit comments

Comments
 (0)