-
-
Notifications
You must be signed in to change notification settings - Fork 506
/
TuistConfig.swift
62 lines (52 loc) · 1.96 KB
/
TuistConfig.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
import Basic
import Foundation
import TuistCore
/// This model allows to configure Tuist.
public class TuistConfig: Equatable, Hashable {
/// Contains options related to the project generation.
///
/// - generateManifestElement: When passed, Tuist generates the projects, targets and schemes to compile the project manifest.
public enum GenerationOption: Hashable, Equatable {
case generateManifest
case xcodeProjectName(String)
}
/// Generation options.
public let generationOptions: [GenerationOption]
/// Returns the default Tuist configuration.
public static var `default`: TuistConfig {
return TuistConfig(generationOptions: [.generateManifest])
}
/// Initializes the tuist cofiguration.
///
/// - Parameters:
/// - generationOptions: Generation options.
public init(generationOptions: [GenerationOption]) {
self.generationOptions = generationOptions
}
static func at(_ path: AbsolutePath, cache: GraphLoaderCaching, modelLoader: GeneratorModelLoading, fileHandler _: FileHandling) throws -> TuistConfig {
if let tuistConfig = cache.tuistConfig(path) {
return tuistConfig
} else {
let tuistConfig = try modelLoader.loadTuistConfig(at: path)
cache.add(tuistConfig: tuistConfig, path: path)
return tuistConfig
}
}
// MARK: - Hashable
public func hash(into hasher: inout Hasher) {
hasher.combine(generationOptions)
}
// MARK: - Equatable
public static func == (lhs: TuistConfig, rhs: TuistConfig) -> Bool {
return lhs.generationOptions == rhs.generationOptions
}
}
public func == (lhs: TuistConfig.GenerationOption, rhs: TuistConfig.GenerationOption) -> Bool {
switch (lhs, rhs) {
case (.generateManifest, .generateManifest):
return true
case let (.xcodeProjectName(lhs), .xcodeProjectName(rhs)):
return lhs == rhs
default: return false
}
}