Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Next Version

### Added
- Added support for input files in build rules #1650 @GtechGovind
- Added `buildArchitectures` to scheme build options and target schemes, to control Xcode's "Override Architectures" scheme setting #1642 @arhxam
- Added FAQ documentation on how to add an Xcode capability, such as In-App Purchase #1644 @Hokila

Expand Down
3 changes: 3 additions & 0 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ targets:
- [ ] **script**: **String** - The script that will be run on each file. This or `compilerSpec` must be defined.
- [ ] **compilerSpec**: **String**: A reference to a built in apple tool to run on each file. This is for advanced use and the the values for this must be checked. This or `script` must be defined.
- [ ] **name**: **String** - The name of a build rule. Defaults to `Build Rule`
- [ ] **inputFiles**: **[String]** - The list of input files
- [ ] **outputFiles**: **[String]** - The list of output files
- [ ] **outputFilesCompilerFlags**: **[String]** - The list of compiler flags to apply to the output files
- [ ] **runOncePerArchitecture**: **Bool** - a boolean that indicates if this rule should run once per architecture. This defaults to true
Expand All @@ -876,6 +877,8 @@ targets:
- filePattern: "*.txt"
name: My Build Rule
compilerSpec: com.apple.xcode.tools.swift.compiler
inputFiles:
- $(SRCROOT)/Input.txt
outputFiles:
- $(SRCROOT)/Generated.swift
runOncePerArchitecture: false
Expand Down
5 changes: 5 additions & 0 deletions Sources/ProjectSpec/BuildRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public struct BuildRule: Equatable {

public var fileType: FileType
public var action: Action
public var inputFiles: [String]?
public var outputFiles: [String]
public var outputFilesCompilerFlags: [String]
public var name: String?
Expand All @@ -56,13 +57,15 @@ public struct BuildRule: Equatable {
fileType: FileType,
action: Action,
name: String? = nil,
inputFiles: [String]? = nil,
outputFiles: [String] = [],
outputFilesCompilerFlags: [String] = [],
runOncePerArchitecture: Bool = runOncePerArchitectureDefault
) {
self.fileType = fileType
self.action = action
self.name = name
self.inputFiles = inputFiles
self.outputFiles = outputFiles
self.outputFilesCompilerFlags = outputFilesCompilerFlags
self.runOncePerArchitecture = runOncePerArchitecture
Expand All @@ -85,6 +88,7 @@ extension BuildRule: JSONObjectConvertible {
action = .script(try jsonDictionary.json(atKeyPath: "script"))
}

inputFiles = jsonDictionary.json(atKeyPath: "inputFiles")
outputFiles = jsonDictionary.json(atKeyPath: "outputFiles") ?? []
outputFilesCompilerFlags = jsonDictionary.json(atKeyPath: "outputFilesCompilerFlags") ?? []
name = jsonDictionary.json(atKeyPath: "name")
Expand All @@ -95,6 +99,7 @@ extension BuildRule: JSONObjectConvertible {
extension BuildRule: JSONEncodable {
public func toJSONValue() -> Any {
var dict: [String: Any?] = [
"inputFiles": inputFiles,
"outputFiles": outputFiles,
"outputFilesCompilerFlags": outputFilesCompilerFlags,
"name": name,
Expand Down
1 change: 1 addition & 0 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,7 @@ public class PBXProjGenerator {
filePatterns: buildRule.fileType.pattern,
name: buildRule.name ?? "Build Rule",
outputFiles: buildRule.outputFiles,
inputFiles: buildRule.inputFiles,
outputFilesCompilerFlags: buildRule.outputFilesCompilerFlags,
script: buildRule.action.script,
runOncePerArchitecture: buildRule.runOncePerArchitecture
Expand Down
2 changes: 2 additions & 0 deletions Tests/ProjectSpecTests/ProjectSpecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,14 @@ class ProjectSpecTests: XCTestCase {
buildRules: [BuildRule(fileType: .pattern("*.xcassets"),
action: .script("pre_process_swift.py"),
name: "My Build Rule",
inputFiles: ["$(SRCROOT)/Assets.xcassets"],
outputFiles: ["$(SRCROOT)/Generated.swift"],
outputFilesCompilerFlags: ["foo"],
runOncePerArchitecture: false),
BuildRule(fileType: .type("sourcecode.swift"),
action: .compilerSpec("com.apple.xcode.tools.swift.compiler"),
name: nil,
inputFiles: [],
outputFiles: ["bar"],
outputFilesCompilerFlags: ["foo"],
runOncePerArchitecture: true)],
Expand Down
9 changes: 8 additions & 1 deletion Tests/ProjectSpecTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1481,19 +1481,26 @@ class SpecLoadingTests: XCTestCase {
"name": "My Rule",
"script": "my script",
"filePattern": "*.swift",
"inputFiles": ["$(SRCROOT)/Source File.swift", "$(DERIVED_FILE_DIR)/Generated.swift"],
"outputFiles": ["file1", "file2"],
"outputFilesCompilerFlags": ["-a", "-b"],
],
[
"compilerSpec": "apple.tool",
"fileType": "sourcecode.swift",
],
[
"compilerSpec": "apple.other-tool",
"filePattern": "*.metal",
"inputFiles": [],
],
]
target["buildRules"] = buildRules

let expectedBuildRules = [
BuildRule(fileType: .pattern("*.swift"), action: .script("my script"), name: "My Rule", outputFiles: ["file1", "file2"], outputFilesCompilerFlags: ["-a", "-b"]),
BuildRule(fileType: .pattern("*.swift"), action: .script("my script"), name: "My Rule", inputFiles: ["$(SRCROOT)/Source File.swift", "$(DERIVED_FILE_DIR)/Generated.swift"], outputFiles: ["file1", "file2"], outputFilesCompilerFlags: ["-a", "-b"]),
BuildRule(fileType: .type("sourcecode.swift"), action: .compilerSpec("apple.tool")),
BuildRule(fileType: .pattern("*.metal"), action: .compilerSpec("apple.other-tool"), inputFiles: []),
]

let parsedTarget = try Target(name: "test", jsonDictionary: target)
Expand Down
15 changes: 13 additions & 2 deletions Tests/XcodeGenKitTests/ProjectGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1515,23 +1515,31 @@ class ProjectGeneratorTests: XCTestCase {
fileType: .type("sourcecode.swift"),
action: .script("do thing"),
name: "My Rule",
inputFiles: ["$(SRCROOT)/Source File.swift", "$(DERIVED_FILE_DIR)/Generated.swift"],
outputFiles: ["file1.swift", "file2.swift"],
outputFilesCompilerFlags: ["--zee", "--bee"]
),
BuildRule(
fileType: .pattern("*.plist"),
action: .compilerSpec("com.apple.build-tasks.copy-plist-file")
),
BuildRule(
fileType: .pattern("*.metal"),
action: .compilerSpec("com.apple.compilers.metal"),
inputFiles: []
),
]
let pbxProject = try scriptSpec.generatePbxProj()

let buildRules = pbxProject.buildRules
try expect(buildRules.count) == 2
try expect(buildRules.count) == 3
let first = buildRules.first { $0.name == "My Rule" }!
let second = buildRules.first { $0.name != "My Rule" }!
let second = buildRules.first { $0.filePatterns == "*.plist" }!
let third = buildRules.first { $0.filePatterns == "*.metal" }!

try expect(first.name) == "My Rule"
try expect(first.isEditable) == true
try expect(first.inputFiles) == ["$(SRCROOT)/Source File.swift", "$(DERIVED_FILE_DIR)/Generated.swift"]
try expect(first.outputFiles) == ["file1.swift", "file2.swift"]
try expect(first.outputFilesCompilerFlags) == ["--zee", "--bee"]
try expect(first.script) == "do thing"
Expand All @@ -1544,8 +1552,11 @@ class ProjectGeneratorTests: XCTestCase {
try expect(second.filePatterns) == "*.plist"
try expect(second.compilerSpec) == "com.apple.build-tasks.copy-plist-file"
try expect(second.script).beNil()
try expect(second.inputFiles).beNil()
try expect(second.outputFiles) == []
try expect(second.outputFilesCompilerFlags) == []

try expect(third.inputFiles) == []
}

$0.it("generates dependency build file settings") {
Expand Down