-
-
Notifications
You must be signed in to change notification settings - Fork 506
/
Generator.swift
125 lines (113 loc) · 6.58 KB
/
Generator.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
121
122
123
124
125
import Basic
import Foundation
import TuistCore
/// A component responsible for generating Xcode projects & workspaces
public protocol Generating {
/// Generates an Xcode project at a given path. Only the specified project is generated (excluding its dependencies).
///
/// - Parameters:
/// - path: The absolute path to the directory where an Xcode project should be generated
/// - Returns: An absolute path to the generated Xcode project many of which adopt `FatalError`
/// - Throws: Errors encountered during the generation process
/// - seealso: TuistCore.FatalError
func generateProject(at path: AbsolutePath) throws -> AbsolutePath
/// Generate an Xcode workspace for the project at a given path. All the project's dependencies will also be generated and included.
///
/// - Parameters:
/// - path: The absolute path to the directory where an Xcode workspace should be generated
/// (e.g. /path/to/directory)
/// - workspaceFiles: Additional files to include in the final generated workspace
/// - Returns: An absolute path to the generated Xcode workspace
/// (e.g. /path/to/directory/project.xcodeproj)
/// - Throws: Errors encountered during the generation process
/// many of which adopt `FatalError`
/// - seealso: TuistCore.FatalError
@discardableResult
func generateProjectWorkspace(at path: AbsolutePath, workspaceFiles: [AbsolutePath]) throws -> AbsolutePath
/// Generate an Xcode workspace at a given path. All referenced projects and their dependencies will be generated and included.
///
/// - Parameters:
/// - path: The absolute path to the directory where an Xcode workspace should be generated
/// (e.g. /path/to/directory)
/// - workspaceFiles: Additional files to include in the final generated workspace
/// - Returns: An absolute path to the generated Xcode workspace
/// (e.g. /path/to/directory/project.xcodeproj)
/// - Throws: Errors encountered during the generation process
/// many of which adopt `FatalError`
/// - seealso: TuistCore.FatalError
@discardableResult
func generateWorkspace(at path: AbsolutePath, workspaceFiles: [AbsolutePath]) throws -> AbsolutePath
}
/// A default implementation of `Generating`
///
/// - seealso: Generating
/// - seealso: GeneratorModelLoading
public class Generator: Generating {
private let graphLoader: GraphLoading
private let workspaceGenerator: WorkspaceGenerating
private let projectGenerator: ProjectGenerating
public convenience init(system: Systeming = System(),
printer: Printing = Printer(),
fileHandler: FileHandling = FileHandler(),
defaultSettingsProvider: DefaultSettingsProviding = DefaultSettingsProvider(),
modelLoader: GeneratorModelLoading) {
let graphLinter = GraphLinter(fileHandler: fileHandler)
let graphLoader = GraphLoader(linter: graphLinter, printer: printer, fileHandler: fileHandler, modelLoader: modelLoader)
let configGenerator = ConfigGenerator(defaultSettingsProvider: defaultSettingsProvider)
let targetGenerator = TargetGenerator(configGenerator: configGenerator)
let projectGenerator = ProjectGenerator(targetGenerator: targetGenerator,
configGenerator: configGenerator,
printer: printer,
system: system,
fileHandler: fileHandler)
let workspaceStructureGenerator = WorkspaceStructureGenerator(fileHandler: fileHandler)
let cocoapodsInteractor = CocoaPodsInteractor()
let workspaceGenerator = WorkspaceGenerator(system: system,
printer: printer,
projectGenerator: projectGenerator,
fileHandler: fileHandler,
workspaceStructureGenerator: workspaceStructureGenerator,
cocoapodsInteractor: cocoapodsInteractor)
self.init(graphLoader: graphLoader,
workspaceGenerator: workspaceGenerator,
projectGenerator: projectGenerator)
}
init(graphLoader: GraphLoading,
workspaceGenerator: WorkspaceGenerating,
projectGenerator: ProjectGenerating) {
self.graphLoader = graphLoader
self.workspaceGenerator = workspaceGenerator
self.projectGenerator = projectGenerator
}
public func generateProject(at path: AbsolutePath) throws -> AbsolutePath {
let (graph, project) = try graphLoader.loadProject(path: path)
let generatedProject = try projectGenerator.generate(project: project,
graph: graph,
sourceRootPath: path)
return generatedProject.path
}
public func generateProjectWorkspace(at path: AbsolutePath,
workspaceFiles: [AbsolutePath]) throws -> AbsolutePath {
let tuistConfig = try graphLoader.loadTuistConfig(path: path)
let (graph, project) = try graphLoader.loadProject(path: path)
let workspace = Workspace(name: project.fileName,
projects: graph.projectPaths,
additionalFiles: workspaceFiles.map(FileElement.file))
return try workspaceGenerator.generate(workspace: workspace,
path: path,
graph: graph,
tuistConfig: tuistConfig)
}
public func generateWorkspace(at path: AbsolutePath,
workspaceFiles: [AbsolutePath]) throws -> AbsolutePath {
let (graph, workspace) = try graphLoader.loadWorkspace(path: path)
let tuistConfig = try graphLoader.loadTuistConfig(path: path)
let updatedWorkspace = workspace
.merging(projects: graph.projectPaths)
.adding(files: workspaceFiles)
return try workspaceGenerator.generate(workspace: updatedWorkspace,
path: path,
graph: graph,
tuistConfig: tuistConfig)
}
}