Generate GraphLoader documentation

This commit is contained in:
Pedro Piñera 2018-04-24 18:07:08 +02:00
parent b8b05815f3
commit 10854dcc9f
5 changed files with 40 additions and 18 deletions

View File

@ -3,24 +3,24 @@ import Foundation
import Utility
enum GenerateCommandError: Error, CustomStringConvertible, Equatable {
static func ==(lhs: GenerateCommandError, rhs: GenerateCommandError) -> Bool {
static func == (_: GenerateCommandError, _: GenerateCommandError) -> Bool {
return true
}
var description: String {
return ""
}
}
public class GenerateCommand: NSObject, Command {
public let command = "generate"
public let overview = "Generates an Xcode workspace to start working on the project."
fileprivate let graphLoaderContext: GraphLoaderContexting
fileprivate let commandsContext: CommandsContexting
/// Path argument.
let pathArgument: OptionArgument<String>
/// Initializes the generate command with the argument parser.
///
/// - Parameter parser: argument parser.
@ -29,7 +29,7 @@ public class GenerateCommand: NSObject, Command {
commandsContext: CommandsContext(),
parser: parser)
}
/// Initializes the command with the printer and the graph loading context.
///
/// - Parameters:
@ -48,12 +48,11 @@ public class GenerateCommand: NSObject, Command {
usage: "The path where the Project.swift file will be generated",
completion: .filename)
}
/// Runs the command.
///
/// - Parameter _: argument parser arguments.
/// - Throws: an error if the command cannot be executed.
public func run(with arguments: ArgumentParser.Result) throws {
public func run(with _: ArgumentParser.Result) throws {
}
}

View File

@ -1,7 +1,18 @@
import Basic
import Foundation
class GraphLoader {
/// Loads the graph that starts at the given path.
protocol GraphLoading: AnyObject {
func load(path: AbsolutePath) throws -> GraphController
}
/// Default graph loader.
class GraphLoader: GraphLoading {
/// Loads the graph at the given path.
///
/// - Parameter path: path where the graph starts from. It's the path where the Workspace.swift or the Project.swift file is.
/// - Returns: a graph controller with that contains the graph representation.
/// - Throws: an error if the graph cannot be loaded.
func load(path: AbsolutePath) throws -> GraphController {
let context = GraphLoaderContext()
if context.fileHandler.exists(path.appending(component: Constants.Manifest.project)) {
@ -13,6 +24,13 @@ class GraphLoader {
}
}
/// Loads a project graph.
///
/// - Parameters:
/// - path: path to the Project.swift.
/// - context: loader context.
/// - Returns: a graph controller with that contains the graph representation.
/// - Throws: an error if the graph cannot be loaded.
fileprivate func loadProject(path: AbsolutePath, context: GraphLoaderContext) throws -> GraphController {
let project = try Project.at(path, context: context)
let entryNodes: [GraphNode] = try project.targets.map({ $0.name }).map { targetName in
@ -21,8 +39,15 @@ class GraphLoader {
return GraphController(cache: context.cache, entryNodes: entryNodes)
}
/// Loads a workspace graph.
///
/// - Parameters:
/// - path: path to the Project.swift.
/// - context: loader context.
/// - Returns: a graph controller with that contains the graph representation.
/// - Throws: an error if the graph cannot be loaded.
fileprivate func loadWorkspace(path: AbsolutePath, context: GraphLoaderContext) throws -> GraphController {
let workspace = try Workspace.parse(from: path, context: context)
let workspace = try Workspace.at(path, context: context)
let projects = try workspace.projects.map { (projectPath) -> (AbsolutePath, Project) in
return try (projectPath, Project.at(projectPath, context: context))
}

View File

@ -14,7 +14,7 @@ class Target: GraphJSONInitiatable, Equatable {
/// Product bundle id.
let bundleId: String
/// Target info plist path.
let infoPlist: AbsolutePath

View File

@ -3,10 +3,9 @@ import Foundation
/// Workspace that references other projects.
class Workspace: Equatable {
/// Workspace name.
let name: String
/// Worskpace projects.
let projects: [AbsolutePath]
@ -26,7 +25,7 @@ class Workspace: Equatable {
/// - context: graph loader context.
/// - Returns: initialized Workspace.
/// - Throws: an error if the workspace cannot be parsed
static func parse(from path: AbsolutePath, context: GraphLoaderContexting) throws -> Workspace {
static func at(_ path: AbsolutePath, context: GraphLoaderContexting) throws -> Workspace {
let workspacePath = path.appending(component: Constants.Manifest.workspace)
if !context.fileHandler.exists(workspacePath) { throw GraphLoadingError.missingFile(workspacePath) }
let json = try context.manifestLoader.load(path: workspacePath, context: context)

View File

@ -1,12 +1,11 @@
import Foundation
class GraphValidator {
let projectValidator: ProjectValidator = ProjectValidator()
func validate(graph: GraphController) {
func validate(graph _: GraphController) {
}
// TODO: Validate invalid platforms.
// TODO: Validate invalid dependencies test -> test
}