Skip to content

Commit 010e7dc

Browse files
committed
Extract PackageModel diagnostics into separate file
1 parent 1ac899d commit 010e7dc

File tree

3 files changed

+91
-78
lines changed

3 files changed

+91
-78
lines changed

Sources/PackageModel/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
add_library(PackageModel
1010
BuildSettings.swift
11+
Diagnostics.swift
1112
Manifest.swift
1213
Package.swift
1314
Platform.swift
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import TSCBasic
12+
13+
import Foundation
14+
import TSCUtility
15+
16+
/// The diagnostic triggered when the package has a newer tools version than the installed tools.
17+
public struct RequireNewerTools: DiagnosticData, Swift.Error {
18+
/// The path of the package.
19+
public let packagePath: String
20+
21+
/// The version of the package.
22+
public let version: String?
23+
24+
/// The installed tools version.
25+
public let installedToolsVersion: ToolsVersion
26+
27+
/// The tools version of the package.
28+
public let packageToolsVersion: ToolsVersion
29+
30+
public init(
31+
packagePath: String,
32+
version: String? = nil,
33+
installedToolsVersion: ToolsVersion,
34+
packageToolsVersion: ToolsVersion
35+
) {
36+
self.packagePath = packagePath
37+
self.version = version
38+
self.installedToolsVersion = installedToolsVersion
39+
self.packageToolsVersion = packageToolsVersion
40+
}
41+
42+
public var description: String {
43+
var text = "package at '\(packagePath)'"
44+
if let version = self.version {
45+
text += " @ \(version)"
46+
}
47+
text += " is using Swift tools version \(packageToolsVersion.description) but the installed version is \(installedToolsVersion.description)"
48+
return text
49+
}
50+
}
51+
52+
/// The diagnostic triggered when the package has an unsupported tools version.
53+
public struct UnsupportedToolsVersion: DiagnosticData, Swift.Error {
54+
/// The path of the package.
55+
public let packagePath: String
56+
57+
/// The version of the package.
58+
public let version: String?
59+
60+
/// The current tools version support by the tools.
61+
public let currentToolsVersion: ToolsVersion
62+
63+
/// The tools version of the package.
64+
public let packageToolsVersion: ToolsVersion
65+
66+
fileprivate var hintString: String {
67+
return "consider using '// swift-tools-version:\(currentToolsVersion.major).\(currentToolsVersion.minor)' to specify the current tools version"
68+
}
69+
70+
public init(
71+
packagePath: String,
72+
version: String? = nil,
73+
currentToolsVersion: ToolsVersion,
74+
packageToolsVersion: ToolsVersion
75+
) {
76+
self.packagePath = packagePath
77+
self.version = version
78+
self.currentToolsVersion = currentToolsVersion
79+
self.packageToolsVersion = packageToolsVersion
80+
}
81+
82+
public var description: String {
83+
var text = "package at '\(self.packagePath)'"
84+
if let version = self.version {
85+
text += " @ \(version)"
86+
}
87+
text += " is using Swift tools version \(packageToolsVersion.description) which is no longer supported; \(hintString)"
88+
return text
89+
}
90+
}

Sources/PackageModel/ToolsVersion.swift

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -162,81 +162,3 @@ public struct ToolsVersion: CustomStringConvertible, Comparable, Hashable, Codab
162162
}
163163
}
164164
}
165-
166-
// MARK:- Diagnostics
167-
168-
/// The diagnostic triggered when the package has a newer tools version than the installed tools.
169-
public struct RequireNewerTools: DiagnosticData, Swift.Error {
170-
/// The path of the package.
171-
public let packagePath: String
172-
173-
/// The version of the package.
174-
public let version: String?
175-
176-
/// The installed tools version.
177-
public let installedToolsVersion: ToolsVersion
178-
179-
/// The tools version of the package.
180-
public let packageToolsVersion: ToolsVersion
181-
182-
public init(
183-
packagePath: String,
184-
version: String? = nil,
185-
installedToolsVersion: ToolsVersion,
186-
packageToolsVersion: ToolsVersion
187-
) {
188-
self.packagePath = packagePath
189-
self.version = version
190-
self.installedToolsVersion = installedToolsVersion
191-
self.packageToolsVersion = packageToolsVersion
192-
}
193-
194-
public var description: String {
195-
var text = "package at '\(packagePath)'"
196-
if let version = self.version {
197-
text += " @ \(version)"
198-
}
199-
text += " is using Swift tools version \(packageToolsVersion.description) but the installed version is \(installedToolsVersion.description)"
200-
return text
201-
}
202-
}
203-
204-
/// The diagnostic triggered when the package has an unsupported tools version.
205-
public struct UnsupportedToolsVersion: DiagnosticData, Swift.Error {
206-
/// The path of the package.
207-
public let packagePath: String
208-
209-
/// The version of the package.
210-
public let version: String?
211-
212-
/// The current tools version support by the tools.
213-
public let currentToolsVersion: ToolsVersion
214-
215-
/// The tools version of the package.
216-
public let packageToolsVersion: ToolsVersion
217-
218-
fileprivate var hintString: String {
219-
return "consider using '// swift-tools-version:\(currentToolsVersion.major).\(currentToolsVersion.minor)' to specify the current tools version"
220-
}
221-
222-
public init(
223-
packagePath: String,
224-
version: String? = nil,
225-
currentToolsVersion: ToolsVersion,
226-
packageToolsVersion: ToolsVersion
227-
) {
228-
self.packagePath = packagePath
229-
self.version = version
230-
self.currentToolsVersion = currentToolsVersion
231-
self.packageToolsVersion = packageToolsVersion
232-
}
233-
234-
public var description: String {
235-
var text = "package at '\(self.packagePath)'"
236-
if let version = self.version {
237-
text += " @ \(version)"
238-
}
239-
text += " is using Swift tools version \(packageToolsVersion.description) which is no longer supported; \(hintString)"
240-
return text
241-
}
242-
}

0 commit comments

Comments
 (0)