From decaa9d08065e23b93b173c94fa722d4c08d5cff Mon Sep 17 00:00:00 2001 From: giginet Date: Fri, 8 Nov 2019 02:12:10 +0900 Subject: [PATCH 1/9] Generate suitable source files for localized file reference --- Sources/XcodeGenKit/SourceGenerator.swift | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index 0b6e96c9..82b58bf8 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -491,12 +491,9 @@ class SourceGenerator { } } else { // add SourceFile to group if there is no Base.lproj directory - let sourceFile = SourceFile( - path: filePath, - fileReference: fileReference, - buildFile: PBXBuildFile(file: fileReference), - buildPhase: .resources - ) + let sourceFile = generateSourceFile(targetType: targetType, + targetSource: targetSource, + path: filePath) allSourceFiles.append(sourceFile) groupChildren.append(fileReference) } From ae75bcb2cb2fe93761e2852311f099fe700f24d5 Mon Sep 17 00:00:00 2001 From: giginet Date: Fri, 8 Nov 2019 02:52:50 +0900 Subject: [PATCH 2/9] Localized --- Sources/XcodeGenKit/SourceGenerator.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index 82b58bf8..6ad49427 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -452,13 +452,16 @@ class SourceGenerator { groupChildren.append(variantGroup) baseLocalisationVariantGroups.append(variantGroup) - let sourceFile = SourceFile( + let fileReference = getFileReference( path: filePath, - fileReference: variantGroup, - buildFile: PBXBuildFile(file: variantGroup), - buildPhase: .resources + inPath: baseLocalisedDirectory, + name: variantGroup.name ?? filePath.lastComponent ) + let sourceFile = generateSourceFile(targetType: targetType, + targetSource: targetSource, + path: filePath) allSourceFiles.append(sourceFile) + groupChildren.append(fileReference) } } From b1b216b1b5dd792ee55ec2c4865c7b6991941429 Mon Sep 17 00:00:00 2001 From: giginet Date: Fri, 8 Nov 2019 04:02:26 +0900 Subject: [PATCH 3/9] Use VariantGroup --- Sources/XcodeGenKit/SourceGenerator.swift | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index 6ad49427..892983b6 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -81,8 +81,8 @@ class SourceGenerator { _ = try getSourceFiles(targetType: .none, targetSource: TargetSource(path: path), path: fullPath) } - func generateSourceFile(targetType: PBXProductType, targetSource: TargetSource, path: Path, buildPhase: TargetSource.BuildPhase? = nil) -> SourceFile { - let fileReference = fileReferencesByPath[path.string.lowercased()]! + func generateSourceFile(targetType: PBXProductType, targetSource: TargetSource, path: Path, buildPhase: TargetSource.BuildPhase? = nil, fileRefenrece: PBXFileElement? = nil) -> SourceFile { + let fileReference = fileRefenrece ?? fileReferencesByPath[path.string.lowercased()]! var settings: [String: Any] = [:] var attributes: [String] = targetSource.attributes var chosenBuildPhase: TargetSource.BuildPhase? @@ -451,17 +451,12 @@ class SourceGenerator { let variantGroup = getVariantGroup(path: filePath, inPath: path) groupChildren.append(variantGroup) baseLocalisationVariantGroups.append(variantGroup) - - let fileReference = getFileReference( - path: filePath, - inPath: baseLocalisedDirectory, - name: variantGroup.name ?? filePath.lastComponent - ) + let sourceFile = generateSourceFile(targetType: targetType, targetSource: targetSource, - path: filePath) + path: filePath, + fileRefenrece: variantGroup) allSourceFiles.append(sourceFile) - groupChildren.append(fileReference) } } @@ -496,7 +491,8 @@ class SourceGenerator { // add SourceFile to group if there is no Base.lproj directory let sourceFile = generateSourceFile(targetType: targetType, targetSource: targetSource, - path: filePath) + path: filePath, + fileRefenrece: fileReference) allSourceFiles.append(sourceFile) groupChildren.append(fileReference) } From c5e9f07a5372db063060f2ca695e6143d2597494 Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 19 Nov 2019 03:00:08 +0900 Subject: [PATCH 4/9] Add tests to add intentdefinition to build source phases --- Sources/XcodeGenKit/SourceGenerator.swift | 2 +- .../SourceGeneratorTests.swift | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index 1b6788c7..b7659d2e 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -451,7 +451,7 @@ class SourceGenerator { let variantGroup = getVariantGroup(path: filePath, inPath: path) groupChildren.append(variantGroup) baseLocalisationVariantGroups.append(variantGroup) - + let sourceFile = generateSourceFile(targetType: targetType, targetSource: targetSource, path: filePath, diff --git a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift index 13fdd01d..f3b7f5eb 100644 --- a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift @@ -833,6 +833,34 @@ class SourceGeneratorTests: XCTestCase { try pbxProj.expectFileMissing(paths: ["Sources", "group2", "file.swift"]) try pbxProj.expectFileMissing(paths: ["Sources", "group", "file.swift"]) } + + $0.context("With localized sources") { + $0.it("*.intentdefinition should be added to source phase") { + let directories = """ + Sources: + Base.lproj: + - Intents.intentdefinition + en.lproj: + - Intents.strings + ja.lproj: + - Intents.strings + """ + try createDirectories(directories) + let directoryPath = Path("TestDirectory") + + let target = Target(name: "IntentDefinitions", + type: .application, + platform: .iOS, + sources: [TargetSource(path: "Sources")]) + let project = Project(basePath: directoryPath, + name: "IntendDefinitions", + targets: [target]) + let pbxProj = try project.generatePbxProj() + let sourceBuildPhase = try unwrap(pbxProj.buildPhases.first { $0 as? PBXSourcesBuildPhase != nil }) as! PBXSourcesBuildPhase + let files = sourceBuildPhase.files?.compactMap { $0.file?.nameOrPath } + try expect(files) == ["Intents.intentdefinition"] + } + } } } } From d441a046d0b3b70b9c7bc9be292c242d4e17cb92 Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 19 Nov 2019 03:31:20 +0900 Subject: [PATCH 5/9] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c720278..257c9c92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Improved variable expansion runtime [#704](https://github.com/yonaskolb/XcodeGen/pull/704) @rcari - Fixed missing headers for static framework targets [#705](https://github.com/yonaskolb/XcodeGen/pull/705) @wag-miles - Using more file types from XcodeProj for PBXFileReferences resulting in less project diffs [#715](https://github.com/yonaskolb/XcodeGen/pull/715) @yonaskolb +- Fixed localized *intentdefinition have to be added to build source phases [#720](https://github.com/yonaskolb/XcodeGen/pull/720) @giginet #### Changed - Deprecated `$old_form` variables in favor of `${new_form}` variables [#704](https://github.com/yonaskolb/XcodeGen/pull/704) @rcari @@ -36,7 +37,7 @@ - Add base localisation by default even if no base localised files were found. Fixes warning in Xcode 11 [#685](https://github.com/yonaskolb/XcodeGen/pull/685) @yonaskolb - Don't generate CFBundleExecutable in default generated Info.plist for `bundle` target types [#689](https://github.com/yonaskolb/XcodeGen/pull/689) @FranzBusch - Fixed resolving relative paths with custom project destination [#681](https://github.com/yonaskolb/XcodeGen/pull/681) @giginet -- Fixed resolving relative paths for Info.plist [#683](https://github.com/yonaskolb/XcodeGen/pull/683) +- Fixed resolving relative paths for Info.plist [#683](https://github.com/yonaskolb/XcodeGen/pull/683) @giginet - Fixed macOS unit test target TEST_HOST [#696](https://github.com/yonaskolb/XcodeGen/pull/696) @mjarvis #### Internal From e24fa881da324dfe736f6acce470359d60614e0c Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 19 Nov 2019 03:35:51 +0900 Subject: [PATCH 6/9] Tweak --- Tests/XcodeGenKitTests/SourceGeneratorTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift index f3b7f5eb..757bb5d9 100644 --- a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift @@ -856,7 +856,7 @@ class SourceGeneratorTests: XCTestCase { name: "IntendDefinitions", targets: [target]) let pbxProj = try project.generatePbxProj() - let sourceBuildPhase = try unwrap(pbxProj.buildPhases.first { $0 as? PBXSourcesBuildPhase != nil }) as! PBXSourcesBuildPhase + let sourceBuildPhase = try unwrap(pbxProj.buildPhases.first { $0 as? PBXSourcesBuildPhase != nil } as? PBXSourcesBuildPhase) let files = sourceBuildPhase.files?.compactMap { $0.file?.nameOrPath } try expect(files) == ["Intents.intentdefinition"] } From 793c2762502272bd8fe84defcda75fc226ff9395 Mon Sep 17 00:00:00 2001 From: Kohki Miki Date: Tue, 19 Nov 2019 03:36:42 +0900 Subject: [PATCH 7/9] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 257c9c92..ad0bdec5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ - Improved variable expansion runtime [#704](https://github.com/yonaskolb/XcodeGen/pull/704) @rcari - Fixed missing headers for static framework targets [#705](https://github.com/yonaskolb/XcodeGen/pull/705) @wag-miles - Using more file types from XcodeProj for PBXFileReferences resulting in less project diffs [#715](https://github.com/yonaskolb/XcodeGen/pull/715) @yonaskolb -- Fixed localized *intentdefinition have to be added to build source phases [#720](https://github.com/yonaskolb/XcodeGen/pull/720) @giginet +- Fixed localized *.intentdefinition have to be added to build source phases [#720](https://github.com/yonaskolb/XcodeGen/pull/720) @giginet #### Changed - Deprecated `$old_form` variables in favor of `${new_form}` variables [#704](https://github.com/yonaskolb/XcodeGen/pull/704) @rcari From 5e9a2a96518e9e5aea15c630a10bc64051ef6544 Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 19 Nov 2019 04:32:22 +0900 Subject: [PATCH 8/9] Add test case with buildPhase --- .../SourceGeneratorTests.swift | 78 +++++++++++++------ 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift index 757bb5d9..0ae2aaa4 100644 --- a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift @@ -834,31 +834,61 @@ class SourceGeneratorTests: XCTestCase { try pbxProj.expectFileMissing(paths: ["Sources", "group", "file.swift"]) } - $0.context("With localized sources") { - $0.it("*.intentdefinition should be added to source phase") { - let directories = """ - Sources: - Base.lproj: - - Intents.intentdefinition - en.lproj: - - Intents.strings - ja.lproj: - - Intents.strings - """ - try createDirectories(directories) - let directoryPath = Path("TestDirectory") + $0.describe("Localized sources") { + $0.context("With localized sources") { + $0.it("*.intentdefinition should be added to source phase") { + let directories = """ + Sources: + Base.lproj: + - Intents.intentdefinition + en.lproj: + - Intents.strings + ja.lproj: + - Intents.strings + """ + try createDirectories(directories) + let directoryPath = Path("TestDirectory") - let target = Target(name: "IntentDefinitions", - type: .application, - platform: .iOS, - sources: [TargetSource(path: "Sources")]) - let project = Project(basePath: directoryPath, - name: "IntendDefinitions", - targets: [target]) - let pbxProj = try project.generatePbxProj() - let sourceBuildPhase = try unwrap(pbxProj.buildPhases.first { $0 as? PBXSourcesBuildPhase != nil } as? PBXSourcesBuildPhase) - let files = sourceBuildPhase.files?.compactMap { $0.file?.nameOrPath } - try expect(files) == ["Intents.intentdefinition"] + let target = Target(name: "IntentDefinitions", + type: .application, + platform: .iOS, + sources: [TargetSource(path: "Sources")]) + let project = Project(basePath: directoryPath, + name: "IntendDefinitions", + targets: [target]) + let pbxProj = try project.generatePbxProj() + let sourceBuildPhase = try unwrap(pbxProj.buildPhases.first { $0.buildPhase == .sources }) + try expect(sourceBuildPhase.files?.compactMap { $0.file?.nameOrPath }) == ["Intents.intentdefinition"] + } + } + + $0.context("With localized sources with buildPhase") { + $0.it("*.intentdefinition should be added to source phase") { + let directories = """ + Sources: + Base.lproj: + - Intents.intentdefinition + en.lproj: + - Intents.strings + ja.lproj: + - Intents.strings + """ + try createDirectories(directories) + let directoryPath = Path("TestDirectory") + + let target = Target(name: "IntentDefinitions", + type: .application, + platform: .iOS, + sources: [TargetSource(path: "Sources", buildPhase: .resources)]) + let project = Project(basePath: directoryPath, + name: "IntendDefinitions", + targets: [target]) + let pbxProj = try project.generatePbxProj() + let sourceBuildPhase = try unwrap(pbxProj.buildPhases.first { $0.buildPhase == .sources }) + let resourcesBuildPhase = try unwrap(pbxProj.buildPhases.first { $0.buildPhase == .resources }) + try expect(sourceBuildPhase.files) == [] + try expect(resourcesBuildPhase.files?.compactMap { $0.file?.nameOrPath }) == ["Intents.intentdefinition"] + } } } } From cad36baa6d2f4fdf5031c918079e90e709026a7d Mon Sep 17 00:00:00 2001 From: Kohki Miki Date: Tue, 19 Nov 2019 04:38:05 +0900 Subject: [PATCH 9/9] Update SourceGeneratorTests.swift --- Tests/XcodeGenKitTests/SourceGeneratorTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift index 0ae2aaa4..1e903ab3 100644 --- a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift @@ -863,7 +863,7 @@ class SourceGeneratorTests: XCTestCase { } $0.context("With localized sources with buildPhase") { - $0.it("*.intentdefinition should be added to source phase") { + $0.it("*.intentdefinition with buildPhase should be added to resource phase") { let directories = """ Sources: Base.lproj: