Skip to content

Commit

Permalink
Add input & output paths for target action
Browse files Browse the repository at this point in the history
  • Loading branch information
Rag0n committed May 14, 2019
1 parent 216028b commit 5f79405
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 23 deletions.
132 changes: 115 additions & 17 deletions Sources/ProjectDescription/TargetAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,28 @@ public struct TargetAction: Codable {
/// Arguments that to be passed.
public let arguments: [String]

/// List of input file paths
public let inputPaths: [String]

/// List of input filelist paths
public let inputFileListPaths: [String]

/// List of output file paths
public let outputPaths: [String]

/// List of output filelist paths
public let outputFileListPaths: [String]

public enum CodingKeys: String, CodingKey {
case name
case tool
case path
case order
case arguments
case inputPaths
case inputFileListPaths
case outputPaths
case outputFileListPaths
}

/// Initializes the target action with its attributes.
Expand All @@ -41,12 +57,22 @@ public struct TargetAction: Codable {
/// - path: Path to the script to execute.
/// - order: Target action order.
/// - arguments: Arguments that to be passed.
init(name: String, tool: String?, path: String?, order: Order, arguments: [String]) {
/// - inputPaths: List of input file paths.
/// - inputFileListPaths: List of input filelist paths.
/// - outputPaths: List of output file paths.
/// - outputFileListPaths: List of output filelist paths.
init(name: String, tool: String?, path: String?, order: Order, arguments: [String],
inputPaths: [String] = [], inputFileListPaths: [String] = [],
outputPaths: [String] = [], outputFileListPaths: [String] = []) {
self.name = name
self.path = path
self.tool = tool
self.order = order
self.arguments = arguments
self.inputPaths = inputPaths
self.inputFileListPaths = inputFileListPaths
self.outputPaths = outputPaths
self.outputFileListPaths = outputFileListPaths
}

/// Returns a target action that gets executed before the sources and resources build phase.
Expand All @@ -55,9 +81,17 @@ public struct TargetAction: Codable {
/// - tool: Name of the tool to execute. Tuist will look up the tool on the environment's PATH.
/// - arguments: Arguments that to be passed.
/// - name: Name of the build phase when the project gets generated.
/// - inputPaths: List of input file paths.
/// - inputFileListPaths: List of input filelist paths.
/// - outputPaths: List of output file paths.
/// - outputFileListPaths: List of output filelist paths.
/// - Returns: Target action.
public static func pre(tool: String, arguments: String..., name: String) -> TargetAction {
return TargetAction(name: name, tool: tool, path: nil, order: .pre, arguments: arguments)
public static func pre(tool: String, arguments: String..., name: String,
inputPaths: [String] = [], inputFileListPaths: [String] = [],
outputPaths: [String] = [], outputFileListPaths: [String] = []) -> TargetAction {
return TargetAction(name: name, tool: tool, path: nil, order: .pre, arguments: arguments,
inputPaths: inputPaths, inputFileListPaths: inputFileListPaths,
outputPaths: outputPaths, outputFileListPaths: outputFileListPaths)
}

/// Returns a target action that gets executed before the sources and resources build phase.
Expand All @@ -66,9 +100,17 @@ public struct TargetAction: Codable {
/// - tool: Name of the tool to execute. Tuist will look up the tool on the environment's PATH.
/// - arguments: Arguments that to be passed.
/// - name: Name of the build phase when the project gets generated.
/// - inputPaths: List of input file paths.
/// - inputFileListPaths: List of input filelist paths.
/// - outputPaths: List of output file paths.
/// - outputFileListPaths: List of output filelist paths.
/// - Returns: Target action.
public static func pre(tool: String, arguments: [String], name: String) -> TargetAction {
return TargetAction(name: name, tool: tool, path: nil, order: .pre, arguments: arguments)
public static func pre(tool: String, arguments: [String], name: String,
inputPaths: [String] = [], inputFileListPaths: [String] = [],
outputPaths: [String] = [], outputFileListPaths: [String] = []) -> TargetAction {
return TargetAction(name: name, tool: tool, path: nil, order: .pre, arguments: arguments,
inputPaths: inputPaths, inputFileListPaths: inputFileListPaths,
outputPaths: outputPaths, outputFileListPaths: outputFileListPaths)
}

/// Returns a target action that gets executed before the sources and resources build phase.
Expand All @@ -77,9 +119,17 @@ public struct TargetAction: Codable {
/// - path: Path to the script to execute.
/// - arguments: Arguments that to be passed.
/// - name: Name of the build phase when the project gets generated.
/// - inputPaths: List of input file paths.
/// - inputFileListPaths: List of input filelist paths.
/// - outputPaths: List of output file paths.
/// - outputFileListPaths: List of output filelist paths.
/// - Returns: Target action.
public static func pre(path: String, arguments: String..., name: String) -> TargetAction {
return TargetAction(name: name, tool: nil, path: path, order: .pre, arguments: arguments)
public static func pre(path: String, arguments: String..., name: String,
inputPaths: [String] = [], inputFileListPaths: [String] = [],
outputPaths: [String] = [], outputFileListPaths: [String] = []) -> TargetAction {
return TargetAction(name: name, tool: nil, path: path, order: .pre, arguments: arguments,
inputPaths: inputPaths, inputFileListPaths: inputFileListPaths,
outputPaths: outputPaths, outputFileListPaths: outputFileListPaths)
}

/// Returns a target action that gets executed before the sources and resources build phase.
Expand All @@ -88,9 +138,17 @@ public struct TargetAction: Codable {
/// - path: Path to the script to execute.
/// - arguments: Arguments that to be passed.
/// - name: Name of the build phase when the project gets generated.
/// - inputPaths: List of input file paths.
/// - inputFileListPaths: List of input filelist paths.
/// - outputPaths: List of output file paths.
/// - outputFileListPaths: List of output filelist paths.
/// - Returns: Target action.
public static func pre(path: String, arguments: [String], name: String) -> TargetAction {
return TargetAction(name: name, tool: nil, path: path, order: .pre, arguments: arguments)
public static func pre(path: String, arguments: [String], name: String,
inputPaths: [String] = [], inputFileListPaths: [String] = [],
outputPaths: [String] = [], outputFileListPaths: [String] = []) -> TargetAction {
return TargetAction(name: name, tool: nil, path: path, order: .pre, arguments: arguments,
inputPaths: inputPaths, inputFileListPaths: inputFileListPaths,
outputPaths: outputPaths, outputFileListPaths: outputFileListPaths)
}

/// Returns a target action that gets executed after the sources and resources build phase.
Expand All @@ -99,9 +157,17 @@ public struct TargetAction: Codable {
/// - tool: Name of the tool to execute. Tuist will look up the tool on the environment's PATH.
/// - arguments: Arguments that to be passed.
/// - name: Name of the build phase when the project gets generated.
/// - inputPaths: List of input file paths.
/// - inputFileListPaths: List of input filelist paths.
/// - outputPaths: List of output file paths.
/// - outputFileListPaths: List of output filelist paths.
/// - Returns: Target action.
public static func post(tool: String, arguments: String..., name: String) -> TargetAction {
return TargetAction(name: name, tool: tool, path: nil, order: .post, arguments: arguments)
public static func post(tool: String, arguments: String..., name: String,
inputPaths: [String] = [], inputFileListPaths: [String] = [],
outputPaths: [String] = [], outputFileListPaths: [String] = []) -> TargetAction {
return TargetAction(name: name, tool: tool, path: nil, order: .post, arguments: arguments,
inputPaths: inputPaths, inputFileListPaths: inputFileListPaths,
outputPaths: outputPaths, outputFileListPaths: outputFileListPaths)
}

/// Returns a target action that gets executed after the sources and resources build phase.
Expand All @@ -110,9 +176,17 @@ public struct TargetAction: Codable {
/// - tool: Name of the tool to execute. Tuist will look up the tool on the environment's PATH.
/// - arguments: Arguments that to be passed.
/// - name: Name of the build phase when the project gets generated.
/// - inputPaths: List of input file paths.
/// - inputFileListPaths: List of input filelist paths.
/// - outputPaths: List of output file paths.
/// - outputFileListPaths: List of output filelist paths.
/// - Returns: Target action.
public static func post(tool: String, arguments: [String], name: String) -> TargetAction {
return TargetAction(name: name, tool: tool, path: nil, order: .post, arguments: arguments)
public static func post(tool: String, arguments: [String], name: String,
inputPaths: [String] = [], inputFileListPaths: [String] = [],
outputPaths: [String] = [], outputFileListPaths: [String] = []) -> TargetAction {
return TargetAction(name: name, tool: tool, path: nil, order: .post, arguments: arguments,
inputPaths: inputPaths, inputFileListPaths: inputFileListPaths,
outputPaths: outputPaths, outputFileListPaths: outputFileListPaths)
}

/// Returns a target action that gets executed after the sources and resources build phase.
Expand All @@ -121,9 +195,17 @@ public struct TargetAction: Codable {
/// - path: Path to the script to execute.
/// - arguments: Arguments that to be passed.
/// - name: Name of the build phase when the project gets generated.
/// - inputPaths: List of input file paths.
/// - inputFileListPaths: List of input filelist paths.
/// - outputPaths: List of output file paths.
/// - outputFileListPaths: List of output filelist paths.
/// - Returns: Target action.
public static func post(path: String, arguments: String..., name: String) -> TargetAction {
return TargetAction(name: name, tool: nil, path: path, order: .post, arguments: arguments)
public static func post(path: String, arguments: String..., name: String,
inputPaths: [String] = [], inputFileListPaths: [String] = [],
outputPaths: [String] = [], outputFileListPaths: [String] = []) -> TargetAction {
return TargetAction(name: name, tool: nil, path: path, order: .post, arguments: arguments,
inputPaths: inputPaths, inputFileListPaths: inputFileListPaths,
outputPaths: outputPaths, outputFileListPaths: outputFileListPaths)
}

/// Returns a target action that gets executed after the sources and resources build phase.
Expand All @@ -132,9 +214,17 @@ public struct TargetAction: Codable {
/// - path: Path to the script to execute.
/// - arguments: Arguments that to be passed.
/// - name: Name of the build phase when the project gets generated.
/// - inputPaths: List of input file paths.
/// - inputFileListPaths: List of input filelist paths.
/// - outputPaths: List of output file paths.
/// - outputFileListPaths: List of output filelist paths.
/// - Returns: Target action.
public static func post(path: String, arguments: [String], name: String) -> TargetAction {
return TargetAction(name: name, tool: nil, path: path, order: .post, arguments: arguments)
public static func post(path: String, arguments: [String], name: String,
inputPaths: [String] = [], inputFileListPaths: [String] = [],
outputPaths: [String] = [], outputFileListPaths: [String] = []) -> TargetAction {
return TargetAction(name: name, tool: nil, path: path, order: .post, arguments: arguments,
inputPaths: inputPaths, inputFileListPaths: inputFileListPaths,
outputPaths: outputPaths, outputFileListPaths: outputFileListPaths)
}

// MARK: - Codable
Expand All @@ -144,6 +234,10 @@ public struct TargetAction: Codable {
name = try container.decode(String.self, forKey: .name)
order = try container.decode(Order.self, forKey: .order)
arguments = try container.decode([String].self, forKey: .arguments)
inputPaths = try container.decodeIfPresent([String].self, forKey: .inputPaths) ?? []
inputFileListPaths = try container.decodeIfPresent([String].self, forKey: .inputFileListPaths) ?? []
outputPaths = try container.decodeIfPresent([String].self, forKey: .outputPaths) ?? []
outputFileListPaths = try container.decodeIfPresent([String].self, forKey: .outputFileListPaths) ?? []
if let path = try container.decodeIfPresent(String.self, forKey: .path) {
self.path = path
tool = nil
Expand All @@ -159,6 +253,10 @@ public struct TargetAction: Codable {
try container.encode(name, forKey: .name)
try container.encode(order, forKey: .order)
try container.encode(arguments, forKey: .arguments)
try container.encode(inputPaths, forKey: .inputPaths)
try container.encode(inputFileListPaths, forKey: .inputFileListPaths)
try container.encode(outputPaths, forKey: .outputPaths)
try container.encode(outputFileListPaths, forKey: .outputFileListPaths)

if let tool = tool {
try container.encode(tool, forKey: .tool)
Expand Down
8 changes: 4 additions & 4 deletions Sources/TuistGenerator/Generator/BuildPhaseGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ final class BuildPhaseGenerator: BuildPhaseGenerating {
try actions.forEach { action in
let buildPhase = try PBXShellScriptBuildPhase(files: [],
name: action.name,
inputPaths: [],
outputPaths: [],
inputFileListPaths: [],
outputFileListPaths: [],
inputPaths: action.inputPaths,
outputPaths: action.outputPaths,
inputFileListPaths: action.inputFileListPaths,
outputFileListPaths: action.outputFileListPaths,
shellPath: "/bin/sh",
shellScript: action.shellScript(sourceRootPath: sourceRootPath))
pbxproj.add(object: buildPhase)
Expand Down
26 changes: 25 additions & 1 deletion Sources/TuistGenerator/Models/TargetAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ public struct TargetAction {
/// Arguments that to be passed
public let arguments: [String]

/// List of input file paths
public let inputPaths: [String]

/// List of input filelist paths
public let inputFileListPaths: [String]

/// List of output file paths
public let outputPaths: [String]

/// List of output filelist paths
public let outputFileListPaths: [String]

/// Initializes a new target action with its attributes.
///
/// - Parameters:
Expand All @@ -36,16 +48,28 @@ public struct TargetAction {
/// - tool: Name of the tool to execute. Tuist will look up the tool on the environment's PATH
/// - path: Path to the script to execute
/// - arguments: Arguments that to be passed
/// - inputPaths: List of input file paths
/// - inputFileListPaths: List of input filelist paths
/// - outputPaths: List of output file paths
/// - outputFileListPaths: List of output filelist paths
public init(name: String,
order: Order,
tool: String? = nil,
path: AbsolutePath? = nil,
arguments: [String] = []) {
arguments: [String] = [],
inputPaths: [String] = [],
inputFileListPaths: [String] = [],
outputPaths: [String] = [],
outputFileListPaths: [String] = []) {
self.name = name
self.order = order
self.tool = tool
self.path = path
self.arguments = arguments
self.inputPaths = inputPaths
self.inputFileListPaths = inputFileListPaths
self.outputPaths = outputPaths
self.outputFileListPaths = outputFileListPaths
}

/// Returns the shell script that should be used in the target build phase.
Expand Down
8 changes: 7 additions & 1 deletion Sources/TuistKit/Generator/GeneratorModelLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,13 @@ extension TuistGenerator.TargetAction {
let order = TuistGenerator.TargetAction.Order.from(manifest: manifest.order)
let path = manifest.path.map { AbsolutePath($0, relativeTo: path) }
let arguments = manifest.arguments
return TargetAction(name: name, order: order, tool: tool, path: path, arguments: arguments)
let inputPaths = manifest.inputPaths
let inputFileListPaths = manifest.inputFileListPaths
let outputPaths = manifest.outputPaths
let outputFileListPaths = manifest.outputFileListPaths
return TargetAction(name: name, order: order, tool: tool, path: path1, arguments: arguments,
inputPaths: inputPaths, inputFileListPaths: inputFileListPaths,
outputPaths: outputPaths, outputFileListPaths: outputFileListPaths)
}
}

Expand Down

0 comments on commit 5f79405

Please sign in to comment.