forked from nsoperations/Carthage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Constants.swift
120 lines (98 loc) · 5.08 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
111
112
113
114
115
116
117
118
119
120
import Foundation
import Result
/// A struct including all constants.
public struct Constants {
public static var concurrencyLimit: UInt {
return max(1, UInt(ProcessInfo.processInfo.activeProcessorCount))
}
/// Carthage's bundle identifier.
public static let bundleIdentifier: String = "org.carthage.CarthageKit"
/// The name of the folder into which Carthage puts binaries it builds (relative
/// to the working directory).
public static let binariesFolderPath = "Carthage/Build"
/// The relative path to a project's checked out dependencies.
public static let checkoutsPath = "Carthage/Checkouts"
/// 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/build/
public static var derivedDataURL: URL = Constants.userCachesURL.appendingPathComponent("build", 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"
/// The relative path to a project's Cartfile.schemes.
public static let schemesCartfilePath = "Cartfile.schemes"
/// The relative path to the Cartfile.project
public static let projectCartfilePath = "Cartfile.project"
/// Path to the file used to check consistency between Cartfile.resolved and the last bootstrap
public static let resolvedCartfileHashPath = "Carthage/.resolved.md5"
/// 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 binaryAssetPattern = ".framework"
/// MIME types allowed for GitHub Release assets, for them to be considered as
/// binary frameworks.
public static let binaryAssetContentTypes = ["application/zip", "application/octet-stream"]
}
}