From a80500c605384712ae846f89e9c41212370d6e62 Mon Sep 17 00:00:00 2001 From: SooHwanCho <51935215+JCSooHwanCho@users.noreply.github.com> Date: Sat, 29 Apr 2023 06:32:06 +0900 Subject: [PATCH] Support for custom shell path in `ExecuteAction` (#5154) * bump up Xcodeproj to 8.9.0 * add shellPath property at ExecuteAction * update changelog * run lint * update pull request link * match changelog with PR title * remove changes in changelog (it will be auto-generated) * update shellPath comment * update fixture to use shellPath in ExecutionAction * bump up XcodeProj to 8.10.0 --- Package.resolved | 4 +-- Package.swift | 2 +- .../ProjectDescription/ExecuteAction.swift | 6 +++- .../SchemeDescriptorsGenerator.swift | 2 ++ .../TuistGraph/Models/ExecutionAction.swift | 4 +++ .../ExecutionAction+ManifestMapper.swift | 7 +++- .../ProjectDescriptionTests/SchemeTests.swift | 3 +- .../SchemeDescriptorsGeneratorTests.swift | 35 ++++++++++++++----- .../Linter/SchemeLinterTests.swift | 3 +- .../Models/ArchiveActionTests.swift | 2 ++ .../Models/BuildActionTests.swift | 2 ++ .../Models/ExecutionActionTests.swift | 1 + .../Generator/TestModelGenerator.swift | 8 ++++- Tuist/Dependencies.swift | 2 +- Tuist/Dependencies/Lockfiles/Package.resolved | 4 +-- .../Workspace.swift | 10 +++--- 16 files changed, 71 insertions(+), 24 deletions(-) diff --git a/Package.resolved b/Package.resolved index 334e9dbad..4c80979da 100644 --- a/Package.resolved +++ b/Package.resolved @@ -265,8 +265,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tuist/XcodeProj.git", "state" : { - "revision" : "b6de1bfe021b861c94e7c83821b595083f74b997", - "version" : "8.8.0" + "revision" : "5fdac93cb4a7fd4bad5ac2da34e5bc878263043f", + "version" : "8.10.0" } }, { diff --git a/Package.swift b/Package.swift index b26d5951c..056815982 100644 --- a/Package.swift +++ b/Package.swift @@ -62,7 +62,7 @@ let package = Package( .package(url: "https://github.com/SwiftDocOrg/GraphViz.git", exact: "0.2.0"), .package(url: "https://github.com/SwiftGen/StencilSwiftKit.git", exact: "2.9.0"), .package(url: "https://github.com/SwiftGen/SwiftGen", exact: "6.5.1"), - .package(url: "https://github.com/tuist/XcodeProj.git", exact: "8.8.0"), + .package(url: "https://github.com/tuist/XcodeProj.git", exact: "8.10.0"), ], targets: [ .target( diff --git a/Sources/ProjectDescription/ExecuteAction.swift b/Sources/ProjectDescription/ExecuteAction.swift index 4a519af19..b9aca03db 100644 --- a/Sources/ProjectDescription/ExecuteAction.swift +++ b/Sources/ProjectDescription/ExecuteAction.swift @@ -6,9 +6,13 @@ public struct ExecutionAction: Equatable, Codable { public let scriptText: String public let target: TargetReference? - public init(title: String = "Run Script", scriptText: String, target: TargetReference? = nil) { + /// The path to the shell which shall execute this script. if it is nil, Xcode will use default value. + public let shellPath: String? + + public init(title: String = "Run Script", scriptText: String, target: TargetReference? = nil, shellPath: String? = nil) { self.title = title self.scriptText = scriptText self.target = target + self.shellPath = shellPath } } diff --git a/Sources/TuistGenerator/Generator/SchemeDescriptorsGenerator.swift b/Sources/TuistGenerator/Generator/SchemeDescriptorsGenerator.swift index 5793338a7..752066a55 100644 --- a/Sources/TuistGenerator/Generator/SchemeDescriptorsGenerator.swift +++ b/Sources/TuistGenerator/Generator/SchemeDescriptorsGenerator.swift @@ -731,6 +731,7 @@ final class SchemeDescriptorsGenerator: SchemeDescriptorsGenerating { return XCScheme.ExecutionAction( scriptText: action.scriptText, title: action.title, + shellToInvoke: action.shellPath, environmentBuildable: nil ) } @@ -745,6 +746,7 @@ final class SchemeDescriptorsGenerator: SchemeDescriptorsGenerating { return XCScheme.ExecutionAction( scriptText: action.scriptText, title: action.title, + shellToInvoke: action.shellPath, environmentBuildable: buildableReference ) } diff --git a/Sources/TuistGraph/Models/ExecutionAction.swift b/Sources/TuistGraph/Models/ExecutionAction.swift index 75c5f0ebc..9aed0a329 100644 --- a/Sources/TuistGraph/Models/ExecutionAction.swift +++ b/Sources/TuistGraph/Models/ExecutionAction.swift @@ -11,6 +11,8 @@ public struct ExecutionAction: Equatable, Codable { public let scriptText: String /// Name of the build or test target that will provide the action's build settings. public let target: TargetReference? + /// The path to the shell which shall execute this script. if it is nil, Xcode will use default value. + public let shellPath: String? public let showEnvVarsInLog: Bool @@ -20,11 +22,13 @@ public struct ExecutionAction: Equatable, Codable { title: String, scriptText: String, target: TargetReference?, + shellPath: String?, showEnvVarsInLog: Bool = true ) { self.title = title self.scriptText = scriptText self.target = target + self.shellPath = shellPath self.showEnvVarsInLog = showEnvVarsInLog } } diff --git a/Sources/TuistLoader/Models+ManifestMappers/ExecutionAction+ManifestMapper.swift b/Sources/TuistLoader/Models+ManifestMappers/ExecutionAction+ManifestMapper.swift index 4e2dc95dd..4b04bdc7d 100644 --- a/Sources/TuistLoader/Models+ManifestMappers/ExecutionAction+ManifestMapper.swift +++ b/Sources/TuistLoader/Models+ManifestMappers/ExecutionAction+ManifestMapper.swift @@ -17,6 +17,11 @@ extension TuistGraph.ExecutionAction { name: $0.targetName ) } - return ExecutionAction(title: manifest.title, scriptText: manifest.scriptText, target: targetReference) + return ExecutionAction( + title: manifest.title, + scriptText: manifest.scriptText, + target: targetReference, + shellPath: manifest.shellPath + ) } } diff --git a/Tests/ProjectDescriptionTests/SchemeTests.swift b/Tests/ProjectDescriptionTests/SchemeTests.swift index e6a5b0916..e08793870 100644 --- a/Tests/ProjectDescriptionTests/SchemeTests.swift +++ b/Tests/ProjectDescriptionTests/SchemeTests.swift @@ -99,7 +99,8 @@ final class SchemeTests: XCTestCase { target: TargetReference( projectPath: nil, target: "target" - ) + ), + shellPath: "/bin/sh" ), ] } diff --git a/Tests/TuistGeneratorTests/Generator/SchemeDescriptorsGeneratorTests.swift b/Tests/TuistGeneratorTests/Generator/SchemeDescriptorsGeneratorTests.swift index 3b883fc9f..f82ec585e 100644 --- a/Tests/TuistGeneratorTests/Generator/SchemeDescriptorsGeneratorTests.swift +++ b/Tests/TuistGeneratorTests/Generator/SchemeDescriptorsGeneratorTests.swift @@ -211,12 +211,14 @@ final class SchemeDescriptorsGeneratorTests: XCTestCase { let preAction = ExecutionAction( title: "Pre Action", scriptText: "echo Pre Actions", - target: TargetReference(projectPath: projectPath, name: "App") + target: TargetReference(projectPath: projectPath, name: "App"), + shellPath: "/bin/sh" ) let postAction = ExecutionAction( title: "Post Action", scriptText: "echo Post Actions", - target: TargetReference(projectPath: projectPath, name: "App") + target: TargetReference(projectPath: projectPath, name: "App"), + shellPath: "/bin/sh" ) let buildAction = BuildAction.test( targets: [TargetReference(projectPath: projectPath, name: "App")], @@ -252,6 +254,7 @@ final class SchemeDescriptorsGeneratorTests: XCTestCase { // Pre Action XCTAssertEqual(got?.preActions.first?.title, "Pre Action") XCTAssertEqual(got?.preActions.first?.scriptText, "echo Pre Actions") + XCTAssertEqual(got?.preActions.first?.shellToInvoke, "/bin/sh") let preBuildableReference = got?.preActions.first?.environmentBuildable @@ -263,6 +266,7 @@ final class SchemeDescriptorsGeneratorTests: XCTestCase { // Post Action XCTAssertEqual(got?.postActions.first?.title, "Post Action") XCTAssertEqual(got?.postActions.first?.scriptText, "echo Post Actions") + XCTAssertEqual(got?.postActions.first?.shellToInvoke, "/bin/sh") let postBuildableReference = got?.postActions.first?.environmentBuildable @@ -319,7 +323,8 @@ final class SchemeDescriptorsGeneratorTests: XCTestCase { let preAction = ExecutionAction( title: "Pre Action", scriptText: "echo Pre Actions", - target: TargetReference(projectPath: projectPath, name: "App") + target: TargetReference(projectPath: projectPath, name: "App"), + shellPath: nil ) let buildAction = BuildAction.test( targets: [TargetReference(projectPath: projectPath, name: "App")], @@ -773,12 +778,14 @@ final class SchemeDescriptorsGeneratorTests: XCTestCase { let preAction = ExecutionAction( title: "Pre Action", scriptText: "echo Pre Actions", - target: TargetReference(projectPath: projectPath, name: "AppTests") + target: TargetReference(projectPath: projectPath, name: "AppTests"), + shellPath: "/bin/sh" ) let postAction = ExecutionAction( title: "Post Action", scriptText: "echo Post Actions", - target: TargetReference(projectPath: projectPath, name: "AppTests") + target: TargetReference(projectPath: projectPath, name: "AppTests"), + shellPath: "/bin/sh" ) let testAction = TestAction.test( targets: [TestableTarget(target: TargetReference(projectPath: projectPath, name: "AppTests"))], @@ -824,6 +831,7 @@ final class SchemeDescriptorsGeneratorTests: XCTestCase { XCTAssertEqual(result.preActions.first?.title, "Pre Action") XCTAssertEqual(result.preActions.first?.scriptText, "echo Pre Actions") + XCTAssertEqual(result.preActions.first?.shellToInvoke, "/bin/sh") let preBuildableReference = try XCTUnwrap(result.preActions.first?.environmentBuildable) @@ -835,6 +843,7 @@ final class SchemeDescriptorsGeneratorTests: XCTestCase { // Post Action XCTAssertEqual(result.postActions.first?.title, "Post Action") XCTAssertEqual(result.postActions.first?.scriptText, "echo Post Actions") + XCTAssertEqual(result.postActions.first?.shellToInvoke, "/bin/sh") let postBuildableReference = try XCTUnwrap(result.postActions.first?.environmentBuildable) @@ -1090,12 +1099,14 @@ final class SchemeDescriptorsGeneratorTests: XCTestCase { let preAction = ExecutionAction( title: "Pre Action", scriptText: "echo Pre Actions", - target: TargetReference(projectPath: projectPath, name: "App") + target: TargetReference(projectPath: projectPath, name: "App"), + shellPath: "/bin/sh" ) let postAction = ExecutionAction( title: "Post Action", scriptText: "echo Post Actions", - target: TargetReference(projectPath: projectPath, name: "App") + target: TargetReference(projectPath: projectPath, name: "App"), + shellPath: "/bin/sh" ) let launchAction = RunAction.test( @@ -1136,8 +1147,10 @@ final class SchemeDescriptorsGeneratorTests: XCTestCase { // Then XCTAssertEqual(got?.preActions.first?.title, "Pre Action") XCTAssertEqual(got?.preActions.first?.scriptText, "echo Pre Actions") + XCTAssertEqual(got?.preActions.first?.shellToInvoke, "/bin/sh") XCTAssertEqual(got?.postActions.first?.title, "Post Action") XCTAssertEqual(got?.postActions.first?.scriptText, "echo Post Actions") + XCTAssertEqual(got?.postActions.first?.shellToInvoke, "/bin/sh") } func test_schemeLaunchAction_with_disabled_attachDebugger() throws { @@ -1562,12 +1575,14 @@ final class SchemeDescriptorsGeneratorTests: XCTestCase { let preAction = ExecutionAction( title: "Pre Action", scriptText: "echo Pre Actions", - target: TargetReference(projectPath: projectPath, name: "App") + target: TargetReference(projectPath: projectPath, name: "App"), + shellPath: "/bin/sh" ) let postAction = ExecutionAction( title: "Post Action", scriptText: "echo Post Actions", - target: TargetReference(projectPath: projectPath, name: "App") + target: TargetReference(projectPath: projectPath, name: "App"), + shellPath: "/bin/sh" ) let scheme = makeProfileActionScheme( preActions: [preAction], @@ -1599,8 +1614,10 @@ final class SchemeDescriptorsGeneratorTests: XCTestCase { // Then XCTAssertEqual(got?.preActions.first?.title, "Pre Action") XCTAssertEqual(got?.preActions.first?.scriptText, "echo Pre Actions") + XCTAssertEqual(got?.preActions.first?.shellToInvoke, "/bin/sh") XCTAssertEqual(got?.postActions.first?.title, "Post Action") XCTAssertEqual(got?.postActions.first?.scriptText, "echo Post Actions") + XCTAssertEqual(got?.postActions.first?.shellToInvoke, "/bin/sh") } // MARK: - Analyze Action Tests diff --git a/Tests/TuistGeneratorTests/Linter/SchemeLinterTests.swift b/Tests/TuistGeneratorTests/Linter/SchemeLinterTests.swift index 270c50f4b..d0c28b94e 100644 --- a/Tests/TuistGeneratorTests/Linter/SchemeLinterTests.swift +++ b/Tests/TuistGeneratorTests/Linter/SchemeLinterTests.swift @@ -144,7 +144,8 @@ class SchemeLinterTests: TuistTestCase { target: .init( projectPath: try! AbsolutePath(validating: "/Project/../Project2"), name: "Target2" - ) + ), + shellPath: nil )]) ), ]) diff --git a/Tests/TuistGraphTests/Models/ArchiveActionTests.swift b/Tests/TuistGraphTests/Models/ArchiveActionTests.swift index adc27959d..37235a281 100644 --- a/Tests/TuistGraphTests/Models/ArchiveActionTests.swift +++ b/Tests/TuistGraphTests/Models/ArchiveActionTests.swift @@ -16,6 +16,7 @@ final class ArchiveActionTests: TuistUnitTestCase { title: "preActionTitle", scriptText: "text", target: nil, + shellPath: nil, showEnvVarsInLog: false ), ], @@ -24,6 +25,7 @@ final class ArchiveActionTests: TuistUnitTestCase { title: "postActionTitle", scriptText: "text", target: nil, + shellPath: nil, showEnvVarsInLog: true ), ] diff --git a/Tests/TuistGraphTests/Models/BuildActionTests.swift b/Tests/TuistGraphTests/Models/BuildActionTests.swift index bed5a8788..32a4b3b67 100644 --- a/Tests/TuistGraphTests/Models/BuildActionTests.swift +++ b/Tests/TuistGraphTests/Models/BuildActionTests.swift @@ -19,6 +19,7 @@ final class BuildActionTests: TuistUnitTestCase { title: "preActionTitle", scriptText: "text", target: nil, + shellPath: nil, showEnvVarsInLog: true ), ], @@ -27,6 +28,7 @@ final class BuildActionTests: TuistUnitTestCase { title: "postActionTitle", scriptText: "text", target: nil, + shellPath: nil, showEnvVarsInLog: false ), ] diff --git a/Tests/TuistGraphTests/Models/ExecutionActionTests.swift b/Tests/TuistGraphTests/Models/ExecutionActionTests.swift index 7619b6b49..413329420 100644 --- a/Tests/TuistGraphTests/Models/ExecutionActionTests.swift +++ b/Tests/TuistGraphTests/Models/ExecutionActionTests.swift @@ -14,6 +14,7 @@ final class ExecutionActionTests: TuistUnitTestCase { projectPath: "/path/to/project", name: "name" ), + shellPath: nil, showEnvVarsInLog: false ) diff --git a/Tests/TuistIntegrationTests/Generator/TestModelGenerator.swift b/Tests/TuistIntegrationTests/Generator/TestModelGenerator.swift index 176c02ecb..18aff1587 100644 --- a/Tests/TuistIntegrationTests/Generator/TestModelGenerator.swift +++ b/Tests/TuistIntegrationTests/Generator/TestModelGenerator.swift @@ -363,7 +363,13 @@ final class TestModelGenerator { private func createExecutionActions() -> [ExecutionAction] { (0 ..< 10).map { - ExecutionAction(title: "ExecutionAction\($0)", scriptText: "ScripText\($0)", target: nil, showEnvVarsInLog: false) + ExecutionAction( + title: "ExecutionAction\($0)", + scriptText: "ScripText\($0)", + target: nil, + shellPath: nil, + showEnvVarsInLog: false + ) } } diff --git a/Tuist/Dependencies.swift b/Tuist/Dependencies.swift index 85c86e69a..a50361ded 100644 --- a/Tuist/Dependencies.swift +++ b/Tuist/Dependencies.swift @@ -18,7 +18,7 @@ let dependencies = Dependencies( .package(url: "https://github.com/SwiftDocOrg/GraphViz.git", .exact("0.2.0")), .package(url: "https://github.com/SwiftGen/StencilSwiftKit.git", .exact("2.9.0")), .package(url: "https://github.com/SwiftGen/SwiftGen", .exact("6.5.1")), - .package(url: "https://github.com/tuist/XcodeProj.git", .exact("8.8.0")), + .package(url: "https://github.com/tuist/XcodeProj.git", .exact("8.10.0")), ], platforms: [.macOS] ) diff --git a/Tuist/Dependencies/Lockfiles/Package.resolved b/Tuist/Dependencies/Lockfiles/Package.resolved index e7a4b9172..0a9157751 100644 --- a/Tuist/Dependencies/Lockfiles/Package.resolved +++ b/Tuist/Dependencies/Lockfiles/Package.resolved @@ -247,8 +247,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tuist/XcodeProj.git", "state" : { - "revision" : "b6de1bfe021b861c94e7c83821b595083f74b997", - "version" : "8.8.0" + "revision" : "5fdac93cb4a7fd4bad5ac2da34e5bc878263043f", + "version" : "8.10.0" } }, { diff --git a/projects/tuist/fixtures/ios_app_with_custom_scheme/Workspace.swift b/projects/tuist/fixtures/ios_app_with_custom_scheme/Workspace.swift index 2f2a75653..013e7dce4 100644 --- a/projects/tuist/fixtures/ios_app_with_custom_scheme/Workspace.swift +++ b/projects/tuist/fixtures/ios_app_with_custom_scheme/Workspace.swift @@ -10,14 +10,16 @@ let customAppScheme = Scheme( ], preActions: [ ExecutionAction( - scriptText: "echo pre-action", - target: .project(path: "App", target: "App") + scriptText: "echo \"pre-action in $SHELL\"", + target: .project(path: "App", target: "App"), + shellPath: "/bin/zsh" ), ], postActions: [ ExecutionAction( - scriptText: "echo post-action", - target: .project(path: "Frameworks/Framework1", target: "Framework1") + scriptText: "echo \"post-action in $SHELL\"", + target: .project(path: "Frameworks/Framework1", target: "Framework1"), + shellPath: "/bin/zsh" ), ] ),