From 1259fdc2df64fc6c062e8590ced4f26eaba010c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C-=E5=87=A1?= <827799383@qq.com> Date: Wed, 7 Sep 2022 22:17:14 +0800 Subject: [PATCH] Add shellToInvoke to XCScheme.ExecutionAction (#721) Co-authored-by: kongkaikai --- .../xcshareddata/xcschemes/iOS.xcscheme | 3 ++- .../Scheme/XCScheme+ExecutionAction.swift | 24 +++++++++++++++---- .../XcodeProjTests/Scheme/XCSchemeTests.swift | 2 ++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Fixtures/iOS/Project.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme b/Fixtures/iOS/Project.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme index 119ecf609..441f0e3b2 100644 --- a/Fixtures/iOS/Project.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme +++ b/Fixtures/iOS/Project.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme @@ -19,7 +19,8 @@ ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction"> + scriptText = "echo postbuild" + shellToInvoke = "/bin/sh"> diff --git a/Sources/XcodeProj/Scheme/XCScheme+ExecutionAction.swift b/Sources/XcodeProj/Scheme/XCScheme+ExecutionAction.swift index 5dd3d7d21..484e99aaa 100644 --- a/Sources/XcodeProj/Scheme/XCScheme+ExecutionAction.swift +++ b/Sources/XcodeProj/Scheme/XCScheme+ExecutionAction.swift @@ -9,19 +9,29 @@ extension XCScheme { public var title: String public var scriptText: String + public var shellToInvoke: String? public var environmentBuildable: BuildableReference? // MARK: - Init - public init(scriptText: String, title: String = "Run Script", environmentBuildable: BuildableReference? = nil) { + public init( + scriptText: String, + title: String = "Run Script", + shellToInvoke: String? = nil, + environmentBuildable: BuildableReference? = nil + ) { self.scriptText = scriptText self.title = title + self.shellToInvoke = shellToInvoke self.environmentBuildable = environmentBuildable } init(element: AEXMLElement) throws { scriptText = element["ActionContent"].attributes["scriptText"] ?? "" title = element["ActionContent"].attributes["title"] ?? "Run Script" + if let shellToInvoke = element["ActionContent"].attributes["shellToInvoke"] { + self.shellToInvoke = shellToInvoke + } environmentBuildable = try? BuildableReference(element: element["ActionContent"]["EnvironmentBuildable"]["BuildableReference"]) } @@ -31,12 +41,16 @@ extension XCScheme { let element = AEXMLElement(name: "ExecutionAction", value: nil, attributes: ["ActionType": ExecutionAction.ActionType]) + var attributes = [ + "title": title, + "scriptText": scriptText, + ] + if let shellToInvoke = shellToInvoke { + attributes["shellToInvoke"] = shellToInvoke + } let content = AEXMLElement(name: "ActionContent", value: nil, - attributes: [ - "title": title, - "scriptText": scriptText, - ]) + attributes: attributes) element.addChild(content) if let environmentBuildable = environmentBuildable { let environment = content.addChild(name: "EnvironmentBuildable") diff --git a/Tests/XcodeProjTests/Scheme/XCSchemeTests.swift b/Tests/XcodeProjTests/Scheme/XCSchemeTests.swift index 2ec14710c..678147597 100644 --- a/Tests/XcodeProjTests/Scheme/XCSchemeTests.swift +++ b/Tests/XcodeProjTests/Scheme/XCSchemeTests.swift @@ -329,8 +329,10 @@ final class XCSchemeIntegrationTests: XCTestCase { XCTAssertEqual(scheme.buildAction?.buildActionEntries.first?.buildableReference.referencedContainer, "container:Project.xcodeproj") XCTAssertEqual(scheme.buildAction?.preActions.first?.title, "Build Pre-action") XCTAssertEqual(scheme.buildAction?.preActions.first?.scriptText, "echo prebuild") + XCTAssertNil(scheme.buildAction?.preActions.first?.shellToInvoke) XCTAssertEqual(scheme.buildAction?.postActions.first?.title, "Build Post-action") XCTAssertEqual(scheme.buildAction?.postActions.first?.scriptText, "echo postbuild") + XCTAssertEqual(scheme.buildAction?.postActions.first?.shellToInvoke, "/bin/sh") // Test action XCTAssertEqual(scheme.testAction?.buildConfiguration, "Debug") XCTAssertEqual(scheme.testAction?.selectedDebuggerIdentifier, "Xcode.DebuggerFoundation.Debugger.LLDB")