@@ -81,21 +81,23 @@ public typealias WorkspaceLoaderProvider = (_ fileSystem: FileSystem, _ observab
81
81
-> WorkspaceLoader
82
82
83
83
public protocol _SwiftCommand {
84
+ var globalOptions : GlobalOptions { get }
85
+ // Most commands will search upwards from package path until they find a package manifest. Commands which set this to true will instead stick to the defined package path.
86
+ var packagePathIsAuthoritative : Bool { get }
84
87
var toolWorkspaceConfiguration : ToolWorkspaceConfiguration { get }
85
88
var workspaceDelegateProvider : WorkspaceDelegateProvider { get }
86
89
var workspaceLoaderProvider : WorkspaceLoaderProvider { get }
87
90
func buildSystemProvider( _ swiftTool: SwiftTool ) throws -> BuildSystemProvider
88
91
}
89
92
90
93
extension _SwiftCommand {
94
+ public var packagePathIsAuthoritative : Bool { false }
91
95
public var toolWorkspaceConfiguration : ToolWorkspaceConfiguration {
92
96
return . init( )
93
97
}
94
98
}
95
99
96
100
public protocol SwiftCommand : ParsableCommand , _SwiftCommand {
97
- var globalOptions : GlobalOptions { get }
98
-
99
101
func run( _ swiftTool: SwiftTool ) throws
100
102
}
101
103
@@ -115,6 +117,7 @@ extension SwiftCommand {
115
117
public func run( ) throws {
116
118
let swiftTool = try SwiftTool (
117
119
options: globalOptions,
120
+ packagePathIsAuthoritative: self . packagePathIsAuthoritative,
118
121
toolWorkspaceConfiguration: self . toolWorkspaceConfiguration,
119
122
workspaceDelegateProvider: self . workspaceDelegateProvider,
120
123
workspaceLoaderProvider: self . workspaceLoaderProvider
@@ -153,8 +156,6 @@ extension SwiftCommand {
153
156
}
154
157
155
158
public protocol AsyncSwiftCommand : AsyncParsableCommand , _SwiftCommand {
156
- var globalOptions : GlobalOptions { get }
157
-
158
159
func run( _ swiftTool: SwiftTool ) async throws
159
160
}
160
161
@@ -164,6 +165,7 @@ extension AsyncSwiftCommand {
164
165
public func run( ) async throws {
165
166
let swiftTool = try SwiftTool (
166
167
options: globalOptions,
168
+ packagePathIsAuthoritative: self . packagePathIsAuthoritative,
167
169
toolWorkspaceConfiguration: self . toolWorkspaceConfiguration,
168
170
workspaceDelegateProvider: self . workspaceDelegateProvider,
169
171
workspaceLoaderProvider: self . workspaceLoaderProvider
@@ -283,6 +285,7 @@ public final class SwiftTool {
283
285
/// - parameter options: The command line options to be passed to this tool.
284
286
public convenience init (
285
287
options: GlobalOptions ,
288
+ packagePathIsAuthoritative: Bool ,
286
289
toolWorkspaceConfiguration: ToolWorkspaceConfiguration = . init( ) ,
287
290
workspaceDelegateProvider: @escaping WorkspaceDelegateProvider ,
288
291
workspaceLoaderProvider: @escaping WorkspaceLoaderProvider
@@ -295,6 +298,7 @@ public final class SwiftTool {
295
298
try self . init (
296
299
outputStream: TSCBasic . stderrStream,
297
300
options: options,
301
+ packagePathIsAuthoritative: packagePathIsAuthoritative,
298
302
toolWorkspaceConfiguration: toolWorkspaceConfiguration,
299
303
workspaceDelegateProvider: workspaceDelegateProvider,
300
304
workspaceLoaderProvider: workspaceLoaderProvider
@@ -305,6 +309,7 @@ public final class SwiftTool {
305
309
internal init (
306
310
outputStream: OutputByteStream ,
307
311
options: GlobalOptions ,
312
+ packagePathIsAuthoritative: Bool ,
308
313
toolWorkspaceConfiguration: ToolWorkspaceConfiguration ,
309
314
workspaceDelegateProvider: @escaping WorkspaceDelegateProvider ,
310
315
workspaceLoaderProvider: @escaping WorkspaceLoaderProvider
@@ -348,7 +353,12 @@ public final class SwiftTool {
348
353
}
349
354
350
355
// Create local variables to use while finding build path to avoid capture self before init error.
351
- let packageRoot = findPackageRoot ( fileSystem: fileSystem)
356
+ let packageRoot : AbsolutePath ?
357
+ if packagePathIsAuthoritative {
358
+ packageRoot = fileSystem. currentWorkingDirectory
359
+ } else {
360
+ packageRoot = findPackageRoot ( fileSystem: fileSystem)
361
+ }
352
362
353
363
self . packageRoot = packageRoot
354
364
self . scratchDirectory =
0 commit comments