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 shellToInvoke to XCScheme.ExecutionAction #721

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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