Skip to content

Commit 2df8acd

Browse files
authored
Merge pull request #468 from apple/master
Bring Swift 5.1 branch up-to-date with master
2 parents 46f1ee0 + 875705e commit 2df8acd

File tree

4 files changed

+213
-45
lines changed

4 files changed

+213
-45
lines changed

Package.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
// swift-tools-version:4.2.0
1+
// swift-tools-version:5.0
22

33
// This file defines Swift package manager support for llbuild. See:
44
// https://github.com/apple/swift-package-manager/tree/master/Documentation
5-
//
6-
// You can build using:
7-
//
8-
// ```shell
9-
// swift build -Xlinker -lsqlite3 -Xlinker -lncurses
10-
// ```
115

126
import PackageDescription
137

@@ -61,7 +55,8 @@ let package = Package(
6155
.target(
6256
name: "llbuildCore",
6357
dependencies: ["llbuildBasic"],
64-
path: "lib/Core"
58+
path: "lib/Core",
59+
linkerSettings: [.linkedLibrary("sqlite3")]
6560
),
6661
.target(
6762
name: "llbuildBuildSystem",
@@ -122,7 +117,8 @@ let package = Package(
122117
.target(
123118
name: "llvmSupport",
124119
dependencies: ["llvmDemangle"],
125-
path: "lib/llvm/Support"
120+
path: "lib/llvm/Support",
121+
linkerSettings: [.linkedLibrary("ncurses")]
126122
),
127123
],
128124
cxxLanguageStandard: .cxx14

[email protected]

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// swift-tools-version:4.2.0
2+
3+
// This file defines Swift package manager support for llbuild. See:
4+
// https://github.com/apple/swift-package-manager/tree/master/Documentation
5+
6+
import PackageDescription
7+
8+
let package = Package(
9+
name: "llbuild",
10+
products: [
11+
.library(
12+
name: "libllbuild",
13+
targets: ["libllbuild"]),
14+
.library(
15+
name: "llbuildSwift",
16+
targets: ["llbuildSwift"]),
17+
],
18+
targets: [
19+
/// The llbuild testing tool.
20+
.target(
21+
name: "llbuild",
22+
dependencies: ["llbuildCommands"],
23+
path: "products/llbuild"
24+
),
25+
26+
/// The custom build tool used by the Swift package manager.
27+
.target(
28+
name: "swift-build-tool",
29+
dependencies: ["llbuildBuildSystem"],
30+
path: "products/swift-build-tool"
31+
),
32+
33+
/// The custom build tool used by the Swift package manager.
34+
.target(
35+
name: "llbuildSwift",
36+
dependencies: ["libllbuild"],
37+
path: "products/llbuildSwift",
38+
exclude: ["llbuild.swift"]
39+
),
40+
41+
/// The public llbuild API.
42+
.target(
43+
name: "libllbuild",
44+
dependencies: ["llbuildCore", "llbuildBuildSystem"],
45+
path: "products/libllbuild"
46+
),
47+
48+
// MARK: Components
49+
50+
.target(
51+
name: "llbuildBasic",
52+
dependencies: ["llvmSupport"],
53+
path: "lib/Basic"
54+
),
55+
.target(
56+
name: "llbuildCore",
57+
dependencies: ["llbuildBasic"],
58+
path: "lib/Core"
59+
),
60+
.target(
61+
name: "llbuildBuildSystem",
62+
dependencies: ["llbuildCore"],
63+
path: "lib/BuildSystem"
64+
),
65+
.target(
66+
name: "llbuildNinja",
67+
dependencies: ["llbuildBasic"],
68+
path: "lib/Ninja"
69+
),
70+
.target(
71+
name: "llbuildCommands",
72+
dependencies: ["llbuildCore", "llbuildBuildSystem", "llbuildNinja"],
73+
path: "lib/Commands"
74+
),
75+
76+
// MARK: Test Targets
77+
78+
.target(
79+
name: "llbuildBasicTests",
80+
dependencies: ["llbuildBasic", "gtest"],
81+
path: "unittests/Basic"),
82+
.target(
83+
name: "llbuildCoreTests",
84+
dependencies: ["llbuildCore", "gtest"],
85+
path: "unittests/Core"),
86+
.target(
87+
name: "llbuildBuildSystemTests",
88+
dependencies: ["llbuildBuildSystem", "gtest"],
89+
path: "unittests/BuildSystem"),
90+
.target(
91+
name: "llbuildNinjaTests",
92+
dependencies: ["llbuildNinja", "gtest"],
93+
path: "unittests/Ninja"),
94+
95+
// MARK: GoogleTest
96+
97+
.target(
98+
name: "gtest",
99+
path: "utils/unittest/googletest/src",
100+
exclude: [
101+
"gtest-death-test.cc",
102+
"gtest-filepath.cc",
103+
"gtest-port.cc",
104+
"gtest-printers.cc",
105+
"gtest-test-part.cc",
106+
"gtest-typed-test.cc",
107+
"gtest.cc",
108+
]),
109+
110+
// MARK: Ingested LLVM code.
111+
.target(
112+
name: "llvmDemangle",
113+
path: "lib/llvm/Demangle"
114+
),
115+
116+
.target(
117+
name: "llvmSupport",
118+
dependencies: ["llvmDemangle"],
119+
path: "lib/llvm/Support"
120+
),
121+
],
122+
cxxLanguageStandard: .cxx14
123+
)

products/llbuildSwift/BuildSystemBindings.swift

Lines changed: 83 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private final class ToolWrapper {
7373
_delegate.execute_command = { return BuildSystem.toCommandWrapper($0!).executeCommand($1!, $2!, $3!, $4!) }
7474

7575
// Create the low-level command.
76-
wrapper._command = Command(llb_buildsystem_external_command_create(name, _delegate))
76+
wrapper._command = Command(handle: llb_buildsystem_external_command_create(name, _delegate))
7777

7878
return wrapper._command.handle
7979
}
@@ -99,7 +99,7 @@ private final class CommandWrapper {
9999

100100
init(command: ExternalCommand) {
101101
self.command = command
102-
self._command = Command(nil)
102+
self._command = Command(handle: nil)
103103
}
104104

105105
func getSignature(_: OpaquePointer, _ data: UnsafeMutablePointer<llb_data_t>) {
@@ -199,42 +199,91 @@ extension SchedulerAlgorithm {
199199

200200
/// Handle for a command as invoked by the low-level BuildSystem.
201201
public struct Command: Hashable, CustomStringConvertible, CustomDebugStringConvertible {
202-
fileprivate let handle: OpaquePointer?
202+
private struct Values: Hashable {
203+
let name: String
204+
let shouldShowStatus: Bool
205+
let description: String
206+
let verboseDescription: String
207+
}
203208

204-
fileprivate init(_ handle: OpaquePointer?) {
205-
self.handle = handle
209+
private enum Representation: Hashable {
210+
case handle(OpaquePointer?)
211+
case values(Values)
212+
}
213+
214+
private let representation: Representation
215+
216+
fileprivate init(handle: OpaquePointer?) {
217+
self.representation = .handle(handle)
218+
}
219+
220+
/// Creates a dummy `Command` with specific values for testing purposes.
221+
public init(name: String, shouldShowStatus: Bool, description: String, verboseDescription: String) {
222+
self.representation = .values(Values(
223+
name: name,
224+
shouldShowStatus: shouldShowStatus,
225+
description: description,
226+
verboseDescription: verboseDescription
227+
))
228+
}
229+
230+
fileprivate var handle: OpaquePointer? {
231+
switch representation {
232+
case .handle(let handle):
233+
return handle
234+
case .values:
235+
return nil
236+
}
206237
}
207238

208239
/// The command name.
209240
//
210241
// FIXME: We shouldn't need to expose this to use for mapping purposes, we should be able to use something more efficient.
211242
public var name: String {
212-
var data = llb_data_t()
213-
withUnsafeMutablePointer(to: &data) { (ptr: UnsafeMutablePointer<llb_data_t>) in
214-
llb_buildsystem_command_get_name(handle, ptr)
243+
switch representation {
244+
case .handle(let handle):
245+
var data = llb_data_t()
246+
withUnsafeMutablePointer(to: &data) { (ptr: UnsafeMutablePointer<llb_data_t>) in
247+
llb_buildsystem_command_get_name(handle, ptr)
248+
}
249+
return stringFromData(data)
250+
case .values(let values):
251+
return values.name
215252
}
216-
return stringFromData(data)
217253
}
218254

219255
/// Whether the default status reporting shows status for the command.
220256
public var shouldShowStatus: Bool {
221-
return llb_buildsystem_command_should_show_status(handle)
257+
switch representation {
258+
case .handle(let handle):
259+
return llb_buildsystem_command_should_show_status(handle)
260+
case .values(let values):
261+
return values.shouldShowStatus
262+
}
222263
}
223264

224265
/// The description provided by the command.
225266
public var description: String {
226-
let name = llb_buildsystem_command_get_description(handle)!
227-
defer { free(name) }
228-
229-
return String(cString: name)
267+
switch representation {
268+
case .handle(let handle):
269+
let name = llb_buildsystem_command_get_description(handle)!
270+
defer { free(name) }
271+
return String(cString: name)
272+
case .values(let values):
273+
return values.description
274+
}
230275
}
231276

232277
/// The verbose description provided by the command.
233278
public var verboseDescription: String {
234-
let name = llb_buildsystem_command_get_verbose_description(handle)!
235-
defer { free(name) }
236-
237-
return String(cString: name)
279+
switch representation {
280+
case .handle(let handle):
281+
let name = llb_buildsystem_command_get_verbose_description(handle)!
282+
defer { free(name) }
283+
return String(cString: name)
284+
case .values(let values):
285+
return values.verboseDescription
286+
}
238287
}
239288

240289
/// The debug description provides the verbose description.
@@ -243,11 +292,11 @@ public struct Command: Hashable, CustomStringConvertible, CustomDebugStringConve
243292
}
244293

245294
public func hash(into hasher: inout Hasher) {
246-
hasher.combine(handle!)
295+
hasher.combine(representation)
247296
}
248297

249298
public static func ==(lhs: Command, rhs: Command) -> Bool {
250-
return lhs.handle == rhs.handle
299+
return lhs.representation == rhs.representation
251300
}
252301
}
253302

@@ -571,28 +620,28 @@ public final class BuildSystem {
571620
_delegate.lookup_tool = { return BuildSystem.toSystem($0!).lookupTool($1!) }
572621
_delegate.had_command_failure = { BuildSystem.toSystem($0!).hadCommandFailure() }
573622
_delegate.handle_diagnostic = { BuildSystem.toSystem($0!).handleDiagnostic($1, String(cString: $2!), Int($3), Int($4), String(cString: $5!)) }
574-
_delegate.command_status_changed = { BuildSystem.toSystem($0!).commandStatusChanged(Command($1), $2) }
575-
_delegate.command_preparing = { BuildSystem.toSystem($0!).commandPreparing(Command($1)) }
576-
_delegate.command_started = { BuildSystem.toSystem($0!).commandStarted(Command($1)) }
577-
_delegate.should_command_start = { BuildSystem.toSystem($0!).shouldCommandStart(Command($1)) }
578-
_delegate.command_finished = { BuildSystem.toSystem($0!).commandFinished(Command($1), $2) }
579-
_delegate.command_had_error = { BuildSystem.toSystem($0!).commandHadError(Command($1), $2!) }
580-
_delegate.command_had_note = { BuildSystem.toSystem($0!).commandHadNote(Command($1), $2!) }
581-
_delegate.command_had_warning = { BuildSystem.toSystem($0!).commandHadWarning(Command($1), $2!) }
623+
_delegate.command_status_changed = { BuildSystem.toSystem($0!).commandStatusChanged(Command(handle: $1), $2) }
624+
_delegate.command_preparing = { BuildSystem.toSystem($0!).commandPreparing(Command(handle: $1)) }
625+
_delegate.command_started = { BuildSystem.toSystem($0!).commandStarted(Command(handle: $1)) }
626+
_delegate.should_command_start = { BuildSystem.toSystem($0!).shouldCommandStart(Command(handle: $1)) }
627+
_delegate.command_finished = { BuildSystem.toSystem($0!).commandFinished(Command(handle: $1), $2) }
628+
_delegate.command_had_error = { BuildSystem.toSystem($0!).commandHadError(Command(handle: $1), $2!) }
629+
_delegate.command_had_note = { BuildSystem.toSystem($0!).commandHadNote(Command(handle: $1), $2!) }
630+
_delegate.command_had_warning = { BuildSystem.toSystem($0!).commandHadWarning(Command(handle: $1), $2!) }
582631
_delegate.command_cannot_build_output_due_to_missing_inputs = {
583632
let inputsPtr = $3!
584633
let inputs = (0..<Int($4)).map { BuildKey(key: inputsPtr[$0]) }
585-
BuildSystem.toSystem($0!).commandCannotBuildOutputDueToMissingInputs(Command($1), BuildKey(key: $2!.pointee), inputs)
634+
BuildSystem.toSystem($0!).commandCannotBuildOutputDueToMissingInputs(Command(handle: $1), BuildKey(key: $2!.pointee), inputs)
586635
}
587636
_delegate.cannot_build_node_due_to_multiple_producers = {
588637
let commandsPtr = $2!
589-
let commands = (0..<Int($3)).map { Command(commandsPtr[$0]) }
638+
let commands = (0..<Int($3)).map { Command(handle: commandsPtr[$0]) }
590639
BuildSystem.toSystem($0!).cannotBuildNodeDueToMultipleProducers(BuildKey(key: $1!.pointee), commands)
591640
}
592-
_delegate.command_process_started = { BuildSystem.toSystem($0!).commandProcessStarted(Command($1), ProcessHandle($2!)) }
593-
_delegate.command_process_had_error = { BuildSystem.toSystem($0!).commandProcessHadError(Command($1), ProcessHandle($2!), $3!) }
594-
_delegate.command_process_had_output = { BuildSystem.toSystem($0!).commandProcessHadOutput(Command($1), ProcessHandle($2!), $3!) }
595-
_delegate.command_process_finished = { BuildSystem.toSystem($0!).commandProcessFinished(Command($1), ProcessHandle($2!), CommandExtendedResult($3!)) }
641+
_delegate.command_process_started = { BuildSystem.toSystem($0!).commandProcessStarted(Command(handle: $1), ProcessHandle($2!)) }
642+
_delegate.command_process_had_error = { BuildSystem.toSystem($0!).commandProcessHadError(Command(handle: $1), ProcessHandle($2!), $3!) }
643+
_delegate.command_process_had_output = { BuildSystem.toSystem($0!).commandProcessHadOutput(Command(handle: $1), ProcessHandle($2!), $3!) }
644+
_delegate.command_process_finished = { BuildSystem.toSystem($0!).commandProcessFinished(Command(handle: $1), ProcessHandle($2!), CommandExtendedResult($3!)) }
596645
_delegate.cycle_detected = {
597646
var rules = [BuildKey]()
598647
UnsafeBufferPointer(start: $1, count: Int($2)).forEach {

products/llbuildSwift/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ else()
1313
if(FOUNDATION_BUILD_DIR)
1414
list(APPEND additional_args
1515
-L${FOUNDATION_BUILD_DIR}
16-
-Fsystem
17-
${FOUNDATION_BUILD_DIR}/CoreFoundation-prefix/System/Library/Frameworks
16+
-Fsystem ${FOUNDATION_BUILD_DIR}
17+
-Fsystem ${FOUNDATION_BUILD_DIR}/CoreFoundation-prefix/System/Library/Frameworks
1818
-I${FOUNDATION_BUILD_DIR}/swift)
1919
endif()
2020
if(LIBDISPATCH_BUILD_DIR)

0 commit comments

Comments
 (0)