Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tomerd committed Dec 21, 2021
1 parent b2380e6 commit c5bcf54
Show file tree
Hide file tree
Showing 12 changed files with 440 additions and 423 deletions.
10 changes: 7 additions & 3 deletions Sources/Basics/FileSystem+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extension FileSystem {
}

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

// temporary 5.6, remove on next version: transition from previous configuration location
Expand All @@ -108,10 +108,12 @@ extension FileSystem {
.filter{ self.isFile($0) && !self.isSymlink($0) && $0.extension != "lock"}
for file in configurationFiles {
let destination = idiomaticConfigurationDirectory.appending(component: file.basename)
observabilityScope?.emit(warning: "Usage of \(file) has been deprecated. Please delete it and use the new \(destination) instead.")
if !self.exists(destination) {
try self.copy(from: file, to: destination)
}
// FIXME: We should emit a warning here using the diagnostic engine.
TSCBasic.stderrStream.write("warning: Usage of \(file) has been deprecated. Please delete it and use the new \(destination) instead.\n")
TSCBasic.stderrStream.flush()
}
}
// in the case where ~/.swiftpm/configuration is the idiomatic location (eg on Linux)
Expand All @@ -125,10 +127,12 @@ extension FileSystem {
.filter{ self.isFile($0) && !self.isSymlink($0) && $0.extension != "lock"}
for file in configurationFiles {
let destination = idiomaticConfigurationDirectory.appending(component: file.basename)
observabilityScope?.emit(warning: "Usage of \(file) has been deprecated. Please delete it and use the new \(destination) instead.")
if !self.exists(destination) {
try self.copy(from: file, to: destination)
}
// FIXME: We should emit a warning here using the diagnostic engine.
TSCBasic.stderrStream.write("warning: Usage of \(file) has been deprecated. Please delete it and use the new \(destination) instead.\n")
TSCBasic.stderrStream.flush()
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions Sources/Commands/APIDigester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ struct APIDigesterBaselineDumper {
try workingCopy.checkout(revision: baselineRevision)

// Create the workspace for this package.
let workspace = try Workspace(
forRootPackage: baselinePackageRoot
)
let workspace = try Workspace(forRootPackage: baselinePackageRoot)

let graph = try workspace.loadPackageGraph(
rootPath: baselinePackageRoot,
observabilityScope: observabilityScope
observabilityScope: self.observabilityScope
)

// Don't emit a baseline for a module that didn't exist yet in this revision.
Expand Down
79 changes: 3 additions & 76 deletions Sources/Commands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,6 @@ public class SwiftTool {
return workspace
}

// we do not take an observabilityScope in the workspace initializer as the workspace is designed to be long lived
// instead observabilityScope is passed into the individual workspace methods which are short lived
// however, the workspace initializer may need to emit diagnostics, for which the CLI sets this thread local
Thread.current.threadDictionary["observabilityScope"] = observabilityScope

let isXcodeBuildSystemEnabled = self.options.buildSystem == .xcode
let repositoryProvider = GitRepositoryProvider(processSet: self.processSet)
let delegate = ToolWorkspaceDelegate(self.outputStream, logLevel: self.logLevel, observabilityScope: self.observabilityScope)
Expand Down Expand Up @@ -546,72 +541,7 @@ public class SwiftTool {
return try Workspace.DefaultLocations.resolvedVersionsFile(forRootPackage: self.getPackageRoot())
}

/*
func getMirrorsConfig(sharedConfigurationDirectory: AbsolutePath? = nil) throws -> Workspace.Configuration.Mirrors {
let sharedConfigurationDirectory = sharedConfigurationDirectory ?? self.sharedConfigurationDirectory
let sharedMirrorFile = sharedConfigurationDirectory.map { Workspace.DefaultLocations.mirrorsConfigurationFile(at: $0) }
return try .init(
localMirrorFile: self.mirrorsConfigFile(),
sharedMirrorFile: sharedMirrorFile,
fileSystem: localFileSystem
)
}

private func mirrorsConfigFile() throws -> AbsolutePath {
// TODO: does this make sense now that we a global configuration as well? or should we at least rename it?
// Look for the override in the environment.
if let envPath = ProcessEnv.vars["SWIFTPM_MIRROR_CONFIG"] {
return try AbsolutePath(validating: envPath)
}

// Otherwise, use the default path.
// TODO: replace multiroot-data-file with explicit overrides
if let multiRootPackageDataFile = options.multirootPackageDataFile {
// migrate from legacy location
let legacyPath = multiRootPackageDataFile.appending(components: "xcshareddata", "swiftpm", "config")
let newPath = multiRootPackageDataFile.appending(components: "xcshareddata", "swiftpm", "configuration", "mirrors.json")
if localFileSystem.exists(legacyPath) {
try localFileSystem.createDirectory(newPath.parentDirectory, recursive: true)
try localFileSystem.move(from: legacyPath, to: newPath)
}
return newPath
}

// migrate from legacy location
let legacyPath = try self.getPackageRoot().appending(components: ".swiftpm", "config")
let newPath = try Workspace.DefaultLocations.mirrorsConfigurationFile(forRootPackage: self.getPackageRoot())
if localFileSystem.exists(legacyPath) {
observabilityScope.emit(warning: "Usage of \(legacyPath) has been deprecated. Please delete it and use the new \(newPath) instead.")
if !localFileSystem.exists(newPath) {
try localFileSystem.createDirectory(newPath.parentDirectory, recursive: true)
try localFileSystem.copy(from: legacyPath, to: newPath)
}
}
return newPath
}

func getRegistriesConfig(sharedConfigurationDirectory: AbsolutePath? = nil) throws -> Workspace.Configuration.Registries {
let localRegistriesFile = try Workspace.DefaultLocations.registriesConfigurationFile(forRootPackage: self.getPackageRoot())

let sharedConfigurationDirectory = sharedConfigurationDirectory ?? self.sharedConfigurationDirectory
let sharedRegistriesFile = sharedConfigurationDirectory.map {
Workspace.DefaultLocations.registriesConfigurationFile(at: $0)
}

return try .init(
localRegistriesFile: localRegistriesFile,
sharedRegistriesFile: sharedRegistriesFile,
fileSystem: localFileSystem
)
}*/

internal func getLocalConfigurationDirectory() throws -> AbsolutePath {
// TODO: does this make sense now that we a global configuration as well? or should we at least rename it?
// Look for the override in the environment.
//if let envPath = ProcessEnv.vars["SWIFTPM_MIRROR_CONFIG"] {
// return try AbsolutePath(validating: envPath)
//}

// Otherwise, use the default path.
// TODO: replace multiroot-data-file with explicit overrides
if let multiRootPackageDataFile = options.multirootPackageDataFile {
Expand Down Expand Up @@ -1075,11 +1005,8 @@ private func getSharedSecurityDirectory(options: SwiftToolOptions, observability
return explicitSecurityPath
}

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

do {
return try localFileSystem.getOrCreateSwiftPMConfigurationDirectory(observabilityScope: observabilityScope)
return try localFileSystem.getOrCreateSwiftPMConfigurationDirectory()
} catch {
observabilityScope.emit(warning: "Failed creating default configuration location, \(error)")
return .none
Expand Down
10 changes: 5 additions & 5 deletions Sources/SourceControl/RepositoryManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public class RepositoryManager {
fileSystem: FileSystem,
path: AbsolutePath,
provider: RepositoryProvider,
delegate: RepositoryManagerDelegate? = nil,
cachePath: AbsolutePath? = nil,
cacheLocalPackages: Bool? = nil
cachePath: AbsolutePath? = .none,
cacheLocalPackages: Bool = false,
delegate: RepositoryManagerDelegate? = .none
) {
self.fileSystem = fileSystem
self.path = path
self.cachePath = cachePath
self.cacheLocalPackages = cacheLocalPackages ?? false
self.cacheLocalPackages = cacheLocalPackages

self.provider = provider
self.delegate = delegate
Expand All @@ -108,7 +108,7 @@ public class RepositoryManager {
self.repositories = [:]
try? self.storage.reset()
// FIXME: We should emit a warning here using the diagnostic engine.
TSCBasic.stderrStream.write("warning: unable to restore checkouts state: \(error)")
TSCBasic.stderrStream.write("warning: unable to restore checkouts state: \(error)\n")
TSCBasic.stderrStream.flush()
}
}
Expand Down
Loading

0 comments on commit c5bcf54

Please sign in to comment.