Skip to content

Commit 4d45bb3

Browse files
committed
Resolve remaining compilation issues
1 parent 53d7c7a commit 4d45bb3

File tree

8 files changed

+245
-288
lines changed

8 files changed

+245
-288
lines changed

Sources/Commands/Completions+bash.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import Foundation
1212
import TSCBasic
1313
import TSCUtility
1414

15-
let listDependenciesCommand = "swift package \(PackageMode.completionTool.rawValue) \(PackageToolOptions.CompletionToolMode.listDependencies.rawValue)"
16-
let listExecutablesCommand = "swift package \(PackageMode.completionTool.rawValue) \(PackageToolOptions.CompletionToolMode.listExecutables.rawValue)"
15+
//let listDependenciesCommand = "swift package \(PackageMode.completionTool.rawValue) \(PackageToolOptions.CompletionToolMode.listDependencies.rawValue)"
16+
//let listExecutablesCommand = "swift package \(PackageMode.completionTool.rawValue) \(PackageToolOptions.CompletionToolMode.listExecutables.rawValue)"
1717

1818
/// Template for Bash completion script.
1919
///
@@ -79,21 +79,20 @@ func bash_template(on stream: OutputByteStream) {
7979
esac
8080
}
8181
82-
_swift_dependency() {
83-
COMPREPLY=( $(compgen -W "$(\(listDependenciesCommand))" -- $cur) )
84-
}
85-
86-
_swift_executable() {
87-
COMPREPLY=( $(compgen -W "$(\(listExecutablesCommand))" -- $cur) )
88-
}
89-
90-
9182
"""
9283

93-
SwiftBuildTool(args: []).parser.generateCompletionScript(for: .bash, on: stream)
94-
SwiftRunTool(args: []).parser.generateCompletionScript(for: .bash, on: stream)
95-
SwiftPackageTool(args: []).parser.generateCompletionScript(for: .bash, on: stream)
96-
SwiftTestTool(args: []).parser.generateCompletionScript(for: .bash, on: stream)
84+
// _swift_dependency() {
85+
// COMPREPLY=( $(compgen -W "$(\(listDependenciesCommand))" -- $cur) )
86+
// }
87+
//
88+
// _swift_executable() {
89+
// COMPREPLY=( $(compgen -W "$(\(listExecutablesCommand))" -- $cur) )
90+
// }
91+
92+
// SwiftBuildTool(args: []).parser.generateCompletionScript(for: .bash, on: stream)
93+
// SwiftRunTool(args: []).parser.generateCompletionScript(for: .bash, on: stream)
94+
// SwiftPackageTool(args: []).parser.generateCompletionScript(for: .bash, on: stream)
95+
// SwiftTestTool(args: []).parser.generateCompletionScript(for: .bash, on: stream)
9796

9897
// Forward to swift compiler completion, if defined.
9998
stream <<< """

Sources/Commands/Completions+zsh.swift

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,25 @@ func zsh_template(on stream: OutputByteStream) {
6262
esac
6363
}
6464
65-
_swift_dependency() {
66-
local dependencies
67-
dependencies=( $(\(listDependenciesCommand)) )
68-
_describe '' dependencies
69-
}
70-
71-
_swift_executable() {
72-
local executables
73-
executables=( $(\(listExecutablesCommand)) )
74-
_describe '' executables
75-
}
76-
7765
7866
"""
7967

80-
81-
SwiftBuildTool(args: []).parser.generateCompletionScript(for: .zsh, on: stream)
82-
SwiftRunTool(args: []).parser.generateCompletionScript(for: .zsh, on: stream)
83-
SwiftPackageTool(args: []).parser.generateCompletionScript(for: .zsh, on: stream)
84-
SwiftTestTool(args: []).parser.generateCompletionScript(for: .zsh, on: stream)
68+
// _swift_dependency() {
69+
// local dependencies
70+
// dependencies=( $(\(listDependenciesCommand)) )
71+
// _describe '' dependencies
72+
// }
73+
//
74+
// _swift_executable() {
75+
// local executables
76+
// executables=( $(\(listExecutablesCommand)) )
77+
// _describe '' executables
78+
// }
79+
//
80+
// SwiftBuildTool(args: []).parser.generateCompletionScript(for: .zsh, on: stream)
81+
// SwiftRunTool(args: []).parser.generateCompletionScript(for: .zsh, on: stream)
82+
// SwiftPackageTool(args: []).parser.generateCompletionScript(for: .zsh, on: stream)
83+
// SwiftTestTool(args: []).parser.generateCompletionScript(for: .zsh, on: stream)
8584

8685
// Figure out how to forward to swift compiler's bash completion.
8786
stream <<< """

Sources/Commands/Options.swift

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import PackageModel
1515
import SPMBuildCore
1616
import Build
1717

18-
public struct BuildFlagsGroup: ParsableArguments {
18+
struct BuildFlagsGroup: ParsableArguments {
1919
@Option(name: .customLong("Xcc", withSingleDash: true),
2020
help: "Pass flag through to all C compiler invocations")
2121
var cCompilerFlags: [String]
@@ -44,7 +44,7 @@ public struct BuildFlagsGroup: ParsableArguments {
4444
xlinker: linkerFlags)
4545
}
4646

47-
public init() {}
47+
init() {}
4848
}
4949

5050
extension BuildConfiguration: ExpressibleByArgument {
@@ -53,154 +53,158 @@ extension BuildConfiguration: ExpressibleByArgument {
5353
}
5454
}
5555

56-
public enum BuildSystemKind: String, ExpressibleByArgument {
56+
enum BuildSystemKind: String, ExpressibleByArgument {
5757
case native
5858
case xcode
5959
}
6060

6161
public struct SwiftToolOptions: ParsableArguments {
6262
@OptionGroup()
63-
public var buildFlagsGroup: BuildFlagsGroup
63+
var buildFlagsGroup: BuildFlagsGroup
6464

6565
/// Custom arguments to pass to C compiler, swift compiler and the linker.
66-
public var buildFlags: BuildFlags {
66+
var buildFlags: BuildFlags {
6767
buildFlagsGroup.buildFlags
6868
}
6969

70+
var xcbuildFlags: [String] {
71+
buildFlagsGroup.xcbuildFlags
72+
}
73+
7074
/// Build configuration.
7175
@Option(name: .shortAndLong, default: .debug, help: "Build with configuration")
72-
public var configuration: BuildConfiguration
76+
var configuration: BuildConfiguration
7377

7478
/// The custom build directory, if provided.
7579
@Option(help: "Specify build/cache directory",
7680
transform: { try PathArgument(argument: $0).path })
77-
public var buildPath: AbsolutePath?
81+
var buildPath: AbsolutePath?
7882

7983
/// The custom working directory that the tool should operate in (deprecated).
8084
@Option(name: [.long, .customShort("C")],
8185
transform: { try PathArgument(argument: $0).path })
82-
public var chdir: AbsolutePath?
86+
var chdir: AbsolutePath?
8387

8488
/// The custom working directory that the tool should operate in.
8589
@Option(help: "Change working directory before any other operation",
8690
transform: { try PathArgument(argument: $0).path })
87-
public var packagePath: AbsolutePath?
91+
var packagePath: AbsolutePath?
8892

8993
/// The path to the file containing multiroot package data. This is currently Xcode's workspace file.
9094
@Option(name: .customLong("multiroot-data-file"),
9195
transform: { try PathArgument(argument: $0).path })
92-
public var multirootPackageDataFile: AbsolutePath?
96+
var multirootPackageDataFile: AbsolutePath?
9397

9498
/// Enable prefetching in resolver which will kick off parallel git cloning.
9599
@Flag(name: .customLong("prefetching"), default: true, inversion: .prefixedEnableDisable)
96-
public var shouldEnableResolverPrefetching: Bool
100+
var shouldEnableResolverPrefetching: Bool
97101

98102
/// If print version option was passed.
99103
@Flag(name: .customLong("version"))
100-
public var shouldPrintVersion: Bool
104+
var shouldPrintVersion: Bool
101105

102106
// FIXME: We need to allow -vv type options for this.
103107
/// The verbosity of informational output.
104108
@Flag(name: .shortAndLong, help: "Increase verbosity of informational output")
105-
public var verbose: Bool
109+
var verbose: Bool
106110

107-
public var verbosity: Int { verbose ? 1 : 0 }
111+
var verbosity: Int { verbose ? 1 : 0 }
108112

109113
/// Disables sandboxing when executing subprocesses.
110114
@Flag(name: .customLong("disable-sandbox"), help: "Disable using the sandbox when executing subprocesses")
111-
public var shouldDisableSandbox: Bool
115+
var shouldDisableSandbox: Bool
112116

113117
/// Disables manifest caching.
114118
@Flag(name: .customLong("disable-package-manifest-caching"), help: "Disable caching Package.swift manifests")
115-
public var shouldDisableManifestCaching: Bool
119+
var shouldDisableManifestCaching: Bool
116120

117121
/// Path to the compilation destination describing JSON file.
118122
@Option(name: .customLong("destination"), transform: { try PathArgument(argument: $0).path })
119-
public var customCompileDestination: AbsolutePath?
123+
var customCompileDestination: AbsolutePath?
120124

121125
/// The compilation destination’s target triple.
122126
@Option(name: .customLong("triple"), transform: Triple.init)
123-
public var customCompileTriple: Triple?
127+
var customCompileTriple: Triple?
124128

125129
/// Path to the compilation destination’s SDK.
126130
@Option(name: .customLong("sdk"), transform: { try PathArgument(argument: $0).path })
127-
public var customCompileSDK: AbsolutePath?
131+
var customCompileSDK: AbsolutePath?
128132

129133
/// Path to the compilation destination’s toolchain.
130134
@Option(name: .customLong("toolchain"), transform: { try PathArgument(argument: $0).path })
131-
public var customCompileToolchain: AbsolutePath?
135+
var customCompileToolchain: AbsolutePath?
132136

133137
/// If should link the Swift stdlib statically.
134138
@Flag(name: .customLong("static-swift-stdlib"), default: false, inversion: .prefixedNo, help: "Link Swift stdlib statically")
135-
public var shouldLinkStaticSwiftStdlib: Bool
139+
var shouldLinkStaticSwiftStdlib: Bool
136140

137141
/// Skip updating dependencies from their remote during a resolution.
138142
@Flag(name: .customLong("skip-update"), help: "Skip updating dependencies from their remote during a resolution")
139-
public var skipDependencyUpdate: Bool
143+
var skipDependencyUpdate: Bool
140144

141145
/// Which compile-time sanitizers should be enabled.
142146
@Option(name: .customLong("sanitize"),
143147
help: "Turn on runtime checks for erroneous behavior",
144148
transform: { try Sanitizer(argument: $0) })
145-
public var sanitizers: [Sanitizer]
149+
var sanitizers: [Sanitizer]
146150

147-
public var enabledSanitizers: EnabledSanitizers {
151+
var enabledSanitizers: EnabledSanitizers {
148152
EnabledSanitizers(Set(sanitizers))
149153
}
150154

151155
/// Whether to enable code coverage.
152156
@Flag(name: .customLong("enable-code-coverage"), help: "Test with code coverage enabled")
153-
public var shouldEnableCodeCoverage: Bool
157+
var shouldEnableCodeCoverage: Bool
154158

155159
// TODO: Does disable-automatic-resolution alias force-resolved-versions?
156160

157161
/// Use Package.resolved file for resolving dependencies.
158162
@Flag(name: [.long, .customLong("disable-automatic-resolution")], help: "Disable automatic resolution if Package.resolved file is out-of-date")
159-
public var forceResolvedVersions: Bool
163+
var forceResolvedVersions: Bool
160164

161165
@Flag(name: .customLong("index-store"), inversion: .prefixedEnableDisable, help: "Enable or disable indexing-while-building feature")
162-
public var indexStoreEnable: Bool?
166+
var indexStoreEnable: Bool?
163167

164168
/// The mode to use for indexing-while-building feature.
165-
public var indexStore: BuildParameters.IndexStoreMode {
169+
var indexStore: BuildParameters.IndexStoreMode {
166170
guard let enable = indexStoreEnable else { return .auto }
167171
return enable ? .on : .off
168172
}
169173

170174
/// Whether to enable generation of `.swiftinterface`s alongside `.swiftmodule`s.
171175
@Flag(name: .customLong("enable-parseable-module-interfaces"))
172-
public var shouldEnableParseableModuleInterfaces: Bool
176+
var shouldEnableParseableModuleInterfaces: Bool
173177

174178
/// Write dependency resolver trace to a file.
175179
@Flag(name: .customLong("trace-resolver"))
176-
public var enableResolverTrace: Bool
180+
var enableResolverTrace: Bool
177181

178182
/// The number of jobs for llbuild to start (aka the number of schedulerLanes)
179183
@Option(name: .shortAndLong, help: "The number of jobs to spawn in parallel during the build process")
180-
public var jobs: UInt32?
184+
var jobs: UInt32?
181185

182186
/// Whether to enable test discovery on platforms without Objective-C runtime.
183187
@Flag(help: "Enable test discovery on platforms without Objective-C runtime")
184-
public var enableTestDiscovery: Bool
188+
var enableTestDiscovery: Bool
185189

186190
/// Whether to enable llbuild manifest caching.
187191
@Flag()
188-
public var enableBuildManifestCaching: Bool
192+
var enableBuildManifestCaching: Bool
189193

190194
/// Emit the Swift module separately from the object files.
191195
@Flag()
192-
public var emitSwiftModuleSeparately: Bool
196+
var emitSwiftModuleSeparately: Bool
193197

194198
/// The build system to use.
195-
@Option()
196-
public var buildSystem: BuildSystemKind = .native
199+
@Option(default: .native)
200+
var buildSystem: BuildSystemKind
197201

198202
public mutating func validate() throws {
199203
if shouldPrintVersion {
200204
print(Versioning.currentVersion.completeDisplayString)
201205
throw ExitCode.success
202206
}
203207
}
204-
208+
205209
public init() {}
206210
}

Sources/Commands/SwiftBuildTool.swift

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,22 @@ import PackageGraph
1515
import SPMBuildCore
1616
import Build
1717

18-
public struct BuildToolOptions: ParsableArguments {
18+
extension BuildSubset {
19+
var argumentName: String {
20+
switch self {
21+
case .allExcludingTests:
22+
fatalError("no corresponding argument")
23+
case .allIncludingTests:
24+
return "--build-tests"
25+
case .product:
26+
return "--product"
27+
case .target:
28+
return "--target"
29+
}
30+
}
31+
}
32+
33+
struct BuildToolOptions: ParsableArguments {
1934
enum BuildToolMode {
2035
/// Build the package.
2136
case build
@@ -73,21 +88,21 @@ public struct BuildToolOptions: ParsableArguments {
7388
var target: String?
7489

7590
/// Specific product to build.
76-
@Option(help: "Build the specified product)
91+
@Option(help: "Build the specified product")
7792
var product: String?
7893
}
7994

8095
/// swift-build tool namespace
81-
public class SwiftBuildTool: SwiftTool<BuildToolOptions> {
82-
static let configuration = CommandConfiguration(
96+
public struct SwiftBuildTool: ParsableCommand {
97+
public static let configuration = CommandConfiguration(
8398
commandName: "build",
8499
abstract: "Build sources into binary products")
85100

86101
@OptionGroup()
87102
var options: BuildToolOptions
88103

89-
func runImpl() throws {
90-
let swiftTool = try SwiftTool(options: options.swiftOptions)
104+
public func run() throws {
105+
let swiftTool = SwiftTool(options: options.swiftOptions)
91106

92107
switch try options.mode() {
93108
case .build:
@@ -97,7 +112,7 @@ public class SwiftBuildTool: SwiftTool<BuildToolOptions> {
97112
checkClangVersion()
98113
#endif
99114

100-
guard let subset = options.buildSubset(diagnostics: diagnostics) else { return }
115+
guard let subset = options.buildSubset(diagnostics: swiftTool.diagnostics) else { return }
101116
let buildSystem = try swiftTool.createBuildSystem()
102117
try buildSystem.build(subset: subset)
103118

@@ -119,6 +134,8 @@ public class SwiftBuildTool: SwiftTool<BuildToolOptions> {
119134
print("warning: minimum recommended clang is version 3.6, otherwise you may encounter linker errors.")
120135
}
121136
}
137+
138+
public init() {}
122139
}
123140

124141
extension Diagnostic.Message {

0 commit comments

Comments
 (0)