Skip to content

Commit

Permalink
Add shellToInvoke to XCScheme.ExecutionAction (#721)
Browse files Browse the repository at this point in the history
Co-authored-by: kongkaikai <[email protected]>
  • Loading branch information
CrazyFanFan and kongkaikai authored Sep 7, 2022
1 parent 4fdab09 commit 1259fdc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Build Post-action"
scriptText = "echo postbuild">
scriptText = "echo postbuild"
shellToInvoke = "/bin/sh">
</ActionContent>
</ExecutionAction>
</PostActions>
Expand Down
24 changes: 19 additions & 5 deletions Sources/XcodeProj/Scheme/XCScheme+ExecutionAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
}

Expand All @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions Tests/XcodeProjTests/Scheme/XCSchemeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1259fdc

Please sign in to comment.