forked from Carthage/Carthage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Constants.swift
110 lines (93 loc) · 4.14 KB
/
Constants.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import Foundation
import Result
import Tentacle
/// A struct including all constants.
public struct Constants {
/// Carthage's bundle identifier.
public static let bundleIdentifier: String = "org.carthage.CarthageKit"
/// The name of the folder into which Carthage puts checked out dependencies (relative
/// to the working directory).
public static let checkoutsFolderPath = "Carthage/Checkouts"
/// The name of the folder into which Carthage puts binaries it builds (relative
/// to the working directory).
public static let binariesFolderPath = "Carthage/Build"
/// The fallback dependencies URL to be used in case
/// the intended ~/Library/Caches/org.carthage.CarthageKit cannot
/// be found or created.
private static let fallbackDependenciesURL: URL = {
let homePath: String
if let homeEnvValue = ProcessInfo.processInfo.environment["HOME"] {
homePath = (homeEnvValue as NSString).appendingPathComponent(".carthage")
} else {
homePath = ("~/.carthage" as NSString).expandingTildeInPath
}
return URL(fileURLWithPath: homePath, isDirectory: true)
}()
/// ~/Library/Caches/org.carthage.CarthageKit/
private static let userCachesURL: URL = {
let fileManager = FileManager.default
let urlResult: Result<URL, NSError> = Result(catching: {
try fileManager.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
}).flatMap { cachesURL in
let dependenciesURL = cachesURL.appendingPathComponent(Constants.bundleIdentifier, isDirectory: true)
let dependenciesPath = dependenciesURL.absoluteString
if fileManager.fileExists(atPath: dependenciesPath, isDirectory: nil) {
if fileManager.isWritableFile(atPath: dependenciesPath) {
return Result(value: dependenciesURL)
} else {
let error = NSError(domain: Constants.bundleIdentifier, code: 0, userInfo: nil)
return Result(error: error)
}
} else {
return Result(catching: {
try fileManager.createDirectory(
at: dependenciesURL,
withIntermediateDirectories: true,
attributes: [FileAttributeKey.posixPermissions: 0o755]
)
return dependenciesURL
})
}
}
switch urlResult {
case let .success(url):
_ = try? FileManager.default.removeItem(at: Constants.fallbackDependenciesURL)
return url
case let .failure(error):
NSLog("Warning: No Caches directory could be found or created: \(error.localizedDescription). (\(error))")
return Constants.fallbackDependenciesURL
}
}()
public struct Dependency {
/// The file URL to the directory in which downloaded release binaries will be
/// stored.
///
/// ~/Library/Caches/org.carthage.CarthageKit/binaries/
public static var assetsURL: URL = Constants.userCachesURL.appendingPathComponent("binaries", isDirectory: true)
/// The file URL to the directory in which cloned dependencies will be stored.
///
/// ~/Library/Caches/org.carthage.CarthageKit/dependencies/
public static var repositoriesURL: URL = Constants.userCachesURL.appendingPathComponent("dependencies", isDirectory: true)
/// The file URL to the directory in which per-dependency derived data
/// directories will be stored.
///
/// ~/Library/Caches/org.carthage.CarthageKit/DerivedData/
public static var derivedDataURL: URL = Constants.userCachesURL.appendingPathComponent("DerivedData", isDirectory: true)
}
public struct Project {
/// The relative path to a project's Cartfile.
public static let cartfilePath = "Cartfile"
/// The relative path to a project's Cartfile.private.
public static let privateCartfilePath = "Cartfile.private"
/// The relative path to a project's Cartfile.resolved.
public static let resolvedCartfilePath = "Cartfile.resolved"
// TODO: Deprecate this.
/// The text that needs to exist in a GitHub Release asset's name, for it to be
/// tried as a binary framework.
public static let frameworkBinaryAssetPattern = ".framework"
public static let xcframeworkBinaryAssetPattern = ".xcframework"
/// MIME types allowed for GitHub Release assets, for them to be considered as
/// binary frameworks.
public static let binaryAssetContentTypes = ["application/zip", "application/x-zip-compressed", "application/octet-stream"]
}
}