Skip to content

Commit

Permalink
Merge pull request #240 from xcodeswift/showEnvVarsInLog
Browse files Browse the repository at this point in the history
Fix Writing of showEnvVarsInLog
  • Loading branch information
briantkelley authored Mar 7, 2018
2 parents 3c95e75 + 177dff2 commit 343d686
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Fixed
- `PBXObject.isEqual(to:)` overrides correctly call super https://github.com/xcodeswift/xcproj/pull/239 by @briantkelley
- `PBXAggregateTarget` does not write `buildRules` https://github.com/xcodeswift/xcproj/pull/241 by @briantkelley
- Writes showEnvVarsInLog only when false https://github.com/xcodeswift/xcproj/pull/240 by @briantkelley

## 4.1.0

Expand Down
9 changes: 6 additions & 3 deletions Sources/xcproj/PBXShellScriptBuildPhase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final public class PBXShellScriptBuildPhase: PBXBuildPhase {
shellScript: String? = nil,
buildActionMask: UInt = defaultBuildActionMask,
runOnlyForDeploymentPostprocessing: Bool = false,
showEnvVarsInLog: Bool = false) {
showEnvVarsInLog: Bool = true) {
self.name = name
self.inputPaths = inputPaths
self.outputPaths = outputPaths
Expand Down Expand Up @@ -76,7 +76,7 @@ final public class PBXShellScriptBuildPhase: PBXBuildPhase {
self.outputPaths = (try container.decodeIfPresent(.outputPaths)) ?? []
self.shellPath = try container.decodeIfPresent(.shellPath)
self.shellScript = try container.decodeIfPresent(.shellScript)
self.showEnvVarsInLog = try container.decodeIntBool(.showEnvVarsInLog)
self.showEnvVarsInLog = try container.decodeIntBoolIfPresent(.showEnvVarsInLog) ?? true
try super.init(from: decoder)
}

Expand Down Expand Up @@ -117,7 +117,10 @@ extension PBXShellScriptBuildPhase: PlistSerializable {
if let shellScript = shellScript {
dictionary["shellScript"] = .string(CommentedString(shellScript))
}
dictionary["showEnvVarsInLog"] = .string(CommentedString("\(showEnvVarsInLog.int)"))
if !showEnvVarsInLog {
// Xcode only writes this key if it's set to false; default is true and is omitted
dictionary["showEnvVarsInLog"] = .string(CommentedString("\(showEnvVarsInLog.int)"))
}
return (key: CommentedString(reference, comment: self.name ?? "ShellScript"), value: .dictionary(dictionary))
}

Expand Down
24 changes: 23 additions & 1 deletion Tests/xcprojTests/PBXShellScriptBuildPhaseSpec.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import XCTest
import xcproj
@testable import xcproj

final class PBXShellScriptBuildPhaseSpec: XCTestCase {

Expand Down Expand Up @@ -30,6 +30,28 @@ final class PBXShellScriptBuildPhaseSpec: XCTestCase {
XCTAssertEqual(one, another)
}

func test_write_showEnvVarsInLog() {
let show = PBXShellScriptBuildPhase(showEnvVarsInLog: true)
let doNotShow = PBXShellScriptBuildPhase(showEnvVarsInLog: false)

let proj = PBXProj(rootObject: "rootObject",
objectVersion: 48,
objects: ["show": show,
"doNotShow": doNotShow])

let (_, showPlistValue) = show.plistKeyAndValue(proj: proj, reference: "ref")
let (_, doNotShowPlistValue) = doNotShow.plistKeyAndValue(proj: proj, reference: "ref")

if case PlistValue.dictionary(let showDictionary) = showPlistValue,
case PlistValue.dictionary(let doNotShowDictionary) = doNotShowPlistValue {

XCTAssertNil(showDictionary["showEnvVarsInLog"])
XCTAssertEqual(doNotShowDictionary["showEnvVarsInLog"]?.string, "0")
} else {
XCTAssert(false)
}
}

private func testDictionary() -> [String: Any] {
return [
"files": ["files"],
Expand Down

0 comments on commit 343d686

Please sign in to comment.