forked from swiftlang/swift-package-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLLBuildManifestBuilder+Product.swift
More file actions
170 lines (152 loc) · 6.84 KB
/
Copy pathLLBuildManifestBuilder+Product.swift
File metadata and controls
170 lines (152 loc) · 6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2015-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import struct Basics.AbsolutePath
import struct Basics.InternalError
import struct LLBuildManifest.Node
import struct SPMBuildCore.BuildParameters
import struct PackageGraph.ResolvedProduct
extension LLBuildManifestBuilder {
func createProductCommand(_ buildProduct: ProductBuildDescription) throws {
let cmdName = try buildProduct.commandName
// Add dependency on Info.plist generation on Darwin platforms.
let testInputs: [AbsolutePath]
if buildProduct.product.type == .test
&& buildProduct.buildParameters.triple.isDarwin()
&& buildProduct.buildParameters.testingParameters.experimentalTestOutput {
let testBundleInfoPlistPath = try buildProduct.binaryPath.parentDirectory.parentDirectory.appending(component: "Info.plist")
testInputs = [testBundleInfoPlistPath]
self.manifest.addWriteInfoPlistCommand(
principalClass: "\(buildProduct.product.targets[buildProduct.product.targets.startIndex].c99name).SwiftPMXCTestObserver",
outputPath: testBundleInfoPlistPath
)
} else {
testInputs = []
}
// Create a phony node to represent the entire target.
let targetName = try buildProduct.llbuildTargetName
let output: Node = .virtual(targetName)
let finalProductNode: Node
switch buildProduct.product.type {
case .library(.static):
finalProductNode = try .file(buildProduct.binaryPath)
try self.manifest.addShellCmd(
name: cmdName,
description: "Archiving \(buildProduct.binaryPath.prettyPath())",
inputs: (buildProduct.objects + [buildProduct.linkFileListPath]).map(Node.file),
outputs: [finalProductNode],
arguments: try buildProduct.archiveArguments()
)
default:
let inputs = try buildProduct.objects
+ buildProduct.dylibs.map { try $0.binaryPath }
+ [buildProduct.linkFileListPath]
+ testInputs
let shouldCodeSign: Bool
let linkedBinaryNode: Node
let linkedBinaryPath = try buildProduct.binaryPath
if case .executable = buildProduct.product.type,
buildProduct.buildParameters.triple.isMacOSX,
buildProduct.buildParameters.debuggingParameters.shouldEnableDebuggingEntitlement {
shouldCodeSign = true
linkedBinaryNode = try .file(buildProduct.binaryPath, isMutated: true)
} else {
shouldCodeSign = false
linkedBinaryNode = try .file(buildProduct.binaryPath)
}
try self.manifest.addShellCmd(
name: cmdName,
description: "Linking \(buildProduct.binaryPath.prettyPath())",
inputs: inputs.map(Node.file),
outputs: [linkedBinaryNode],
arguments: try buildProduct.linkArguments()
)
if shouldCodeSign {
let basename = try buildProduct.binaryPath.basename
let plistPath = try buildProduct.binaryPath.parentDirectory
.appending(component: "\(basename)-entitlement.plist")
self.manifest.addEntitlementPlistCommand(
entitlement: "com.apple.security.get-task-allow",
outputPath: plistPath
)
let cmdName = try buildProduct.commandName
let codeSigningOutput = Node.virtual(targetName + "-CodeSigning")
try self.manifest.addShellCmd(
name: "\(cmdName)-entitlements",
description: "Applying debug entitlements to \(buildProduct.binaryPath.prettyPath())",
inputs: [linkedBinaryNode, .file(plistPath)],
outputs: [codeSigningOutput],
arguments: buildProduct.codeSigningArguments(plistPath: plistPath, binaryPath: linkedBinaryPath)
)
finalProductNode = codeSigningOutput
} else {
finalProductNode = linkedBinaryNode
}
}
self.manifest.addNode(output, toTarget: targetName)
self.manifest.addPhonyCmd(
name: output.name,
inputs: [finalProductNode],
outputs: [output]
)
if self.plan.graph.reachableProducts.contains(id: buildProduct.product.id) {
if buildProduct.product.type != .test {
self.addNode(output, toTarget: .main)
}
self.addNode(output, toTarget: .test)
}
self.manifest.addWriteLinkFileListCommand(
objects: Array(buildProduct.objects),
linkFileListPath: buildProduct.linkFileListPath
)
}
}
extension ProductBuildDescription {
package var llbuildTargetName: String {
get throws {
try self.product.getLLBuildTargetName(buildParameters: self.buildParameters)
}
}
package var commandName: String {
get throws {
try "C.\(self.llbuildTargetName)\(self.buildParameters.suffix)"
}
}
}
extension ResolvedProduct {
public func getLLBuildTargetName(buildParameters: BuildParameters) throws -> String {
let triple = buildParameters.triple.tripleString
let config = buildParameters.buildConfig
let suffix = buildParameters.suffix
let potentialExecutableTargetName = "\(name)-\(triple)-\(config)\(suffix).exe"
let potentialLibraryTargetName = "\(name)-\(triple)-\(config)\(suffix).dylib"
switch type {
case .library(.dynamic):
return potentialLibraryTargetName
case .test:
return "\(name)-\(triple)-\(config)\(suffix).test"
case .library(.static):
return "\(name)-\(triple)-\(config)\(suffix).a"
case .library(.automatic):
throw InternalError("automatic library not supported")
case .executable, .snippet:
return potentialExecutableTargetName
case .macro:
#if BUILD_MACROS_AS_DYLIBS
return potentialLibraryTargetName
#else
return potentialExecutableTargetName
#endif
case .plugin:
throw InternalError("unexpectedly asked for the llbuild target name of a plugin product")
}
}
}