From 60a0f64416720143c6945b817cf89a2344e25a07 Mon Sep 17 00:00:00 2001 From: min Date: Tue, 7 May 2019 20:42:44 -0700 Subject: [PATCH 1/5] Add support for no_codegen settings ATTRIBUTE --- Sources/ProjectSpec/TargetSource.swift | 6 +++- Sources/XcodeGenKit/SourceGenerator.swift | 11 ++++++- .../SourceGeneratorTests.swift | 33 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Sources/ProjectSpec/TargetSource.swift b/Sources/ProjectSpec/TargetSource.swift index 6ed21bff..e18dd3cc 100644 --- a/Sources/ProjectSpec/TargetSource.swift +++ b/Sources/ProjectSpec/TargetSource.swift @@ -14,6 +14,7 @@ public struct TargetSource: Equatable { public var buildPhase: BuildPhase? public var headerVisibility: HeaderVisibility? public var createIntermediateGroups: Bool? + public var noCodegen: Bool public enum HeaderVisibility: String { case `public` @@ -126,7 +127,8 @@ public struct TargetSource: Equatable { optional: Bool = false, buildPhase: BuildPhase? = nil, headerVisibility: HeaderVisibility? = nil, - createIntermediateGroups: Bool? = nil + createIntermediateGroups: Bool? = nil, + noCodegen: Bool = false ) { self.path = path self.name = name @@ -137,6 +139,7 @@ public struct TargetSource: Equatable { self.buildPhase = buildPhase self.headerVisibility = headerVisibility self.createIntermediateGroups = createIntermediateGroups + self.noCodegen = noCodegen } } @@ -178,6 +181,7 @@ extension TargetSource: JSONObjectConvertible { } createIntermediateGroups = jsonDictionary.json(atKeyPath: "createIntermediateGroups") + noCodegen = jsonDictionary.json(atKeyPath: "noCodegen") ?? false } } diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index 03305a4b..221d53b5 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -51,6 +51,7 @@ class SourceGenerator { func generateSourceFile(targetType: PBXProductType, targetSource: TargetSource, path: Path, buildPhase: TargetSource.BuildPhase? = nil) -> SourceFile { let fileReference = fileReferencesByPath[path.string.lowercased()]! var settings: [String: Any] = [:] + var attributes: [String] = [] var chosenBuildPhase: TargetSource.BuildPhase? let headerVisibility = targetSource.headerVisibility ?? .public @@ -77,16 +78,24 @@ class SourceGenerator { } } + if targetSource.noCodegen { + attributes.append("no_codegen") + } + if chosenBuildPhase == .headers { if headerVisibility != .project { // Xcode doesn't write the default of project - settings["ATTRIBUTES"] = [headerVisibility.settingName] + attributes.append(headerVisibility.settingName) } } if chosenBuildPhase == .sources && targetSource.compilerFlags.count > 0 { settings["COMPILER_FLAGS"] = targetSource.compilerFlags.joined(separator: " ") } + if !attributes.isEmpty { + settings["ATTRIBUTES"] = attributes + } + let buildFile = PBXBuildFile(file: fileReference, settings: settings.isEmpty ? nil : settings) return SourceFile( path: path, diff --git a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift index 0e718f75..40023642 100644 --- a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift @@ -644,6 +644,39 @@ class SourceGeneratorTests: XCTestCase { try pbxProj.expectFile(paths: ["../OtherDirectory", "Outside", "a.swift"], names: ["OtherDirectory", "Outside", "a.swift"], buildPhase: .sources) try pbxProj.expectFile(paths: ["../OtherDirectory", "Outside", "Outside2", "b.swift"], names: ["OtherDirectory", "Outside", "Outside2", "b.swift"], buildPhase: .sources) } + + $0.it("correctly adds no_codegen attribute") { + let directories = """ + A: + - Intent.intentdefinition + """ + try createDirectories(directories) + + let definition: String = "Intent.intentdefinition" + + let target = Target(name: "Test", type: .framework, platform: .iOS, sources: [ + TargetSource(path: "A/\(definition)", buildPhase: .sources, noCodegen: true) + ]) + let project = Project(basePath: directoryPath, name: "Test", targets: [target]) + + let pbxProj = try project.generatePbxProj() + + let fileReference = pbxProj.getFileReference( + paths: ["A", definition], + names: ["A", definition] + ) + guard let buildFile = pbxProj.buildFiles + .first(where: { $0.file == fileReference }) else { + throw failure("Cant find build file") + } + + + try pbxProj.expectFile(paths: ["A", definition], buildPhase: .sources) + + if (buildFile.settings! as NSDictionary) != (["ATTRIBUTES": ["no_codegen"]] as NSDictionary) { + throw failure("File does not contain no_codegen attribute") + } + } } } } From efb5951d13487ad9e05dd208d777d886ede3b721 Mon Sep 17 00:00:00 2001 From: min Date: Sat, 11 May 2019 08:36:24 -0700 Subject: [PATCH 2/5] Allow more flexibility by accepting an [String] for attributes --- Docs/ProjectSpec.md | 1 + Sources/ProjectSpec/TargetSource.swift | 8 ++++---- Sources/XcodeGenKit/SourceGenerator.swift | 6 +----- Tests/XcodeGenKitTests/SourceGeneratorTests.swift | 5 ++--- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index ff8ba02f..34af5581 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -326,6 +326,7 @@ A source can be provided via a string (the path) or an object of the form: - `public` - `private` - `project` +- [ ] **attributes**: **[String]** - Additional settings attributes for the file reference. ```yaml targets: diff --git a/Sources/ProjectSpec/TargetSource.swift b/Sources/ProjectSpec/TargetSource.swift index e18dd3cc..3611e2be 100644 --- a/Sources/ProjectSpec/TargetSource.swift +++ b/Sources/ProjectSpec/TargetSource.swift @@ -14,7 +14,7 @@ public struct TargetSource: Equatable { public var buildPhase: BuildPhase? public var headerVisibility: HeaderVisibility? public var createIntermediateGroups: Bool? - public var noCodegen: Bool + public var attributes: [String] public enum HeaderVisibility: String { case `public` @@ -128,7 +128,7 @@ public struct TargetSource: Equatable { buildPhase: BuildPhase? = nil, headerVisibility: HeaderVisibility? = nil, createIntermediateGroups: Bool? = nil, - noCodegen: Bool = false + attributes: [String] = [] ) { self.path = path self.name = name @@ -139,7 +139,7 @@ public struct TargetSource: Equatable { self.buildPhase = buildPhase self.headerVisibility = headerVisibility self.createIntermediateGroups = createIntermediateGroups - self.noCodegen = noCodegen + self.attributes = attributes } } @@ -181,7 +181,7 @@ extension TargetSource: JSONObjectConvertible { } createIntermediateGroups = jsonDictionary.json(atKeyPath: "createIntermediateGroups") - noCodegen = jsonDictionary.json(atKeyPath: "noCodegen") ?? false + attributes = jsonDictionary.json(atKeyPath: "attributes") ?? [] } } diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index 221d53b5..c6d1c50a 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -51,7 +51,7 @@ class SourceGenerator { func generateSourceFile(targetType: PBXProductType, targetSource: TargetSource, path: Path, buildPhase: TargetSource.BuildPhase? = nil) -> SourceFile { let fileReference = fileReferencesByPath[path.string.lowercased()]! var settings: [String: Any] = [:] - var attributes: [String] = [] + var attributes: [String] = targetSource.attributes var chosenBuildPhase: TargetSource.BuildPhase? let headerVisibility = targetSource.headerVisibility ?? .public @@ -78,10 +78,6 @@ class SourceGenerator { } } - if targetSource.noCodegen { - attributes.append("no_codegen") - } - if chosenBuildPhase == .headers { if headerVisibility != .project { // Xcode doesn't write the default of project diff --git a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift index 40023642..6aa9e668 100644 --- a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift @@ -645,7 +645,7 @@ class SourceGeneratorTests: XCTestCase { try pbxProj.expectFile(paths: ["../OtherDirectory", "Outside", "Outside2", "b.swift"], names: ["OtherDirectory", "Outside", "Outside2", "b.swift"], buildPhase: .sources) } - $0.it("correctly adds no_codegen attribute") { + $0.it("correctly adds target source attributes") { let directories = """ A: - Intent.intentdefinition @@ -655,7 +655,7 @@ class SourceGeneratorTests: XCTestCase { let definition: String = "Intent.intentdefinition" let target = Target(name: "Test", type: .framework, platform: .iOS, sources: [ - TargetSource(path: "A/\(definition)", buildPhase: .sources, noCodegen: true) + TargetSource(path: "A/\(definition)", buildPhase: .sources, attributes: ["no_codegen"]) ]) let project = Project(basePath: directoryPath, name: "Test", targets: [target]) @@ -670,7 +670,6 @@ class SourceGeneratorTests: XCTestCase { throw failure("Cant find build file") } - try pbxProj.expectFile(paths: ["A", definition], buildPhase: .sources) if (buildFile.settings! as NSDictionary) != (["ATTRIBUTES": ["no_codegen"]] as NSDictionary) { From 848963db99ae0bc464a2f07549c58729a789627d Mon Sep 17 00:00:00 2001 From: Min Kim Date: Thu, 13 Jun 2019 21:30:51 -0700 Subject: [PATCH 3/5] Update Docs/ProjectSpec.md Co-Authored-By: Yonas Kolb --- Docs/ProjectSpec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index 34af5581..40ec1450 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -326,7 +326,7 @@ A source can be provided via a string (the path) or an object of the form: - `public` - `private` - `project` -- [ ] **attributes**: **[String]** - Additional settings attributes for the file reference. +- [ ] **attributes**: **[String]** - Additional settings attributes that will be applied to any build files. ```yaml targets: From 885033b1bf0f8ce6c3cb7065ce30dfc2a66ad1c7 Mon Sep 17 00:00:00 2001 From: min Date: Thu, 13 Jun 2019 21:36:25 -0700 Subject: [PATCH 4/5] Update Changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d13a787..e681dadf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Next Version +## 2.6.0 + +#### Added +- Added ability to set `attributes` on build files [#583](https://github.com/yonaskolb/XcodeGen/pull/583) @min + ## 2.5.0 #### Added From c68393c35d8f1bd52bb7fdb2ef4f038599eafa6e Mon Sep 17 00:00:00 2001 From: min Date: Thu, 13 Jun 2019 21:57:03 -0700 Subject: [PATCH 5/5] Fix added heading --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f685f4a..d408ce4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next Version +#### Added - Added ability to encode ProjectSpec to JSON [#545](https://github.com/yonaskolb/XcodeGen/pull/545) @ryohey - Added ability to skip tests [#582](https://github.com/yonaskolb/XcodeGen/pull/582) @kadarandras - Added ability to set `attributes` on build files [#583](https://github.com/yonaskolb/XcodeGen/pull/583) @min