Fix localized variant groups across targets and support folder resources - #1640
Open
eschwieb wants to merge 2 commits into
Open
Fix localized variant groups across targets and support folder resources#1640eschwieb wants to merge 2 commits into
eschwieb wants to merge 2 commits into
Conversation
Localized resources can be shared by several targets, but each target may include a different set of languages. XcodeGen was reusing the same variant groups and file references across those targets. Since an Xcode file reference can only have one parent, processing a later target could pull a child away from an earlier group or leave a same-named group detached from the project hierarchy. Use a separate variant-group cache for each target, while still reusing groups across source entries within that target. Localized file references are now cached together with their owning variant group, while ordinary file references continue to be shared across the project. The new tests cover targets with both different and identical language selections, direct and localized uses of the same file, storyboard resources split across source entries, and the final relationships after writing and reopening the generated project.
XcodeGen could create variant groups for localized files, but directories inside .lproj folders had no file type and were not added to the resources phase. This prevented resources such as localized Help folders from being copied by Xcode. Treat these directories as folder references and add their variant groups to the resources phase. Allow a non-base localization to create the group when necessary, while keeping folders separate from same-named localized files. Add coverage for serialized folder groups, mixed folder and XIB resources, target-specific language selections, folders missing from Base, and same-stem folder/file collisions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
XcodeGen reused localized variant groups and their child file references across targets. That works only when every target uses the same localizations. If two targets selected different languages, generating the second target could move shared references out of the first target’s variant group or leave a same-named variant group detached from the project hierarchy.
XcodeGen also did not handle directories inside
.lprojfolders as localized folder resources. A structure such as:needs to become a
Helpvariant group whose language children are folder references. Previously, the children had no folder type and the variant group was not added to the resources phase, so Xcode would not copy the localized directories correctly.What changed
Variant groups are now kept separate for each target, and localized child references are scoped to the variant group that owns them. Ordinary file references remain shared across the project.
Localized directories are now emitted as folder references and their variant groups are added to the resources phase. A non-base localization can create the folder variant group when the folder is missing from
Base.lprojor when a target selects only another language.Folder matching is also kept separate from extension-insensitive file matching, so resources such as
Help/andHelp.stringsdo not accidentally end up in the same variant group.Tests
The new tests cover:
The complete Swift test suite passes.
Developed with assistance from GitHub Copilot. I did human review of each step along the way, and verified this addresses the issues we found in downstream code.