Support SourceFileLists in TargetActions (#2686)
This commit is contained in:
parent
e23164569d
commit
38e41607d4
|
@ -7,6 +7,7 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/
|
|||
### Changed
|
||||
|
||||
- Add missing disabling of swiftformat and swift-format [#2795](https://github.com/tuist/tuist/pull/2795) by [@fortmarek](https://github.com/fortmarek)
|
||||
- Add support for globbing in build phase input file and file lists as well as output and output file lists. [#2686](https://github.com/tuist/tuist/pull/2686) by [@FranzBusch](https://github.com/FranzBusch)
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -13,10 +13,10 @@ extension TuistGraph.TargetAction {
|
|||
static func from(manifest: ProjectDescription.TargetAction, generatorPaths: GeneratorPaths) throws -> TuistGraph.TargetAction {
|
||||
let name = manifest.name
|
||||
let order = TuistGraph.TargetAction.Order.from(manifest: manifest.order)
|
||||
let inputPaths = try manifest.inputPaths.map { try generatorPaths.resolve(path: $0) }
|
||||
let inputFileListPaths = try manifest.inputFileListPaths.map { try generatorPaths.resolve(path: $0) }
|
||||
let outputPaths = try manifest.outputPaths.map { try generatorPaths.resolve(path: $0) }
|
||||
let outputFileListPaths = try manifest.outputFileListPaths.map { try generatorPaths.resolve(path: $0) }
|
||||
let inputPaths = try absolutePaths(for: manifest.inputPaths, generatorPaths: generatorPaths)
|
||||
let inputFileListPaths = try absolutePaths(for: manifest.inputFileListPaths, generatorPaths: generatorPaths)
|
||||
let outputPaths = try absolutePaths(for: manifest.outputPaths, generatorPaths: generatorPaths)
|
||||
let outputFileListPaths = try absolutePaths(for: manifest.outputFileListPaths, generatorPaths: generatorPaths)
|
||||
let basedOnDependencyAnalysis = manifest.basedOnDependencyAnalysis
|
||||
|
||||
let script: TuistGraph.TargetAction.Script
|
||||
|
@ -43,6 +43,18 @@ extension TuistGraph.TargetAction {
|
|||
basedOnDependencyAnalysis: basedOnDependencyAnalysis
|
||||
)
|
||||
}
|
||||
|
||||
private static func absolutePaths(for paths: [Path], generatorPaths: GeneratorPaths) throws -> [AbsolutePath] {
|
||||
try paths.map { (path: Path) -> [AbsolutePath] in
|
||||
// avoid globbing paths that contain variables
|
||||
if path.pathString.contains("$") {
|
||||
return [try generatorPaths.resolve(path: path)]
|
||||
}
|
||||
let absolutePath = try generatorPaths.resolve(path: path)
|
||||
let base = AbsolutePath(absolutePath.dirname)
|
||||
return try base.throwingGlob(absolutePath.basename)
|
||||
}.reduce([], +)
|
||||
}
|
||||
}
|
||||
|
||||
extension TuistGraph.TargetAction.Order {
|
||||
|
|
|
@ -93,12 +93,20 @@ extension TargetAction {
|
|||
public static func test(name: String = "Action",
|
||||
tool: String = "",
|
||||
order: Order = .pre,
|
||||
arguments: [String] = []) -> TargetAction
|
||||
arguments: [String] = [],
|
||||
inputPaths: [Path] = [],
|
||||
inputFileListPaths: [Path] = [],
|
||||
outputPaths: [Path] = [],
|
||||
outputFileListPaths: [Path] = []) -> TargetAction
|
||||
{
|
||||
TargetAction(
|
||||
name: name,
|
||||
script: .tool(tool, arguments),
|
||||
order: order
|
||||
order: order,
|
||||
inputPaths: inputPaths,
|
||||
inputFileListPaths: inputFileListPaths,
|
||||
outputPaths: outputPaths,
|
||||
outputFileListPaths: outputFileListPaths
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,4 +28,31 @@ final class TargetActionManifestMapperTests: TuistUnitTestCase {
|
|||
XCTAssertEqual(model.script, .tool("my_tool", ["arg1", "arg2"]))
|
||||
XCTAssertEqual(model.order, .pre)
|
||||
}
|
||||
|
||||
func test_doesntGlob_whenVariable() throws {
|
||||
// Given
|
||||
let temporaryPath = try self.temporaryPath()
|
||||
let generatorPaths = GeneratorPaths(manifestDirectory: temporaryPath)
|
||||
let manifest = ProjectDescription.TargetAction.test(
|
||||
name: "MyScript",
|
||||
tool: "my_tool",
|
||||
order: .pre,
|
||||
arguments: ["arg1", "arg2"],
|
||||
inputPaths: ["$(SRCROOT)/foo/bar/**/*.swift"],
|
||||
inputFileListPaths: ["$(SRCROOT)/foo/bar/**/*.swift"],
|
||||
outputPaths: ["$(SRCROOT)/foo/bar/**/*.swift"],
|
||||
outputFileListPaths: ["$(SRCROOT)/foo/bar/**/*.swift"]
|
||||
)
|
||||
// When
|
||||
let model = try TuistGraph.TargetAction.from(manifest: manifest, generatorPaths: generatorPaths)
|
||||
|
||||
// Then
|
||||
XCTAssertEqual(model.name, "MyScript")
|
||||
XCTAssertEqual(model.script, .tool("my_tool", ["arg1", "arg2"]))
|
||||
XCTAssertEqual(model.order, .pre)
|
||||
XCTAssertEqual(model.inputPaths, [temporaryPath.appending(RelativePath("$(SRCROOT)/foo/bar/**/*.swift"))])
|
||||
XCTAssertEqual(model.inputFileListPaths, [temporaryPath.appending(RelativePath("$(SRCROOT)/foo/bar/**/*.swift"))])
|
||||
XCTAssertEqual(model.outputPaths, [temporaryPath.appending(RelativePath("$(SRCROOT)/foo/bar/**/*.swift"))])
|
||||
XCTAssertEqual(model.outputFileListPaths, [temporaryPath.appending(RelativePath("$(SRCROOT)/foo/bar/**/*.swift"))])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ let project = Project(name: "App",
|
|||
infoPlist: "Info.plist",
|
||||
sources: ["Sources/**"],
|
||||
actions: [
|
||||
.pre(tool: "/bin/echo", arguments: ["\"tuist\""], name: "Tuist"),
|
||||
.pre(tool: "/bin/echo", arguments: ["\"tuist\""], name: "Tuist", inputPaths: ["Sources/**/*.swift"]),
|
||||
.post(tool: "/bin/echo", arguments: ["rocks"], name: "Rocks"),
|
||||
.pre(path: "script.sh", name: "Run script"),
|
||||
.pre(script: "echo 'Hello World'", name: "Embedded script"),
|
||||
|
|
Loading…
Reference in New Issue