Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input & output paths for target action #353

Merged
merged 6 commits into from Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/
### Added
- `DefaultSettings.none` to disable the generation of default build settings https://github.com/tuist/tuist/pull/395 by @pepibumur.
- Version information for tuistenv https://github.com/tuist/tuist/pull/399 by @ollieatkinson
- Add input & output paths for target action https://github.com/tuist/tuist/pull/353 by Rag0n

### Fixed

Expand Down
218 changes: 201 additions & 17 deletions Sources/ProjectDescription/TargetAction.swift
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,28 @@ 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 +87,27 @@ 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 +116,27 @@ 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 +145,27 @@ 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 +174,27 @@ 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 +203,27 @@ 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 +232,27 @@ 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 +261,27 @@ 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 +290,27 @@ 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 +320,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 +339,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
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
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