-
-
Notifications
You must be signed in to change notification settings - Fork 300
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 Support for Custom Build Rules #197
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import Foundation | ||
|
||
/// A PBXBuildRule is used to specify a method for transforming an input file in to an output file(s). | ||
final public class PBXBuildRule: PBXObject, Equatable { | ||
|
||
// MARK: - Attributes | ||
|
||
/// Element compiler spec. | ||
public var compilerSpec: String | ||
|
||
/// Element file patterns. | ||
public var filePatterns: String? | ||
|
||
/// Element file type. | ||
public var fileType: String | ||
|
||
/// Element is editable. | ||
public var isEditable: Bool | ||
|
||
/// Element name. | ||
public var name: String? | ||
|
||
/// Element output files. | ||
public var outputFiles: [String] | ||
|
||
/// Element output files compiler flags. | ||
public var outputFilesCompilerFlags: [String]? | ||
|
||
/// Element script. | ||
public var script: String? | ||
|
||
// MARK: - Init | ||
|
||
public init(reference: String, | ||
compilerSpec: String, | ||
filePatterns: String? = nil, | ||
fileType: String, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more very minor thing. As |
||
isEditable: Bool = true, | ||
name: String? = nil, | ||
outputFiles: [String] = [], | ||
outputFilesCompilerFlags: [String]? = nil, | ||
script: String? = nil) { | ||
self.compilerSpec = compilerSpec | ||
self.filePatterns = filePatterns | ||
self.fileType = fileType | ||
self.isEditable = isEditable | ||
self.name = name | ||
self.outputFiles = outputFiles | ||
self.outputFilesCompilerFlags = outputFilesCompilerFlags | ||
self.script = script | ||
super.init(reference: reference) | ||
} | ||
|
||
// MARK: - Decodable | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case compilerSpec | ||
case filePatterns | ||
case fileType | ||
case isEditable | ||
case name | ||
case outputFiles | ||
case outputFilesCompilerFlags | ||
case script | ||
} | ||
|
||
public required init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
self.compilerSpec = try container.decodeIfPresent(.compilerSpec) ?? "" | ||
self.filePatterns = try container.decodeIfPresent(.filePatterns) | ||
self.fileType = try container.decodeIfPresent(.fileType) ?? "" | ||
let isEditable: String? = try container.decodeIfPresent(.isEditable) | ||
self.isEditable = (isEditable.flatMap(UInt.init) ?? 0) == 1 | ||
self.name = try container.decodeIfPresent(.name) | ||
self.outputFiles = try container.decodeIfPresent(.outputFiles) ?? [] | ||
self.outputFilesCompilerFlags = try container.decodeIfPresent(.outputFilesCompilerFlags) | ||
self.script = try container.decodeIfPresent(.script) | ||
try super.init(from: decoder) | ||
} | ||
|
||
// MARK: - Equatable | ||
|
||
public static func == (lhs: PBXBuildRule, | ||
rhs: PBXBuildRule) -> Bool { | ||
let outputFilesCompilerFlagsAreEqual: Bool = { | ||
switch (lhs.outputFilesCompilerFlags, rhs.outputFilesCompilerFlags) { | ||
case (.none, .none): | ||
return true | ||
case (.none, .some), (.some, .none): | ||
return false | ||
case (.some(let lhsOutputFilesCompilerFlags), .some(let rhsOutputFilesCompilerFlags)): | ||
return lhsOutputFilesCompilerFlags == rhsOutputFilesCompilerFlags | ||
} | ||
}() | ||
return lhs.reference == rhs.reference && | ||
lhs.compilerSpec == rhs.compilerSpec && | ||
lhs.filePatterns == rhs.filePatterns && | ||
lhs.fileType == rhs.fileType && | ||
lhs.isEditable == rhs.isEditable && | ||
lhs.name == rhs.name && | ||
lhs.outputFiles == rhs.outputFiles && | ||
outputFilesCompilerFlagsAreEqual && | ||
lhs.script == rhs.script | ||
} | ||
} | ||
|
||
// MARK: - PBXBuildRule Extension (PlistSerializable) | ||
|
||
extension PBXBuildRule: PlistSerializable { | ||
|
||
var multiline: Bool { return true } | ||
|
||
func plistKeyAndValue(proj: PBXProj) -> (key: CommentedString, value: PlistValue) { | ||
var dictionary: [CommentedString: PlistValue] = [:] | ||
dictionary["isa"] = .string(CommentedString(PBXBuildRule.isa)) | ||
dictionary["compilerSpec"] = .string(CommentedString(compilerSpec)) | ||
if let filePatterns = filePatterns { | ||
dictionary["filePatterns"] = .string(CommentedString(filePatterns)) | ||
} | ||
dictionary["fileType"] = .string(CommentedString(fileType)) | ||
dictionary["isEditable"] = .string(CommentedString("\(isEditable ? 1 : 0)")) | ||
if let name = name { | ||
dictionary["name"] = .string(CommentedString(name)) | ||
} | ||
dictionary["outputFiles"] = .array(outputFiles.map { PlistValue.string(CommentedString($0)) }) | ||
if let outputFilesCompilerFlags = outputFilesCompilerFlags { | ||
dictionary["outputFilesCompilerFlags"] = .array(outputFilesCompilerFlags.map { PlistValue.string(CommentedString($0)) }) | ||
} | ||
if let script = script { | ||
dictionary["script"] = .string(CommentedString(script)) | ||
} | ||
return (key: CommentedString(self.reference, comment: PBXBuildRule.isa), | ||
value: .dictionary(dictionary)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Foundation | ||
import XCTest | ||
import xcproj | ||
|
||
final class PBXBuildRuleSpec: XCTestCase { | ||
|
||
var subject: PBXBuildRule! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
subject = PBXBuildRule(reference: "ref", | ||
compilerSpec: "spec", | ||
filePatterns: "pattern", | ||
fileType: "type", | ||
isEditable: true, | ||
name: "rule", | ||
outputFiles:["a", "b"], | ||
outputFilesCompilerFlags: ["-1", "-2"], | ||
script: "script") | ||
} | ||
|
||
func test_init_initializesTheBuildRuleWithTheRightAttributes() { | ||
XCTAssertEqual(subject.reference, "ref") | ||
XCTAssertEqual(subject.compilerSpec, "spec") | ||
XCTAssertEqual(subject.filePatterns, "pattern") | ||
XCTAssertEqual(subject.fileType, "type") | ||
XCTAssertEqual(subject.isEditable, true) | ||
XCTAssertEqual(subject.name, "rule") | ||
XCTAssertEqual(subject.outputFiles, ["a", "b"]) | ||
XCTAssertEqual(subject.outputFilesCompilerFlags ?? [], ["-1", "-2"]) | ||
XCTAssertEqual(subject.script, "script") | ||
} | ||
|
||
func test_isa_returnsTheCorrectValue() { | ||
XCTAssertEqual(PBXBuildRule.isa, "PBXBuildRule") | ||
} | ||
|
||
func test_hashValue_returnsTheReferenceHashValue() { | ||
XCTAssertEqual(subject.hashValue, subject.reference.hashValue) | ||
} | ||
|
||
func test_equal_shouldReturnTheCorrectValue() { | ||
let another = PBXBuildRule(reference: "ref", | ||
compilerSpec: "spec", | ||
filePatterns: "pattern", | ||
fileType: "type", | ||
isEditable: true, | ||
name: "rule", | ||
outputFiles:["a", "b"], | ||
outputFilesCompilerFlags: ["-1", "-2"], | ||
script: "script") | ||
XCTAssertEqual(subject, another) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity. Did you check the optionality of the attributes with Xcode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this up and merging. @pepibumur, yes, I tried examining the encoded form of of a number of different permutations.
compilerSpec
is required so specify how the file should be processed, butfilePatterns
is optional since it's a filter onfileType
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem @briantkelley π it was just curiosity. The changes should be in xcproj 1.8.0 ready to be used :)