Skip to content

[NFC] Fix some of the new Swift main snapshots warnings #7214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Basics/Vendor/Triple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ extension Triple {
}
}

public enum Arch: String, CaseIterable {
public enum Arch: String, CaseIterable, Decodable {
/// ARM (little endian): arm, armv.*, xscale
case arm
// ARM (big endian): armeb
Expand Down
4 changes: 4 additions & 0 deletions Sources/Commands/PackageTools/Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ extension SwiftPackageTool {
}
}

#if swift(<5.11)
extension InitPackage.PackageType: ExpressibleByArgument {}
#else
extension InitPackage.PackageType: @retroactive ExpressibleByArgument {}
#endif
8 changes: 7 additions & 1 deletion Sources/Commands/Utilities/APIDigester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,14 @@ extension PackageGraph {
}
}

extension SerializedDiagnostics.SourceLocation: DiagnosticLocation {
extension SerializedDiagnostics.SourceLocation {
public var description: String {
return "\(filename):\(line):\(column)"
}
}

#if swift(<5.11)
extension SerializedDiagnostics.SourceLocation: DiagnosticLocation {}
#else
extension SerializedDiagnostics.SourceLocation: @retroactive DiagnosticLocation {}
#endif
36 changes: 26 additions & 10 deletions Sources/CoreCommands/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,13 @@ public struct LinkerOptions: ParsableArguments {

// MARK: - Extensions

extension BuildConfiguration: ExpressibleByArgument {
extension BuildConfiguration {
public init?(argument: String) {
self.init(rawValue: argument)
}
}

extension AbsolutePath: ExpressibleByArgument {
extension AbsolutePath {
public init?(argument: String) {
if let cwd = localFileSystem.currentWorkingDirectory {
guard let path = try? AbsolutePath(validating: argument, relativeTo: cwd) else {
Expand All @@ -564,13 +564,13 @@ extension AbsolutePath: ExpressibleByArgument {
}
}

extension WorkspaceConfiguration.CheckingMode: ExpressibleByArgument {
extension WorkspaceConfiguration.CheckingMode {
public init?(argument: String) {
self.init(rawValue: argument)
}
}

extension Sanitizer: ExpressibleByArgument {
extension Sanitizer {
public init?(argument: String) {
if let sanitizer = Sanitizer(rawValue: argument) {
self = sanitizer
Expand All @@ -591,18 +591,34 @@ extension Sanitizer: ExpressibleByArgument {
}
}

extension BuildSystemProvider.Kind: ExpressibleByArgument {}

extension Version: ExpressibleByArgument {}

extension PackageIdentity: ExpressibleByArgument {
extension PackageIdentity {
public init?(argument: String) {
self = .plain(argument)
}
}

extension URL: ExpressibleByArgument {
extension URL {
public init?(argument: String) {
self.init(string: argument)
}
}

#if swift(<5.11)
extension BuildConfiguration: ExpressibleByArgument {}
extension AbsolutePath: ExpressibleByArgument {}
extension WorkspaceConfiguration.CheckingMode: ExpressibleByArgument {}
extension Sanitizer: ExpressibleByArgument {}
extension BuildSystemProvider.Kind: ExpressibleByArgument {}
extension Version: ExpressibleByArgument {}
extension PackageIdentity: ExpressibleByArgument {}
extension URL: ExpressibleByArgument {}
#else
extension BuildConfiguration: @retroactive ExpressibleByArgument {}
extension AbsolutePath: @retroactive ExpressibleByArgument {}
extension WorkspaceConfiguration.CheckingMode: @retroactive ExpressibleByArgument {}
extension Sanitizer: @retroactive ExpressibleByArgument {}
extension BuildSystemProvider.Kind: @retroactive ExpressibleByArgument {}
extension Version: @retroactive ExpressibleByArgument {}
extension PackageIdentity: @retroactive ExpressibleByArgument {}
extension URL: @retroactive ExpressibleByArgument {}
#endif
1 change: 0 additions & 1 deletion Sources/PackageLoading/ManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,6 @@ public final class ManifestLoader: ManifestLoaderProtocol {
for toolsVersion: ToolsVersion
) -> [String] {
var cmd = [String]()
let libraryPath = self.toolchain.swiftPMLibrariesLocation.manifestLibraryPath
let modulesPath = self.toolchain.swiftPMLibrariesLocation.manifestModulesPath
cmd += ["-swift-version", toolsVersion.swiftLanguageVersion.rawValue]
// if runtimePath is set to "PackageFrameworks" that means we could be developing SwiftPM in Xcode
Expand Down
25 changes: 25 additions & 0 deletions Sources/PackageModel/SwiftSDKs/SwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -925,3 +925,28 @@ struct SwiftSDKMetadataV4: Decodable {
/// Mapping of triple strings to corresponding properties of such target triple.
let targetTriples: [String: TripleProperties]
}

extension Optional where Wrapped == AbsolutePath {
fileprivate var configurationString: String {
self?.pathString ?? "not set"
}
}

extension Optional where Wrapped == [AbsolutePath] {
fileprivate var configurationString: String {
self?.map(\.pathString).description ?? "not set"
}
}

extension SwiftSDK.PathsConfiguration: CustomStringConvertible {
public var description: String {
"""
sdkRootPath: \(sdkRootPath.configurationString)
swiftResourcesPath: \(swiftResourcesPath.configurationString)
swiftStaticResourcesPath: \(swiftStaticResourcesPath.configurationString)
includeSearchPaths: \(includeSearchPaths.configurationString)
librarySearchPaths: \(librarySearchPaths.configurationString)
toolsetPaths: \(toolsetPaths.configurationString)
"""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,18 @@ extension SwiftPackageRegistryTool {
}
}

extension SignatureFormat: ExpressibleByArgument {
extension SignatureFormat {
public init?(argument: String) {
self.init(rawValue: argument.lowercased())
}
}

#if swift(<5.11)
extension SignatureFormat: ExpressibleByArgument {}
#else
extension SignatureFormat: @retroactive ExpressibleByArgument {}
#endif

enum MetadataLocation {
case sourceTree(AbsolutePath)
case external(AbsolutePath)
Expand Down
2 changes: 0 additions & 2 deletions Sources/SPMBuildCore/XCFrameworkMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,3 @@ extension XCFrameworkMetadata.Library: Decodable {
case variant = "SupportedPlatformVariant"
}
}

extension Triple.Arch: Decodable {}
36 changes: 27 additions & 9 deletions Sources/SPMTestSupport/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -375,21 +375,19 @@ extension FileSystem {
}
}

extension URL: ExpressibleByStringLiteral {
extension URL {
public init(_ value: StringLiteralType) {
self.init(string: value)!
}
}

extension URL: ExpressibleByStringInterpolation {
extension URL {
public init(stringLiteral value: String) {
self.init(string: value)!
}
}

extension PackageIdentity: ExpressibleByStringLiteral {}

extension PackageIdentity: ExpressibleByStringInterpolation {
extension PackageIdentity {
public init(stringLiteral value: String) {
self = Self.plain(value)
}
Expand All @@ -401,13 +399,13 @@ extension PackageIdentity {
}
}

extension AbsolutePath: ExpressibleByStringLiteral {
extension AbsolutePath {
public init(_ value: StringLiteralType) {
try! self.init(validating: value)
}
}

extension AbsolutePath: ExpressibleByStringInterpolation {
extension AbsolutePath {
public init(stringLiteral value: String) {
try! self.init(validating: value)
}
Expand All @@ -429,13 +427,13 @@ extension RelativePath {
}
}

extension RelativePath: ExpressibleByStringLiteral {
extension RelativePath {
public init(_ value: StringLiteralType) {
try! self.init(validating: value)
}
}

extension RelativePath: ExpressibleByStringInterpolation {
extension RelativePath {
public init(stringLiteral value: String) {
try! self.init(validating: value)
}
Expand All @@ -458,3 +456,23 @@ extension InitPackage {
)
}
}

#if swift(<5.11)
extension RelativePath: ExpressibleByStringLiteral {}
extension RelativePath: ExpressibleByStringInterpolation {}
extension URL: ExpressibleByStringLiteral {}
extension URL: ExpressibleByStringInterpolation {}
extension PackageIdentity: ExpressibleByStringLiteral {}
extension PackageIdentity: ExpressibleByStringInterpolation {}
extension AbsolutePath: ExpressibleByStringLiteral {}
extension AbsolutePath: ExpressibleByStringInterpolation {}
#else
extension RelativePath: @retroactive ExpressibleByStringLiteral {}
extension RelativePath: @retroactive ExpressibleByStringInterpolation {}
extension URL: @retroactive ExpressibleByStringLiteral {}
extension URL: @retroactive ExpressibleByStringInterpolation {}
extension PackageIdentity: @retroactive ExpressibleByStringLiteral {}
extension PackageIdentity: @retroactive ExpressibleByStringInterpolation {}
extension AbsolutePath: @retroactive ExpressibleByStringLiteral {}
extension AbsolutePath: @retroactive ExpressibleByStringInterpolation {}
#endif
25 changes: 0 additions & 25 deletions Sources/SwiftSDKTool/Configuration/ShowConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,3 @@ struct ShowConfiguration: ConfigurationSubcommand {
print(swiftSDK.pathsConfiguration)
}
}

extension SwiftSDK.PathsConfiguration: CustomStringConvertible {
public var description: String {
"""
sdkRootPath: \(sdkRootPath.configurationString)
swiftResourcesPath: \(swiftResourcesPath.configurationString)
swiftStaticResourcesPath: \(swiftStaticResourcesPath.configurationString)
includeSearchPaths: \(includeSearchPaths.configurationString)
librarySearchPaths: \(librarySearchPaths.configurationString)
toolsetPaths: \(toolsetPaths.configurationString)
"""
}
}

extension Optional where Wrapped == AbsolutePath {
fileprivate var configurationString: String {
self?.pathString ?? "not set"
}
}

extension Optional where Wrapped == [AbsolutePath] {
fileprivate var configurationString: String {
self?.map(\.pathString).description ?? "not set"
}
}
8 changes: 7 additions & 1 deletion Sources/Workspace/Diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ extension Basics.Diagnostic {
}
}

extension FileSystemError: CustomStringConvertible {
extension FileSystemError {
public var description: String {
guard let path else {
switch self.kind {
Expand Down Expand Up @@ -246,3 +246,9 @@ extension FileSystemError: CustomStringConvertible {
}
}
}

#if swift(<5.11)
extension FileSystemError: CustomStringConvertible {}
#else
extension FileSystemError: @retroactive CustomStringConvertible {}
#endif
4 changes: 4 additions & 0 deletions Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,11 @@ private func warnToStderr(_ message: String) {
}

// used for manifest validation
#if swift(<5.11)
extension RepositoryManager: ManifestSourceControlValidator {}
#else
extension RepositoryManager: @retroactive ManifestSourceControlValidator {}
#endif

extension ContainerUpdateStrategy {
var repositoryUpdateStrategy: RepositoryUpdateStrategy {
Expand Down
12 changes: 10 additions & 2 deletions Sources/swift-bootstrap/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
}

// TODO: move to shared area
extension AbsolutePath: ExpressibleByArgument {
extension AbsolutePath {
public init?(argument: String) {
if let cwd: AbsolutePath = localFileSystem.currentWorkingDirectory {
guard let path = try? AbsolutePath(validating: argument, relativeTo: cwd) else {
Expand All @@ -465,8 +465,16 @@ extension AbsolutePath: ExpressibleByArgument {
}
}

extension BuildConfiguration: ExpressibleByArgument {
extension BuildConfiguration {
public init?(argument: String) {
self.init(rawValue: argument)
}
}

#if swift(<5.11)
extension AbsolutePath: ExpressibleByArgument {}
extension BuildConfiguration: ExpressibleByArgument {}
#else
extension AbsolutePath: @retroactive ExpressibleByArgument {}
extension BuildConfiguration: @retroactive ExpressibleByArgument {}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private extension VersionSetSpecifier {
}
}

extension ProductFilter: JSONSerializable, JSONMappable {
extension ProductFilter {
public func toJSON() -> JSON {
switch self {
case .everything:
Expand All @@ -200,3 +200,9 @@ extension ProductFilter: JSONSerializable, JSONMappable {
}
}
}

#if swift(<5.11)
extension ProductFilter: JSONSerializable, JSONMappable {}
#else
extension ProductFilter: @retroactive JSONSerializable, @retroactive JSONMappable {}
#endif
6 changes: 0 additions & 6 deletions Tests/PackageGraphTests/DependencyResolverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ private let v1_1Range: VersionSetSpecifier = .range("1.1.0" ..< "1.2.0")
private let v1_1_0Range: VersionSetSpecifier = .range("1.1.0" ..< "1.1.1")
private let v2_0_0Range: VersionSetSpecifier = .range("2.0.0" ..< "2.0.1")

extension PackageReference: Comparable {
public static func < (lhs: PackageReference, rhs: PackageReference) -> Bool {
return lhs.identity < rhs.identity
}
}

class DependencyResolverTests: XCTestCase {
func testVersionSetSpecifier() {
// Check `contains`.
Expand Down
Loading