diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c720278..ad0bdec5 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 diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index a041fd42..b7659d2e 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? @@ -452,12 +452,10 @@ class SourceGenerator { groupChildren.append(variantGroup) baseLocalisationVariantGroups.append(variantGroup) - let sourceFile = SourceFile( - path: filePath, - fileReference: variantGroup, - buildFile: PBXBuildFile(file: variantGroup), - buildPhase: .resources - ) + let sourceFile = generateSourceFile(targetType: targetType, + targetSource: targetSource, + path: filePath, + fileRefenrece: variantGroup) allSourceFiles.append(sourceFile) } } @@ -491,12 +489,10 @@ 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, + fileRefenrece: fileReference) allSourceFiles.append(sourceFile) groupChildren.append(fileReference) } diff --git a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift index 13fdd01d..1e903ab3 100644 --- a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift @@ -833,6 +833,64 @@ class SourceGeneratorTests: XCTestCase { try pbxProj.expectFileMissing(paths: ["Sources", "group2", "file.swift"]) try pbxProj.expectFileMissing(paths: ["Sources", "group", "file.swift"]) } + + $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.buildPhase == .sources }) + try expect(sourceBuildPhase.files?.compactMap { $0.file?.nameOrPath }) == ["Intents.intentdefinition"] + } + } + + $0.context("With localized sources with buildPhase") { + $0.it("*.intentdefinition with buildPhase should be added to resource 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"] + } + } + } } } }