forked from swiftlang/swiftly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlatform.swift
90 lines (74 loc) · 3.67 KB
/
Platform.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import Foundation
public protocol Platform {
/// The platform-specific location on disk where applications are
/// supposed to store their custom data.
var appDataDirectory: URL { get }
/// The file extension of the downloaded toolchain for this platform.
/// e.g. for Linux systems this is "tar.gz" and on macOS it's "pkg".
var toolchainFileExtension: String { get }
/// Checks whether a given system dependency has been installed yet or not.
/// This will only really be used on Linux.
func isSystemDependencyPresent(_ dependency: SystemDependency) -> Bool
/// Installs a toolchain from a file on disk pointed to by the given URL.
/// After this completes, a user can “use” the toolchain.
func install(from: URL, version: ToolchainVersion) throws
/// Uninstalls a toolchain associated with the given version.
/// If this version is in use, the next latest version will be used afterwards.
func uninstall(_ version: ToolchainVersion) throws
/// Select the toolchain associated with the given version.
/// Returns whether the selection was successful.
func use(_ version: ToolchainVersion, currentToolchain: ToolchainVersion?) throws -> Bool
/// Clear the current active toolchain.
func unUse(currentToolchain: ToolchainVersion) throws
/// Get a list of snapshot builds for the platform. If a version is specified, only
/// return snapshots associated with the version.
/// This will likely have a default implementation.
func listAvailableSnapshots(version: String?) async -> [Snapshot]
/// Update swiftly itself, if a new version has been released.
/// This will likely have a default implementation.
func selfUpdate() async throws
/// Get a path pointing to a unique, temporary file.
/// This does not need to actually create the file.
func getTempFilePath() -> URL
}
extension Platform {
/// The location on disk where swiftly will store its configuration, installed toolchains, and symlinks to
/// the active location.
///
/// The structure of this directory looks like the following:
///
/// ```
/// homeDir/
/// |
/// -- toolchains/
/// |
/// -- config.json
/// ```
///
public var swiftlyHomeDir: URL {
SwiftlyCore.mockedHomeDir
?? ProcessInfo.processInfo.environment["SWIFTLY_HOME_DIR"].map { URL(fileURLWithPath: $0) }
?? self.appDataDirectory.appendingPathComponent("swiftly", isDirectory: true)
}
/// The directory which stores the swiftly executable itself as well as symlinks
/// to executables in the "bin" directory of the active toolchain.
///
/// If a mocked home directory is set, this will be the "bin" subdirectory of the home directory.
/// If not, this will be the SWIFTLY_BIN_DIR environment variable if set. If that's also unset,
/// this will default to /usr/local/bin.
public var swiftlyBinDir: URL {
SwiftlyCore.mockedHomeDir.map { $0.appendingPathComponent("bin", isDirectory: true) } ??
ProcessInfo.processInfo.environment["SWIFTLY_BIN_DIR"].map { URL(fileURLWithPath: $0) } ??
URL(fileURLWithPath: "/usr/local/bin")
}
/// The "toolchains" subdirectory of swiftly's home directory. Contains the Swift toolchains managed by swiftly.
public var swiftlyToolchainsDir: URL {
self.swiftlyHomeDir.appendingPathComponent("toolchains", isDirectory: true)
}
/// The URL of the configuration file in swiftly's home directory.
public var swiftlyConfigFile: URL {
self.swiftlyHomeDir.appendingPathComponent("config.json")
}
}
public struct SystemDependency {}
public struct Snapshot: Decodable {}