From 2277b323f217b0087a545fef9028dcfc386d6126 Mon Sep 17 00:00:00 2001 From: Sascha Schwabbauer Date: Tue, 12 Jan 2021 23:51:11 +0100 Subject: [PATCH] Add support for runOncePerArchitecture (#950) Add changelog and small change Fix build error --- CHANGELOG.md | 1 + Docs/ProjectSpec.md | 2 ++ Sources/ProjectSpec/BuildRule.swift | 17 ++++++++++++++++- Sources/XcodeGenKit/PBXProjGenerator.swift | 3 ++- Tests/ProjectSpecTests/ProjectSpecTests.swift | 6 ++++-- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a56707f..3b2929c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Add `useBaseInternationalization` to Project Spec Options to opt out of Base Internationalization. [#961](https://github.com/yonaskolb/XcodeGen/pull/961) @liamnichols - More detailed error message with method arguments. [#990](https://github.com/yonaskolb/XcodeGen/pull/990) @bannzai - Added `basedOnDependencyAnalysis` to Project Spec Build Script to be able to choose not to skip the script. [#992](https://github.com/yonaskolb/XcodeGen/pull/992) @myihsan +- Add `BuildRule.runOncePerArchitecture` to allow running build rules once per architecture. [#950](https://github.com/yonaskolb/XcodeGen/pull/950) @sascha #### Changed - **Breaking**: Info.plists with custom prefixes are no longer added to the Copy Bundle Resources build phase [#945](https://github.com/yonaskolb/XcodeGen/pull/945) @anivaros diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index e7374fe7..4cf4f2a1 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -605,6 +605,7 @@ targets: - [ ] **name**: **String** - The name of a build rule. Defaults to `Build Rule` - [ ] **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 ```yaml targets: @@ -619,6 +620,7 @@ targets: compilerSpec: com.apple.xcode.tools.swift.compiler outputFiles: - $(SRCROOT)/Generated.swift + runOncePerArchitecture: false ``` ### Target Scheme diff --git a/Sources/ProjectSpec/BuildRule.swift b/Sources/ProjectSpec/BuildRule.swift index 760b57c7..f5fefc01 100644 --- a/Sources/ProjectSpec/BuildRule.swift +++ b/Sources/ProjectSpec/BuildRule.swift @@ -5,6 +5,7 @@ public struct BuildRule: Equatable { public static let scriptCompilerSpec = "com.apple.compilers.proxy.script" public static let filePatternFileType = "pattern.proxy" + public static let runOncePerArchitectureDefault = true public enum FileType: Equatable { case type(String) @@ -49,13 +50,22 @@ public struct BuildRule: Equatable { public var outputFiles: [String] public var outputFilesCompilerFlags: [String] public var name: String? + public var runOncePerArchitecture: Bool - public init(fileType: FileType, action: Action, name: String? = nil, outputFiles: [String] = [], outputFilesCompilerFlags: [String] = []) { + public init( + fileType: FileType, + action: Action, + name: String? = nil, + outputFiles: [String] = [], + outputFilesCompilerFlags: [String] = [], + runOncePerArchitecture: Bool = runOncePerArchitectureDefault + ) { self.fileType = fileType self.action = action self.name = name self.outputFiles = outputFiles self.outputFilesCompilerFlags = outputFilesCompilerFlags + self.runOncePerArchitecture = runOncePerArchitecture } } @@ -78,6 +88,7 @@ extension BuildRule: JSONObjectConvertible { outputFiles = jsonDictionary.json(atKeyPath: "outputFiles") ?? [] outputFilesCompilerFlags = jsonDictionary.json(atKeyPath: "outputFilesCompilerFlags") ?? [] name = jsonDictionary.json(atKeyPath: "name") + runOncePerArchitecture = jsonDictionary.json(atKeyPath: "runOncePerArchitecture") ?? BuildRule.runOncePerArchitectureDefault } } @@ -103,6 +114,10 @@ extension BuildRule: JSONEncodable { dict["script"] = string } + if runOncePerArchitecture != BuildRule.runOncePerArchitectureDefault { + dict["runOncePerArchitecture"] = runOncePerArchitecture + } + return dict } } diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index 7327c65c..52060d93 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -1150,7 +1150,8 @@ public class PBXProjGenerator { name: buildRule.name ?? "Build Rule", outputFiles: buildRule.outputFiles, outputFilesCompilerFlags: buildRule.outputFilesCompilerFlags, - script: buildRule.action.script + script: buildRule.action.script, + runOncePerArchitecture: buildRule.runOncePerArchitecture ) ) } diff --git a/Tests/ProjectSpecTests/ProjectSpecTests.swift b/Tests/ProjectSpecTests/ProjectSpecTests.swift index d9112a01..2878697d 100644 --- a/Tests/ProjectSpecTests/ProjectSpecTests.swift +++ b/Tests/ProjectSpecTests/ProjectSpecTests.swift @@ -414,12 +414,14 @@ class ProjectSpecTests: XCTestCase { action: .script("pre_process_swift.py"), name: "My Build Rule", outputFiles: ["$(SRCROOT)/Generated.swift"], - outputFilesCompilerFlags: ["foo"]), + outputFilesCompilerFlags: ["foo"], + runOncePerArchitecture: false), BuildRule(fileType: .type("sourcecode.swift"), action: .compilerSpec("com.apple.xcode.tools.swift.compiler"), name: nil, outputFiles: ["bar"], - outputFilesCompilerFlags: ["foo"])], + outputFilesCompilerFlags: ["foo"], + runOncePerArchitecture: true)], scheme: TargetScheme(testTargets: [Scheme.Test.TestTarget(targetReference: "test target", randomExecutionOrder: false, parallelizable: false)],