Skip to content

Commit e009a93

Browse files
committed
[PackageModel] Provide better error when swift-tools-version is missing
<rdar://problem/50921273> (cherry picked from commit 15bd1b0268c7e662659f8ba1679d4309ebcd52bd)
1 parent 52baad6 commit e009a93

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

Sources/PackageModel/ToolsVersion.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public struct ToolsVersion: CustomStringConvertible, Comparable, Hashable {
106106
throw UnsupportedToolsVersion(
107107
packagePath: packagePath,
108108
version: version,
109-
minimumRequiredToolsVersion: .minimumRequired,
109+
currentToolsVersion: currentToolsVersion,
110110
packageToolsVersion: self
111111
)
112112
}
@@ -280,8 +280,7 @@ public struct UnsupportedToolsVersion: DiagnosticData, Swift.Error {
280280
return text
281281
}, preference: .default)
282282
$0 <<< "is using Swift tools version" <<< { $0.packageToolsVersion.description }
283-
$0 <<< "which is no longer supported; use" <<< { $0.minimumRequiredToolsVersion.description }
284-
$0 <<< "or newer instead"
283+
$0 <<< "which is no longer supported;" <<< { $0.hintString }
285284
})
286285

287286
/// The path of the package.
@@ -290,21 +289,25 @@ public struct UnsupportedToolsVersion: DiagnosticData, Swift.Error {
290289
/// The version of the package.
291290
public let version: String?
292291

293-
/// The tools version required by the package.
294-
public let minimumRequiredToolsVersion: ToolsVersion
292+
/// The current tools version support by the tools.
293+
public let currentToolsVersion: ToolsVersion
295294

296-
/// The current tools version.
295+
/// The tools version of the package.
297296
public let packageToolsVersion: ToolsVersion
298297

298+
fileprivate var hintString: String {
299+
return "consider using '// swift-tools-version:\(currentToolsVersion.major).\(currentToolsVersion.minor)' to specify the current tools version"
300+
}
301+
299302
public init(
300303
packagePath: String,
301304
version: String? = nil,
302-
minimumRequiredToolsVersion: ToolsVersion,
305+
currentToolsVersion: ToolsVersion,
303306
packageToolsVersion: ToolsVersion
304307
) {
305308
self.packagePath = packagePath
306309
self.version = version
307-
self.minimumRequiredToolsVersion = minimumRequiredToolsVersion
310+
self.currentToolsVersion = currentToolsVersion
308311
self.packageToolsVersion = packageToolsVersion
309312
}
310313
}

Tests/PackageGraphTests/RepositoryPackageContainerProviderTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class RepositoryPackageContainerProviderTests: XCTestCase {
348348
_ = try container.getDependencies(at: revision.identifier)
349349
} catch let error as RepositoryPackageContainer.GetDependenciesErrorWrapper {
350350
let error = error.underlyingError as! UnsupportedToolsVersion
351-
XCTAssertMatch(error.description, .and(.prefix("package at '/some-repo' @"), .suffix("is using Swift tools version 3.1.0 which is no longer supported; use 4.0.0 or newer instead")))
351+
XCTAssertMatch(error.description, .and(.prefix("package at '/some-repo' @"), .suffix("is using Swift tools version 3.1.0 which is no longer supported; consider using '// swift-tools-version:4.0' to specify the current tools version")))
352352
}
353353
}
354354
}

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ final class WorkspaceTests: XCTestCase {
14811481
}
14821482
workspace.checkPackageGraph(roots: ["Baz"]) { (graph, diagnostics) in
14831483
DiagnosticsEngineTester(diagnostics) { result in
1484-
result.check(diagnostic: .equal("package at '/tmp/ws/roots/Baz' is using Swift tools version 3.1.0 which is no longer supported; use 4.0.0 or newer instead"), behavior: .error, location: "/tmp/ws/roots/Baz")
1484+
result.check(diagnostic: .equal("package at '/tmp/ws/roots/Baz' is using Swift tools version 3.1.0 which is no longer supported; consider using '// swift-tools-version:4.0' to specify the current tools version"), behavior: .error, location: "/tmp/ws/roots/Baz")
14851485
}
14861486
}
14871487
}

0 commit comments

Comments
 (0)