|
| 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 | +} |
0 commit comments