Skip to content

Commit

Permalink
Merge pull request #32 from yonaskolb/build_script_installing
Browse files Browse the repository at this point in the history
Add BuildScript.runOnlyWhenInstalling
  • Loading branch information
yonaskolb authored Aug 24, 2017
2 parents 0352ea3 + edca439 commit 50b1f73
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
8 changes: 6 additions & 2 deletions Sources/ProjectSpec/RunScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public struct RunScript: Equatable {
public var shell: String?
public var inputFiles: [String]
public var outputFiles: [String]
public var runOnlyWhenInstalling: Bool

public enum ScriptType: Equatable {
case path(String)
Expand All @@ -30,12 +31,13 @@ public struct RunScript: Equatable {
}
}

public init(script: ScriptType, name: String? = nil, inputFiles: [String] = [], outputFiles: [String] = [], shell: String? = nil) {
public init(script: ScriptType, name: String? = nil, inputFiles: [String] = [], outputFiles: [String] = [], shell: String? = nil, runOnlyWhenInstalling: Bool = false) {
self.script = script
self.name = name
self.inputFiles = inputFiles
self.outputFiles = outputFiles
self.shell = shell
self.runOnlyWhenInstalling = runOnlyWhenInstalling
}

public static func ==(lhs: RunScript, rhs: RunScript) -> Bool {
Expand All @@ -44,7 +46,8 @@ public struct RunScript: Equatable {
lhs.script == rhs.script &&
lhs.inputFiles == rhs.inputFiles &&
lhs.outputFiles == rhs.outputFiles &&
lhs.shell == rhs.shell
lhs.shell == rhs.shell &&
lhs.runOnlyWhenInstalling == rhs.runOnlyWhenInstalling
}
}

Expand All @@ -62,5 +65,6 @@ extension RunScript: JSONObjectConvertible {
script = .path(path)
}
shell = jsonDictionary.json(atKeyPath: "shell")
runOnlyWhenInstalling = jsonDictionary.json(atKeyPath: "runOnlyWhenInstalling") ?? false
}
}
4 changes: 2 additions & 2 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ public class PBXProjGenerator {
shellScript = script
}
let escapedScript = shellScript.replacingOccurrences(of: "\"", with: "\\\"").replacingOccurrences(of: "\n", with: "\\n")
let shellScriptPhase = PBXShellScriptBuildPhase(
var shellScriptPhase = PBXShellScriptBuildPhase(
reference: generateUUID(PBXShellScriptBuildPhase.self, String(describing: runScript.name) + shellScript + target.name),
files: [],
name: runScript.name ?? "Run Script",
inputPaths: Set(runScript.inputFiles),
outputPaths: Set(runScript.outputFiles),
shellPath: runScript.shell ?? "/bin/sh",
shellScript: escapedScript)

shellScriptPhase.runOnlyForDeploymentPostprocessing = runScript.runOnlyWhenInstalling ? 1 : 0
objects.append(.pbxShellScriptBuildPhase(shellScriptPhase))
buildPhases.append(shellScriptPhase.reference)
return shellScriptPhase
Expand Down
4 changes: 2 additions & 2 deletions Tests/XcodeGenKitTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ func specLoadingTests() {
var target = validTarget
let scripts: [[String: Any]] = [
["path": "script.sh"],
["script": "shell script\ndo thing", "name": "myscript", "inputFiles": ["file","file2"], "outputFiles": ["file","file2"], "shell": "bin/customshell"],
["script": "shell script\ndo thing", "name": "myscript", "inputFiles": ["file","file2"], "outputFiles": ["file","file2"], "shell": "bin/customshell", "runOnlyWhenInstalling": true],
]
target["prebuildScripts"] = scripts
target["postbuildScripts"] = scripts

let expectedScripts = [
RunScript(script: .path("script.sh")),
RunScript(script: .script("shell script\ndo thing"), name: "myscript", inputFiles: ["file","file2"], outputFiles: ["file","file2"], shell: "bin/customshell"),
RunScript(script: .script("shell script\ndo thing"), name: "myscript", inputFiles: ["file","file2"], outputFiles: ["file","file2"], shell: "bin/customshell", runOnlyWhenInstalling: true),
]

let parsedTarget = try Target(jsonDictionary: target)
Expand Down
1 change: 1 addition & 0 deletions docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Run script build phases added via **prebuildScripts** or **postBuildScripts**. T
- ⚪️ **inputFiles**: `[String]` - list of input files
- ⚪️ **outputFiles**: `[String]` - list of output files
- ⚪️ **shell**: `String` - shell used for the script. Defaults to `/bin/sh`
- ⚪️ **runOnlyWhenInstalling**: `Bool` - whether the script is only run when installing (runOnlyForDeploymentPostprocessing). Defaults to no

Either a **path** or **script** must be defined, the rest are optional.

Expand Down

0 comments on commit 50b1f73

Please sign in to comment.