Skip to content

Commit 0de0bc8

Browse files
authored
Improve collections configuration warning (#5783)
If we just copied the config to the new location or if the configs at old and new location are identical, do not warn about the presence of both configs. The warning's purpose is making people aware of the fact that different versions of SwiftPM are using different configs, but if they are identical, there's no need for them to really know about it. rdar://99721607
1 parent 7096850 commit 0de0bc8

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

Sources/Basics/FileSystem+Extensions.swift

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,30 @@ extension FileSystem {
9191
}
9292

9393
extension FileSystem {
94-
public func getOrCreateSwiftPMConfigurationDirectory(warningHandler: (String) -> Void) throws -> AbsolutePath {
94+
public func getOrCreateSwiftPMConfigurationDirectory(warningHandler: @escaping (String) -> Void) throws -> AbsolutePath {
9595
let idiomaticConfigurationDirectory = self.swiftPMConfigurationDirectory
9696

9797
// temporary 5.6, remove on next version: transition from previous configuration location
9898
if !self.exists(idiomaticConfigurationDirectory) {
9999
try self.createDirectory(idiomaticConfigurationDirectory, recursive: true)
100100
}
101101

102+
let handleExistingFiles = { (configurationFiles: [AbsolutePath]) in
103+
for file in configurationFiles {
104+
let destination = idiomaticConfigurationDirectory.appending(component: file.basename)
105+
if !self.exists(destination) {
106+
try self.copy(from: file, to: destination)
107+
} else {
108+
// Only emit a warning if source and destination file differ in their contents.
109+
let srcContents = try? self.readFileContents(file)
110+
let dstContents = try? self.readFileContents(destination)
111+
if srcContents != dstContents {
112+
warningHandler("Usage of \(file) has been deprecated. Please delete it and use the new \(destination) instead.")
113+
}
114+
}
115+
}
116+
}
117+
102118
// in the case where ~/.swiftpm/configuration is not the idiomatic location (eg on macOS where its /Users/<user>/Library/org.swift.swiftpm/configuration)
103119
if idiomaticConfigurationDirectory != self.dotSwiftPMConfigurationDirectory {
104120
// copy the configuration files from old location (eg /Users/<user>/Library/org.swift.swiftpm) to new one (eg /Users/<user>/Library/org.swift.swiftpm/configuration)
@@ -108,13 +124,7 @@ extension FileSystem {
108124
let configurationFiles = try self.getDirectoryContents(oldConfigDirectory)
109125
.map{ oldConfigDirectory.appending(component: $0) }
110126
.filter{ self.isFile($0) && !self.isSymlink($0) && $0.extension != "lock" && ((try? self.readFileContents($0)) ?? []).count > 0 }
111-
for file in configurationFiles {
112-
let destination = idiomaticConfigurationDirectory.appending(component: file.basename)
113-
if !self.exists(destination) {
114-
try self.copy(from: file, to: destination)
115-
}
116-
warningHandler("Usage of \(file) has been deprecated. Please delete it and use the new \(destination) instead.")
117-
}
127+
try handleExistingFiles(configurationFiles)
118128
}
119129
// in the case where ~/.swiftpm/configuration is the idiomatic location (eg on Linux)
120130
} else {
@@ -125,13 +135,7 @@ extension FileSystem {
125135
let configurationFiles = try self.getDirectoryContents(oldConfigDirectory)
126136
.map{ oldConfigDirectory.appending(component: $0) }
127137
.filter{ self.isFile($0) && !self.isSymlink($0) && $0.extension != "lock" && ((try? self.readFileContents($0)) ?? []).count > 0 }
128-
for file in configurationFiles {
129-
let destination = idiomaticConfigurationDirectory.appending(component: file.basename)
130-
if !self.exists(destination) {
131-
try self.copy(from: file, to: destination)
132-
}
133-
warningHandler("Usage of \(file) has been deprecated. Please delete it and use the new \(destination) instead.")
134-
}
138+
try handleExistingFiles(configurationFiles)
135139
}
136140
}
137141
// ~temporary 5.6 migration

Sources/Workspace/Workspace.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3660,7 +3660,7 @@ extension FileSystem {
36603660
extension Workspace.Location {
36613661
func validatingSharedLocations(
36623662
fileSystem: FileSystem,
3663-
warningHandler: (String) -> Void
3663+
warningHandler: @escaping (String) -> Void
36643664
) throws -> Self {
36653665
var location = self
36663666

0 commit comments

Comments
 (0)