Skip to content

Commit 21e859c

Browse files
committed
cleanup
1 parent b2380e6 commit 21e859c

File tree

12 files changed

+214
-134
lines changed

12 files changed

+214
-134
lines changed

Sources/Basics/FileSystem+Extensions.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ extension FileSystem {
8989
}
9090

9191
extension FileSystem {
92-
public func getOrCreateSwiftPMConfigurationDirectory(observabilityScope: ObservabilityScope?) throws -> AbsolutePath {
92+
public func getOrCreateSwiftPMConfigurationDirectory() throws -> AbsolutePath {
9393
let idiomaticConfigurationDirectory = self.swiftPMConfigurationDirectory
9494

9595
// temporary 5.6, remove on next version: transition from previous configuration location
@@ -108,10 +108,12 @@ extension FileSystem {
108108
.filter{ self.isFile($0) && !self.isSymlink($0) && $0.extension != "lock"}
109109
for file in configurationFiles {
110110
let destination = idiomaticConfigurationDirectory.appending(component: file.basename)
111-
observabilityScope?.emit(warning: "Usage of \(file) has been deprecated. Please delete it and use the new \(destination) instead.")
112111
if !self.exists(destination) {
113112
try self.copy(from: file, to: destination)
114113
}
114+
// FIXME: We should emit a warning here using the diagnostic engine.
115+
TSCBasic.stderrStream.write("warning: Usage of \(file) has been deprecated. Please delete it and use the new \(destination) instead.\n")
116+
TSCBasic.stderrStream.flush()
115117
}
116118
}
117119
// in the case where ~/.swiftpm/configuration is the idiomatic location (eg on Linux)
@@ -125,10 +127,12 @@ extension FileSystem {
125127
.filter{ self.isFile($0) && !self.isSymlink($0) && $0.extension != "lock"}
126128
for file in configurationFiles {
127129
let destination = idiomaticConfigurationDirectory.appending(component: file.basename)
128-
observabilityScope?.emit(warning: "Usage of \(file) has been deprecated. Please delete it and use the new \(destination) instead.")
129130
if !self.exists(destination) {
130131
try self.copy(from: file, to: destination)
131132
}
133+
// FIXME: We should emit a warning here using the diagnostic engine.
134+
TSCBasic.stderrStream.write("warning: Usage of \(file) has been deprecated. Please delete it and use the new \(destination) instead.\n")
135+
TSCBasic.stderrStream.flush()
132136
}
133137
}
134138
}

Sources/Commands/APIDigester.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,11 @@ struct APIDigesterBaselineDumper {
9999
try workingCopy.checkout(revision: baselineRevision)
100100

101101
// Create the workspace for this package.
102-
let workspace = try Workspace(
103-
forRootPackage: baselinePackageRoot
104-
)
102+
let workspace = try Workspace(forRootPackage: baselinePackageRoot)
105103

106104
let graph = try workspace.loadPackageGraph(
107105
rootPath: baselinePackageRoot,
108-
observabilityScope: observabilityScope
106+
observabilityScope: self.observabilityScope
109107
)
110108

111109
// Don't emit a baseline for a module that didn't exist yet in this revision.

Sources/Commands/SwiftTool.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,6 @@ public class SwiftTool {
494494
return workspace
495495
}
496496

497-
// we do not take an observabilityScope in the workspace initializer as the workspace is designed to be long lived
498-
// instead observabilityScope is passed into the individual workspace methods which are short lived
499-
// however, the workspace initializer may need to emit diagnostics, for which the CLI sets this thread local
500-
Thread.current.threadDictionary["observabilityScope"] = observabilityScope
501-
502497
let isXcodeBuildSystemEnabled = self.options.buildSystem == .xcode
503498
let repositoryProvider = GitRepositoryProvider(processSet: self.processSet)
504499
let delegate = ToolWorkspaceDelegate(self.outputStream, logLevel: self.logLevel, observabilityScope: self.observabilityScope)
@@ -1096,7 +1091,7 @@ private func getSharedConfigurationDirectory(options: SwiftToolOptions, observab
10961091
}
10971092

10981093
do {
1099-
return try localFileSystem.getOrCreateSwiftPMConfigurationDirectory(observabilityScope: observabilityScope)
1094+
return try localFileSystem.getOrCreateSwiftPMConfigurationDirectory()
11001095
} catch {
11011096
observabilityScope.emit(warning: "Failed creating default configuration location, \(error)")
11021097
return .none

Sources/SourceControl/RepositoryManager.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ public class RepositoryManager {
8282
fileSystem: FileSystem,
8383
path: AbsolutePath,
8484
provider: RepositoryProvider,
85-
delegate: RepositoryManagerDelegate? = nil,
86-
cachePath: AbsolutePath? = nil,
87-
cacheLocalPackages: Bool? = nil
85+
cachePath: AbsolutePath? = .none,
86+
cacheLocalPackages: Bool = false,
87+
delegate: RepositoryManagerDelegate? = .none
8888
) {
8989
self.fileSystem = fileSystem
9090
self.path = path
9191
self.cachePath = cachePath
92-
self.cacheLocalPackages = cacheLocalPackages ?? false
92+
self.cacheLocalPackages = cacheLocalPackages
9393

9494
self.provider = provider
9595
self.delegate = delegate
@@ -108,7 +108,7 @@ public class RepositoryManager {
108108
self.repositories = [:]
109109
try? self.storage.reset()
110110
// FIXME: We should emit a warning here using the diagnostic engine.
111-
TSCBasic.stderrStream.write("warning: unable to restore checkouts state: \(error)")
111+
TSCBasic.stderrStream.write("warning: unable to restore checkouts state: \(error)\n")
112112
TSCBasic.stderrStream.flush()
113113
}
114114
}

Sources/Workspace/Workspace.swift

Lines changed: 107 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ public class Workspace {
247247
/// - Parameters:
248248
/// - fileSystem: The file system to use.
249249
/// - location: Workspace location configuration.
250-
/// - registries: Configuration for registries
251250
/// - authorizationProvider: Provider of authentication information for outbound network requests.
252251
/// - configuration: Configuration to fine tune the dependency resolution behavior.
253252
/// - customManifestLoader: Custom manifest loader. Used to customize how manifest are loaded.
@@ -288,6 +287,92 @@ public class Workspace {
288287
)
289288
}
290289

290+
/// A convenience method for creating a workspace for the given root
291+
/// package path.
292+
///
293+
/// The root package path is used to compute the build directory and other
294+
/// default paths.
295+
///
296+
/// - Parameters:
297+
/// - fileSystem: The file system to use, defaults to local file system.
298+
/// - forRootPackage: The path for the root package.
299+
/// - authorizationProvider: Provider of authentication information for outbound network requests.
300+
/// - configuration: Configuration to fine tune the dependency resolution behavior.
301+
/// - customManifestLoader: Custom manifest loader. Used to customize how manifest are loaded.
302+
/// - customPackageContainerProvider: Custom package container provider. Used to provide specialized package providers.
303+
/// - customRepositoryProvider: Custom repository provider. Used to customize source control access.
304+
/// - delegate: Delegate for workspace events
305+
public convenience init(
306+
fileSystem: FileSystem? = .none,
307+
forRootPackage packagePath: AbsolutePath,
308+
authorizationProvider: AuthorizationProvider? = .none,
309+
configuration: WorkspaceConfiguration? = .none,
310+
// optional customization used for advanced integration situations
311+
customManifestLoader: ManifestLoaderProtocol? = .none,
312+
customPackageContainerProvider: PackageContainerProvider? = .none,
313+
customRepositoryProvider: RepositoryProvider? = .none,
314+
// delegate
315+
delegate: WorkspaceDelegate? = .none
316+
) throws {
317+
let fileSystem = fileSystem ?? localFileSystem
318+
let location = Location(forRootPackage: packagePath, fileSystem: fileSystem)
319+
try self.init(
320+
fileSystem: fileSystem,
321+
location: location,
322+
customManifestLoader: customManifestLoader,
323+
customPackageContainerProvider: customPackageContainerProvider,
324+
customRepositoryProvider: customRepositoryProvider,
325+
delegate: delegate
326+
)
327+
}
328+
329+
/// A convenience method for creating a workspace for the given root
330+
/// package path.
331+
///
332+
/// The root package path is used to compute the build directory and other
333+
/// default paths.
334+
///
335+
/// - Parameters:
336+
/// - fileSystem: The file system to use, defaults to local file system.
337+
/// - forRootPackage: The path for the root package.
338+
/// - authorizationProvider: Provider of authentication information for outbound network requests.
339+
/// - configuration: Configuration to fine tune the dependency resolution behavior.
340+
/// - customToolchain: Custom toolchain. Used to create a customized ManifestLoader, customizing how manifest are loaded.
341+
/// - customPackageContainerProvider: Custom package container provider. Used to provide specialized package providers.
342+
/// - customRepositoryProvider: Custom repository provider. Used to customize source control access.
343+
/// - delegate: Delegate for workspace events
344+
public convenience init(
345+
fileSystem: FileSystem? = .none,
346+
forRootPackage packagePath: AbsolutePath,
347+
authorizationProvider: AuthorizationProvider? = .none,
348+
configuration: WorkspaceConfiguration? = .none,
349+
// optional customization used for advanced integration situations
350+
customToolchain: UserToolchain,
351+
customPackageContainerProvider: PackageContainerProvider? = .none,
352+
customRepositoryProvider: RepositoryProvider? = .none,
353+
// delegate
354+
delegate: WorkspaceDelegate? = .none
355+
) throws {
356+
let fileSystem = fileSystem ?? localFileSystem
357+
let location = Location(forRootPackage: packagePath, fileSystem: fileSystem)
358+
let manifestLoader = ManifestLoader(
359+
toolchain: customToolchain.configuration,
360+
cacheDir: location.sharedManifestsCacheDirectory
361+
)
362+
try self.init(
363+
fileSystem: fileSystem,
364+
forRootPackage: packagePath,
365+
authorizationProvider: authorizationProvider,
366+
configuration: configuration,
367+
customManifestLoader: manifestLoader,
368+
customPackageContainerProvider: customPackageContainerProvider,
369+
customRepositoryProvider: customRepositoryProvider,
370+
delegate: delegate
371+
)
372+
}
373+
374+
375+
291376
// deprecate 12/21
292377
@_disfavoredOverload
293378
@available(*, deprecated, message: "use alternative initializer")
@@ -406,64 +491,6 @@ public class Workspace {
406491
}
407492
}
408493

409-
/// A convenience method for creating a workspace for the given root
410-
/// package path.
411-
///
412-
/// The root package path is used to compute the build directory and other
413-
/// default paths.
414-
///
415-
/// - Parameters:
416-
/// - fileSystem: The file system to use, defaults to local file system.
417-
/// - forRootPackage: The path for the root package.
418-
/// - customToolchain: A custom toolchain.
419-
/// - delegate: Delegate for workspace events
420-
public convenience init(
421-
fileSystem: FileSystem? = .none,
422-
forRootPackage packagePath: AbsolutePath,
423-
customToolchain: UserToolchain,
424-
delegate: WorkspaceDelegate? = .none
425-
) throws {
426-
let fileSystem = fileSystem ?? localFileSystem
427-
let location = Location(forRootPackage: packagePath, fileSystem: fileSystem)
428-
let manifestLoader = ManifestLoader(
429-
toolchain: customToolchain.configuration,
430-
cacheDir: location.sharedManifestsCacheDirectory
431-
)
432-
try self.init(
433-
fileSystem: fileSystem,
434-
forRootPackage: packagePath,
435-
customManifestLoader: manifestLoader,
436-
delegate: delegate
437-
)
438-
}
439-
440-
/// A convenience method for creating a workspace for the given root
441-
/// package path.
442-
///
443-
/// The root package path is used to compute the build directory and other
444-
/// default paths.
445-
///
446-
/// - Parameters:
447-
/// - fileSystem: The file system to use, defaults to local file system.
448-
/// - forRootPackage: The path for the root package.
449-
/// - customManifestLoader: A custom manifest loader.
450-
/// - delegate: Delegate for workspace events
451-
public convenience init(
452-
fileSystem: FileSystem? = .none,
453-
forRootPackage packagePath: AbsolutePath,
454-
customManifestLoader: ManifestLoaderProtocol? = .none,
455-
delegate: WorkspaceDelegate? = .none
456-
) throws {
457-
let fileSystem = fileSystem ?? localFileSystem
458-
let location = Location(forRootPackage: packagePath, fileSystem: fileSystem)
459-
try self .init(
460-
fileSystem: fileSystem,
461-
location: location,
462-
customManifestLoader: customManifestLoader,
463-
delegate: delegate
464-
)
465-
}
466-
467494
/// A convenience method for creating a workspace for the given root
468495
/// package path.
469496
///
@@ -478,9 +505,10 @@ public class Workspace {
478505
delegate: WorkspaceDelegate? = nil,
479506
identityResolver: IdentityResolver? = nil
480507
) -> Workspace {
481-
let workspace = try! Workspace(forRootPackage: packagePath,
482-
customManifestLoader: manifestLoader,
483-
delegate: delegate
508+
let workspace = try! Workspace(
509+
forRootPackage: packagePath,
510+
customManifestLoader: manifestLoader,
511+
delegate: delegate
484512
)
485513
if let repositoryManager = repositoryManager {
486514
workspace.repositoryManager = repositoryManager
@@ -562,12 +590,11 @@ public class Workspace {
562590
// delegate
563591
delegate: WorkspaceDelegate?
564592
) throws {
565-
// we do not take an observabilityScope in the workspace initializer as the workspace is designed to be long lived.
593+
// we do not store the observabilityScope in the workspace initializer as the workspace is designed to be long lived.
566594
// instead, observabilityScope is passed into the individual workspace methods which are short lived.
567-
// however, the workspace initializer may need to emit diagnostics, for which a consumer like the CLI can set as a thread local
568-
let observabilityScope = Thread.current.threadDictionary["observabilityScope"] as? ObservabilityScope
595+
569596
// validate locations, returning a potentially modified one to deal with non-accessible or non-writable shared locations
570-
let location = try location.validatingSharedLocations(fileSystem: fileSystem, observabilityScope: observabilityScope)
597+
let location = try location.validatingSharedLocations(fileSystem: fileSystem)
571598

572599
let currentToolsVersion = customToolsVersion ?? ToolsVersion.currentToolsVersion
573600
let toolsVersionLoader = ToolsVersionLoader(currentToolsVersion: currentToolsVersion)
@@ -590,8 +617,8 @@ public class Workspace {
590617
fileSystem: fileSystem,
591618
path: location.repositoriesDirectory,
592619
provider: repositoryProvider,
593-
delegate: delegate.map(WorkspaceRepositoryManagerDelegate.init(workspaceDelegate:)),
594-
cachePath: configuration.sharedRepositoriesCacheEnabled ? location.sharedRepositoriesCacheDirectory : .none
620+
cachePath: configuration.sharedRepositoriesCacheEnabled ? location.sharedRepositoriesCacheDirectory : .none,
621+
delegate: delegate.map(WorkspaceRepositoryManagerDelegate.init(workspaceDelegate:))
595622
)
596623

597624
let fingerprints = customFingerprints ?? location.sharedFingerprintsDirectory.map {
@@ -654,7 +681,7 @@ public class Workspace {
654681

655682
self.configuration = configuration
656683

657-
self.state = WorkspaceState(dataPath: self.location.workingDirectory, fileSystem: fileSystem)
684+
self.state = WorkspaceState(fileSystem: fileSystem, storageDirectory: self.location.workingDirectory)
658685
}
659686
}
660687

@@ -3847,7 +3874,7 @@ extension Workspace.Location {
38473874
}
38483875

38493876
extension Workspace.Location {
3850-
func validatingSharedLocations(fileSystem: FileSystem, observabilityScope: ObservabilityScope?) throws -> Self {
3877+
func validatingSharedLocations(fileSystem: FileSystem) throws -> Self {
38513878
var location = self
38523879

38533880
// local configuration directory must be accessible, throw if we cannot access it
@@ -3856,7 +3883,7 @@ extension Workspace.Location {
38563883
// check that shared configuration directory is accessible, or warn + reset if not
38573884
if let sharedConfigurationDirectory = self.sharedConfigurationDirectory {
38583885
// it may not always be possible to create default location (for example de to restricted sandbox)
3859-
let defaultDirectory = try? fileSystem.getOrCreateSwiftPMConfigurationDirectory(observabilityScope: observabilityScope)
3886+
let defaultDirectory = try? fileSystem.getOrCreateSwiftPMConfigurationDirectory()
38603887
if sharedConfigurationDirectory != defaultDirectory {
38613888
// custom location must be writable, throw if we cannot access it
38623889
try fileSystem.withLock(on: sharedConfigurationDirectory.appending(component: "test"), type: .exclusive, {})
@@ -3865,8 +3892,10 @@ extension Workspace.Location {
38653892
do {
38663893
try fileSystem.withLock(on: sharedConfigurationDirectory.appending(component: "test"), type: .exclusive, {})
38673894
} catch {
3868-
observabilityScope?.emit(warning: "\(sharedConfigurationDirectory) is not writable, disabling user-level configuration features. \(error)")
38693895
location.sharedConfigurationDirectory = .none
3896+
// FIXME: We should emit a warning here using the diagnostic engine.
3897+
TSCBasic.stderrStream.write("warning: \(sharedConfigurationDirectory) is not writable, disabling user-level configuration features. \(error)\n")
3898+
TSCBasic.stderrStream.flush()
38703899
}
38713900
}
38723901
}
@@ -3883,8 +3912,10 @@ extension Workspace.Location {
38833912
do {
38843913
try fileSystem.withLock(on: sharedSecurityDirectory.appending(component: "test"), type: .exclusive, {})
38853914
} catch {
3886-
observabilityScope?.emit(warning: "\(sharedSecurityDirectory) is not writable, disabling user-level security features. \(error)")
38873915
location.sharedSecurityDirectory = .none
3916+
// FIXME: We should emit a warning here using the diagnostic engine.
3917+
TSCBasic.stderrStream.write("warning: \(sharedSecurityDirectory) is not writable, disabling user-level security features. \(error)\n")
3918+
TSCBasic.stderrStream.flush()
38883919
}
38893920
}
38903921
}
@@ -3901,8 +3932,10 @@ extension Workspace.Location {
39013932
do {
39023933
try fileSystem.withLock(on: sharedCacheDirectory.appending(component: "test"), type: .exclusive, {})
39033934
} catch {
3904-
observabilityScope?.emit(warning: "\(sharedCacheDirectory) is not writable, disabling user-level cache features. \(error)")
39053935
location.sharedCacheDirectory = .none
3936+
// FIXME: We should emit a warning here using the diagnostic engine.
3937+
TSCBasic.stderrStream.write("warning: \(sharedCacheDirectory) is not writable, disabling user-level cache features. \(error)\n")
3938+
TSCBasic.stderrStream.flush()
39063939
}
39073940
}
39083941
}

0 commit comments

Comments
 (0)