Skip to content

Commit 86038f0

Browse files
committed
Remove duplicated options in SwiftBootstrapCommand
1 parent 9204f3a commit 86038f0

File tree

4 files changed

+30
-107
lines changed

4 files changed

+30
-107
lines changed

Sources/CoreCommands/Options.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -332,28 +332,28 @@ public struct BuildOptions: ParsableArguments {
332332
parsing: .unconditionalSingleValue,
333333
help: "Pass flag through to all C compiler invocations"
334334
)
335-
var cCompilerFlags: [String] = []
335+
package var cCompilerFlags: [String] = []
336336

337337
@Option(
338338
name: .customLong("Xswiftc", withSingleDash: true),
339339
parsing: .unconditionalSingleValue,
340340
help: "Pass flag through to all Swift compiler invocations"
341341
)
342-
var swiftCompilerFlags: [String] = []
342+
package var swiftCompilerFlags: [String] = []
343343

344344
@Option(
345345
name: .customLong("Xlinker", withSingleDash: true),
346346
parsing: .unconditionalSingleValue,
347347
help: "Pass flag through to all linker invocations"
348348
)
349-
var linkerFlags: [String] = []
349+
package var linkerFlags: [String] = []
350350

351351
@Option(
352352
name: .customLong("Xcxx", withSingleDash: true),
353353
parsing: .unconditionalSingleValue,
354354
help: "Pass flag through to all C++ compiler invocations"
355355
)
356-
var cxxCompilerFlags: [String] = []
356+
package var cxxCompilerFlags: [String] = []
357357

358358
@Option(
359359
name: .customLong("Xxcbuild", withSingleDash: true),
@@ -385,7 +385,7 @@ public struct BuildOptions: ParsableArguments {
385385
)
386386
public var _deprecated_manifestFlags: [String] = []
387387

388-
var manifestFlags: [String] {
388+
package var manifestFlags: [String] {
389389
self._deprecated_manifestFlags.isEmpty ?
390390
self._buildToolsSwiftCFlags :
391391
self._deprecated_manifestFlags

Sources/CoreCommands/SwiftCommandState.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import class TSCBasic.ThreadSafeOutputByteStream
5656

5757
import var TSCUtility.verbosity
5858

59-
typealias Diagnostic = Basics.Diagnostic
59+
package typealias Diagnostic = Basics.Diagnostic
6060

6161
public struct ToolWorkspaceConfiguration {
6262
let shouldInstallSignalHandlers: Bool
@@ -1149,7 +1149,7 @@ extension Workspace.ManagedDependency {
11491149
}
11501150

11511151
extension LoggingOptions {
1152-
fileprivate var logLevel: Diagnostic.Severity {
1152+
package var logLevel: Diagnostic.Severity {
11531153
if self.verbose {
11541154
return .info
11551155
} else if self.veryVerbose {

Sources/swift-bootstrap/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
add_executable(swift-bootstrap
10-
main.swift)
10+
SwiftBootstrapCommand.swift)
11+
12+
target_compile_options(swift-bootstrap PRIVATE
13+
-parse-as-library)
14+
1115
target_link_libraries(swift-bootstrap PRIVATE
1216
ArgumentParser
1317
Basics

Sources/swift-bootstrap/main.swift renamed to Sources/swift-bootstrap/SwiftBootstrapCommand.swift

+18-99
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@ import struct TSCBasic.OrderedSet
3636
import enum TSCUtility.Diagnostics
3737
import struct TSCUtility.Version
3838

39-
await { () async in
40-
await SwiftBootstrapBuildTool.main()
41-
}()
42-
4339
private struct EmptyWorkspaceLoader: WorkspaceLoader {
4440
func load(workspace: AbsolutePath) throws -> [AbsolutePath] {
4541
[]
4642
}
4743
}
4844

49-
struct SwiftBootstrapBuildTool: AsyncSwiftCommand {
45+
@main
46+
struct SwiftBootstrapCommand: AsyncSwiftCommand {
5047
@OptionGroup(visibility: .hidden)
5148
var globalOptions: GlobalOptions
5249

@@ -60,78 +57,10 @@ struct SwiftBootstrapBuildTool: AsyncSwiftCommand {
6057
shouldDisplay: false
6158
)
6259

63-
@Option(name: .shortAndLong, help: "Build with configuration")
64-
public var configuration: BuildConfiguration = .debug
65-
66-
@Option(name: .customLong("Xcc", withSingleDash: true),
67-
parsing: .unconditionalSingleValue,
68-
help: "Pass flag through to all C compiler invocations")
69-
var cCompilerFlags: [String] = []
70-
71-
@Option(name: .customLong("Xswiftc", withSingleDash: true),
72-
parsing: .unconditionalSingleValue,
73-
help: "Pass flag through to all Swift compiler invocations")
74-
var swiftCompilerFlags: [String] = []
75-
76-
@Option(name: .customLong("Xlinker", withSingleDash: true),
77-
parsing: .unconditionalSingleValue,
78-
help: "Pass flag through to all linker invocations")
79-
var linkerFlags: [String] = []
80-
81-
@Option(name: .customLong("Xcxx", withSingleDash: true),
82-
parsing: .unconditionalSingleValue,
83-
help: "Pass flag through to all C++ compiler invocations")
84-
var cxxCompilerFlags: [String] = []
85-
86-
@Option(name: .customLong("Xxcbuild", withSingleDash: true),
87-
parsing: .unconditionalSingleValue,
88-
help: ArgumentHelp(
89-
"Pass flag through to the Xcode build system invocations",
90-
visibility: .hidden))
91-
public var xcbuildFlags: [String] = []
92-
93-
@Option(name: .customLong("Xbuild-tools-swiftc", withSingleDash: true),
94-
parsing: .unconditionalSingleValue,
95-
help: ArgumentHelp("Pass flag to the manifest build invocation",
96-
visibility: .hidden))
97-
public var manifestFlags: [String] = []
98-
99-
@Option(
100-
name: .customLong("arch"),
101-
help: ArgumentHelp("Build the package for the these architectures", visibility: .hidden))
102-
public var architectures: [String] = []
103-
104-
/// The verbosity of informational output.
105-
@Flag(name: .shortAndLong, help: "Increase verbosity to include informational output")
106-
public var verbose: Bool = false
107-
108-
/// The verbosity of informational output.
109-
@Flag(name: [.long, .customLong("vv")], help: "Increase verbosity to include debug output")
110-
public var veryVerbose: Bool = false
111-
112-
/// Whether to use the integrated Swift driver rather than shelling out
113-
/// to a separate process.
114-
@Flag()
115-
public var useIntegratedSwiftDriver: Bool = false
116-
117-
/// An option that indicates this build should check whether targets only import
118-
/// their explicitly-declared dependencies
119-
@Option(help: "Check that targets only import their explicitly-declared dependencies")
120-
public var explicitTargetDependencyImportCheck: TargetDependencyImportCheckingMode = .none
121-
122-
enum TargetDependencyImportCheckingMode: String, Codable, ExpressibleByArgument, CaseIterable {
123-
case none
124-
case error
125-
}
126-
127-
/// Disables adding $ORIGIN/@loader_path to the rpath, useful when deploying
128-
@Flag(name: .customLong("disable-local-rpath"), help: "Disable adding $ORIGIN/@loader_path to the rpath by default")
129-
public var shouldDisableLocalRpath: Bool = false
130-
13160
private var buildSystem: BuildSystemProvider.Kind {
13261
#if os(macOS)
13362
// Force the Xcode build system if we want to build more than one arch.
134-
return self.architectures.count > 1 ? .xcode : .native
63+
return self.globalOptions.build.architectures.count > 1 ? .xcode : .native
13564
#else
13665
// Force building with the native build system on other platforms than macOS.
13766
return .native
@@ -140,32 +69,22 @@ struct SwiftBootstrapBuildTool: AsyncSwiftCommand {
14069

14170
public var buildFlags: BuildFlags {
14271
BuildFlags(
143-
cCompilerFlags: self.cCompilerFlags,
144-
cxxCompilerFlags: self.cxxCompilerFlags,
145-
swiftCompilerFlags: self.swiftCompilerFlags,
146-
linkerFlags: self.linkerFlags,
147-
xcbuildFlags: self.xcbuildFlags
72+
cCompilerFlags: self.globalOptions.build.cCompilerFlags,
73+
cxxCompilerFlags: self.globalOptions.build.cxxCompilerFlags,
74+
swiftCompilerFlags: self.globalOptions.build.swiftCompilerFlags,
75+
linkerFlags: self.globalOptions.build.linkerFlags,
76+
xcbuildFlags: self.globalOptions.build.xcbuildFlags
14877
)
14978
}
15079

151-
private var logLevel: Basics.Diagnostic.Severity {
152-
if self.verbose {
153-
return .info
154-
} else if self.veryVerbose {
155-
return .debug
156-
} else {
157-
return .warning
158-
}
159-
}
160-
16180
public init() {}
16281

16382
public func run(_ swiftCommandState: SwiftCommandState) async throws {
16483
do {
16584
let fileSystem = localFileSystem
16685

16786
let observabilityScope = ObservabilitySystem { _, diagnostics in
168-
if diagnostics.severity >= logLevel {
87+
if diagnostics.severity >= self.globalOptions.logging.logLevel {
16988
print(diagnostics)
17089
}
17190
}.topScope
@@ -186,19 +105,19 @@ struct SwiftBootstrapBuildTool: AsyncSwiftCommand {
186105
let builder = try Builder(
187106
fileSystem: localFileSystem,
188107
observabilityScope: observabilityScope,
189-
logLevel: self.logLevel
108+
logLevel: self.globalOptions.logging.logLevel
190109
)
191110
try await builder.build(
192111
packagePath: packagePath,
193112
scratchDirectory: scratchDirectory,
194113
buildSystem: self.buildSystem,
195-
configuration: self.configuration,
196-
architectures: self.architectures,
114+
configuration: self.globalOptions.build.configuration ?? .debug,
115+
architectures: self.globalOptions.build.architectures,
197116
buildFlags: self.buildFlags,
198-
manifestBuildFlags: self.manifestFlags,
199-
useIntegratedSwiftDriver: self.useIntegratedSwiftDriver,
200-
explicitTargetDependencyImportCheck: self.explicitTargetDependencyImportCheck,
201-
shouldDisableLocalRpath: self.shouldDisableLocalRpath
117+
manifestBuildFlags: self.globalOptions.build.manifestFlags,
118+
useIntegratedSwiftDriver: self.globalOptions.build.useIntegratedSwiftDriver,
119+
explicitTargetDependencyImportCheck: self.globalOptions.build.explicitTargetDependencyImportCheck,
120+
shouldDisableLocalRpath: self.globalOptions.linker.shouldDisableLocalRpath
202121
)
203122
} catch _ as Diagnostics {
204123
throw ExitCode.failure
@@ -240,7 +159,7 @@ struct SwiftBootstrapBuildTool: AsyncSwiftCommand {
240159
buildFlags: BuildFlags,
241160
manifestBuildFlags: [String],
242161
useIntegratedSwiftDriver: Bool,
243-
explicitTargetDependencyImportCheck: TargetDependencyImportCheckingMode,
162+
explicitTargetDependencyImportCheck: BuildOptions.TargetDependencyImportCheckingMode,
244163
shouldDisableLocalRpath: Bool
245164
) async throws {
246165
let buildSystem = try createBuildSystem(
@@ -268,7 +187,7 @@ struct SwiftBootstrapBuildTool: AsyncSwiftCommand {
268187
buildFlags: BuildFlags,
269188
manifestBuildFlags: [String],
270189
useIntegratedSwiftDriver: Bool,
271-
explicitTargetDependencyImportCheck: TargetDependencyImportCheckingMode,
190+
explicitTargetDependencyImportCheck: BuildOptions.TargetDependencyImportCheckingMode,
272191
shouldDisableLocalRpath: Bool,
273192
logLevel: Basics.Diagnostic.Severity
274193
) throws -> BuildSystem {

0 commit comments

Comments
 (0)