Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some resource files being placed to "Recovered References" group #679

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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