Skip to content

Commit c5bcf54

Browse files
committed
cleanup
1 parent b2380e6 commit c5bcf54

File tree

12 files changed

+440
-423
lines changed

12 files changed

+440
-423
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: 3 additions & 76 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)
@@ -546,72 +541,7 @@ public class SwiftTool {
546541
return try Workspace.DefaultLocations.resolvedVersionsFile(forRootPackage: self.getPackageRoot())
547542
}
548543

549-
/*
550-
func getMirrorsConfig(sharedConfigurationDirectory: AbsolutePath? = nil) throws -> Workspace.Configuration.Mirrors {
551-
let sharedConfigurationDirectory = sharedConfigurationDirectory ?? self.sharedConfigurationDirectory
552-
let sharedMirrorFile = sharedConfigurationDirectory.map { Workspace.DefaultLocations.mirrorsConfigurationFile(at: $0) }
553-
return try .init(
554-
localMirrorFile: self.mirrorsConfigFile(),
555-
sharedMirrorFile: sharedMirrorFile,
556-
fileSystem: localFileSystem
557-
)
558-
}
559-
560-
private func mirrorsConfigFile() throws -> AbsolutePath {
561-
// TODO: does this make sense now that we a global configuration as well? or should we at least rename it?
562-
// Look for the override in the environment.
563-
if let envPath = ProcessEnv.vars["SWIFTPM_MIRROR_CONFIG"] {
564-
return try AbsolutePath(validating: envPath)
565-
}
566-
567-
// Otherwise, use the default path.
568-
// TODO: replace multiroot-data-file with explicit overrides
569-
if let multiRootPackageDataFile = options.multirootPackageDataFile {
570-
// migrate from legacy location
571-
let legacyPath = multiRootPackageDataFile.appending(components: "xcshareddata", "swiftpm", "config")
572-
let newPath = multiRootPackageDataFile.appending(components: "xcshareddata", "swiftpm", "configuration", "mirrors.json")
573-
if localFileSystem.exists(legacyPath) {
574-
try localFileSystem.createDirectory(newPath.parentDirectory, recursive: true)
575-
try localFileSystem.move(from: legacyPath, to: newPath)
576-
}
577-
return newPath
578-
}
579-
580-
// migrate from legacy location
581-
let legacyPath = try self.getPackageRoot().appending(components: ".swiftpm", "config")
582-
let newPath = try Workspace.DefaultLocations.mirrorsConfigurationFile(forRootPackage: self.getPackageRoot())
583-
if localFileSystem.exists(legacyPath) {
584-
observabilityScope.emit(warning: "Usage of \(legacyPath) has been deprecated. Please delete it and use the new \(newPath) instead.")
585-
if !localFileSystem.exists(newPath) {
586-
try localFileSystem.createDirectory(newPath.parentDirectory, recursive: true)
587-
try localFileSystem.copy(from: legacyPath, to: newPath)
588-
}
589-
}
590-
return newPath
591-
}
592-
593-
func getRegistriesConfig(sharedConfigurationDirectory: AbsolutePath? = nil) throws -> Workspace.Configuration.Registries {
594-
let localRegistriesFile = try Workspace.DefaultLocations.registriesConfigurationFile(forRootPackage: self.getPackageRoot())
595-
596-
let sharedConfigurationDirectory = sharedConfigurationDirectory ?? self.sharedConfigurationDirectory
597-
let sharedRegistriesFile = sharedConfigurationDirectory.map {
598-
Workspace.DefaultLocations.registriesConfigurationFile(at: $0)
599-
}
600-
601-
return try .init(
602-
localRegistriesFile: localRegistriesFile,
603-
sharedRegistriesFile: sharedRegistriesFile,
604-
fileSystem: localFileSystem
605-
)
606-
}*/
607-
608544
internal func getLocalConfigurationDirectory() throws -> AbsolutePath {
609-
// TODO: does this make sense now that we a global configuration as well? or should we at least rename it?
610-
// Look for the override in the environment.
611-
//if let envPath = ProcessEnv.vars["SWIFTPM_MIRROR_CONFIG"] {
612-
// return try AbsolutePath(validating: envPath)
613-
//}
614-
615545
// Otherwise, use the default path.
616546
// TODO: replace multiroot-data-file with explicit overrides
617547
if let multiRootPackageDataFile = options.multirootPackageDataFile {
@@ -1075,11 +1005,8 @@ private func getSharedSecurityDirectory(options: SwiftToolOptions, observability
10751005
return explicitSecurityPath
10761006
}
10771007

1078-
do {
1079-
let sharedSecurityDirectory = try localFileSystem.getOrCreateSwiftPMSecurityDirectory()
1080-
// And make sure we can write files (locking the directory writes a lock file)
1081-
try localFileSystem.withLock(on: sharedSecurityDirectory, type: .exclusive) { }
1082-
return sharedSecurityDirectory
1008+
do {
1009+
return try localFileSystem.getOrCreateSwiftPMSecurityDirectory()
10831010
} catch {
10841011
observabilityScope.emit(warning: "Failed creating default security location, \(error)")
10851012
return .none
@@ -1096,7 +1023,7 @@ private func getSharedConfigurationDirectory(options: SwiftToolOptions, observab
10961023
}
10971024

10981025
do {
1099-
return try localFileSystem.getOrCreateSwiftPMConfigurationDirectory(observabilityScope: observabilityScope)
1026+
return try localFileSystem.getOrCreateSwiftPMConfigurationDirectory()
11001027
} catch {
11011028
observabilityScope.emit(warning: "Failed creating default configuration location, \(error)")
11021029
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
}

0 commit comments

Comments
 (0)