Skip to content

Commit

Permalink
Merge pull request #679 from nivanchikov/fix_localized_resources_with…
Browse files Browse the repository at this point in the history
…_directories

Fix some resource files being placed to "Recovered References" group
  • Loading branch information
yonaskolb authored Oct 8, 2019
2 parents 27564f9 + d5cfc58 commit 3e1b965
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Fixed macOS unit test setting preset [#665](https://github.com/yonaskolb/XcodeGen/pull/665) @yonaskolb
- Add `rcproject` files to sources build phase instead of resources [#669](https://github.com/yonaskolb/XcodeGen/pull/669) @Qusic
- Prefer default configuration names for generated schemes [#673](https://github.com/yonaskolb/XcodeGen/pull/673) @giginet
- Fixed some resource files being placed to "Recovered References" group [#679](https://github.com/yonaskolb/XcodeGen/pull/679) @nivanchikov

#### Internal

Expand Down
2 changes: 1 addition & 1 deletion Sources/XcodeGenKit/SourceGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class SourceGenerator {
for child in children {
// only add the children that aren't already in the cachedGroup
// Check equality by path and sourceTree because XcodeProj.PBXObject.== is very slow.
if !cachedGroupChildren.contains(where: { $0.path == child.path && $0.sourceTree == child.sourceTree }) {
if !cachedGroupChildren.contains(where: { $0.name == child.name && $0.path == child.path && $0.sourceTree == child.sourceTree }) {
cachedGroupChildren.append(child)
}
}
Expand Down
63 changes: 63 additions & 0 deletions Tests/XcodeGenKitTests/SourceGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,69 @@ class SourceGeneratorTests: XCTestCase {
try expect(variableGroup.children.filter { $0 == refs.first }.count) == 1
}
}

$0.it("handles localized resources") {
let directories = """
App:
Resources:
en-CA.lproj:
- empty.json
- Localizable.strings
en-US.lproj:
- empty.json
- Localizable.strings
en.lproj:
- empty.json
- Localizable.strings
fonts:
SFUI:
- SFUILight.ttf
"""
try createDirectories(directories)

let target = Target(name: "Test", type: .application, platform: .iOS, sources: [TargetSource(path: "App/Resources")])

let options = SpecOptions(createIntermediateGroups: true)
let project = Project(basePath: directoryPath, name: "Test", targets: [target], options: options)

let outputXcodeProj = try project.generateXcodeProject()
try outputXcodeProj.write(path: directoryPath)

let inputXcodeProj = try XcodeProj(path: directoryPath)
let pbxProj = inputXcodeProj.pbxproj

func getFileReferences(_ path: String) -> [PBXFileReference] {
return pbxProj.fileReferences.filter { $0.path == path }
}

func getVariableGroups(_ name: String?) -> [PBXVariantGroup] {
return pbxProj.variantGroups.filter { $0.name == name }
}

let stringsResourceName = "Localizable.strings"
let jsonResourceName = "empty.json"

guard let stringsVariableGroup = getVariableGroups(stringsResourceName).first else { throw failure("Couldn't find the variable group") }

guard let jsonVariableGroup = getVariableGroups(jsonResourceName).first else { throw failure("Couldn't find the variable group") }

let stringsResource = "en.lproj/Localizable.strings"
let jsonResource = "en-CA.lproj/empty.json"

do {
let refs = getFileReferences(stringsResource)
try expect(refs.count) == 1
try expect(refs.first!.uuid.hasPrefix("TEMP")) == false
try expect(stringsVariableGroup.children.filter { $0 == refs.first }.count) == 1
}

do {
let refs = getFileReferences(jsonResource)
try expect(refs.count) == 1
try expect(refs.first!.uuid.hasPrefix("TEMP")) == false
try expect(jsonVariableGroup.children.filter { $0 == refs.first }.count) == 1
}
}

$0.it("handles duplicate names") {
let directories = """
Expand Down

0 comments on commit 3e1b965

Please sign in to comment.