Skip to content

Commit 3c87d43

Browse files
committed
Make the Commands test suite pass
This depends on adding --version support to ArgumentParser
1 parent 4d45bb3 commit 3c87d43

File tree

9 files changed

+112
-143
lines changed

9 files changed

+112
-143
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let package = Package(
5656
),
5757
],
5858
dependencies: [
59-
.package(url: "https://github.com/apple/swift-argument-parser.git", .branch("master")),
59+
.package(url: "https://github.com/apple/swift-argument-parser.git", .branch("nate/version_flag")),
6060
],
6161
targets: [
6262
// The `PackageDescription` targets define the API which is available to

Sources/Commands/Options.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ public struct SwiftToolOptions: ParsableArguments {
9999
@Flag(name: .customLong("prefetching"), default: true, inversion: .prefixedEnableDisable)
100100
var shouldEnableResolverPrefetching: Bool
101101

102-
/// If print version option was passed.
103-
@Flag(name: .customLong("version"))
104-
var shouldPrintVersion: Bool
105-
106102
// FIXME: We need to allow -vv type options for this.
107103
/// The verbosity of informational output.
108104
@Flag(name: .shortAndLong, help: "Increase verbosity of informational output")
@@ -198,13 +194,6 @@ public struct SwiftToolOptions: ParsableArguments {
198194
/// The build system to use.
199195
@Option(default: .native)
200196
var buildSystem: BuildSystemKind
201-
202-
public mutating func validate() throws {
203-
if shouldPrintVersion {
204-
print(Versioning.currentVersion.completeDisplayString)
205-
throw ExitCode.success
206-
}
207-
}
208197

209198
public init() {}
210199
}

Sources/Commands/SwiftBuildTool.swift

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,6 @@ extension BuildSubset {
3131
}
3232

3333
struct BuildToolOptions: ParsableArguments {
34-
enum BuildToolMode {
35-
/// Build the package.
36-
case build
37-
38-
/// Print the binary output path.
39-
case binPath
40-
}
41-
42-
/// Returns the mode in which the build tool should run.
43-
func mode() throws -> BuildToolMode {
44-
if shouldPrintBinPath {
45-
return .binPath
46-
}
47-
// Get the build configuration or assume debug.
48-
return .build
49-
}
50-
5134
/// Returns the build subset specified with the options.
5235
func buildSubset(diagnostics: DiagnosticsEngine) -> BuildSubset? {
5336
var allSubsets: [BuildSubset] = []
@@ -95,29 +78,36 @@ struct BuildToolOptions: ParsableArguments {
9578
/// swift-build tool namespace
9679
public struct SwiftBuildTool: ParsableCommand {
9780
public static let configuration = CommandConfiguration(
98-
commandName: "build",
99-
abstract: "Build sources into binary products")
81+
commandName: "swift build",
82+
abstract: "Build sources into binary products",
83+
discussion: "SEE ALSO: swift run, swift package, swift test",
84+
version: Versioning.currentVersion.completeDisplayString,
85+
helpNames: [.short, .long, .customLong("help", withSingleDash: true)])
10086

10187
@OptionGroup()
10288
var options: BuildToolOptions
103-
89+
10490
public func run() throws {
105-
let swiftTool = SwiftTool(options: options.swiftOptions)
106-
107-
switch try options.mode() {
108-
case .build:
109-
#if os(Linux)
110-
// Emit warning if clang is older than version 3.6 on Linux.
111-
// See: <rdar://problem/28108951> SR-2299 Swift isn't using Gold by default on stock 14.04.
112-
checkClangVersion()
113-
#endif
114-
115-
guard let subset = options.buildSubset(diagnostics: swiftTool.diagnostics) else { return }
116-
let buildSystem = try swiftTool.createBuildSystem()
117-
try buildSystem.build(subset: subset)
91+
let swiftTool = try SwiftTool(options: options.swiftOptions)
11892

119-
case .binPath:
93+
if options.shouldPrintBinPath {
12094
try print(swiftTool.buildParameters().buildPath.description)
95+
return
96+
}
97+
98+
#if os(Linux)
99+
// Emit warning if clang is older than version 3.6 on Linux.
100+
// See: <rdar://problem/28108951> SR-2299 Swift isn't using Gold by default on stock 14.04.
101+
checkClangVersion()
102+
#endif
103+
104+
guard let subset = options.buildSubset(diagnostics: swiftTool.diagnostics)
105+
else { throw ExitCode.failure }
106+
let buildSystem = try swiftTool.createBuildSystem()
107+
do {
108+
try buildSystem.build(subset: subset)
109+
} catch _ as Diagnostics {
110+
throw ExitCode.failure
121111
}
122112
}
123113

0 commit comments

Comments
 (0)