-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 issues with variant group, versioned, and asset catalog resources #4635
Fix issues with variant group, versioned, and asset catalog resources #4635
Conversation
@efirestone this looks absolutely awesome! I'm swamped with finals now so it might take me a bit to get around to reviewing this, but thank you for opening the PR :D |
No problem at all. Let me know if there's anything I can do to help, and good luck with finals! |
# | ||
# @return [Array<Pathname>] The paths which can be added to the Xcode project | ||
# | ||
def allowable_project_paths(paths) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done as a separate pass because it needs to determine which .lproj
directories are only added directly (without adding any of its children), and therefore needs access to the entire paths list. This was to preserve the existing behavior of non-recursive Resources/*
globs. If we don't care/stop caring about that behavior then this filtering can be added in-line in the paths.each
on L181 and just remove all items ending in .lproj
. I think as-implemented is the right behavior and likely always will be.
Biggest help would be a project / podspec I can eventually turn into an integration spec (ideally just a showcase of all the different cases you've addressed) |
@@ -98,6 +98,7 @@ def add_files_to_build_phases | |||
resource_refs = file_accessor.resources.flatten.map do |res| | |||
project.reference_for_path(res) | |||
end | |||
resource_refs.compact! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some resource files in the glob no longer have direct corresponding file references. This includes things like files within an xcdatamodeld
directory or xcassets
directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a comment to that effect would be excellent!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. I commented on the one just below this, but worth repeating here.
a892c21
to
7f59208
Compare
For the sample project: I added all the sample cases I could think of to the BananaLib fixture. You would just need to change from |
path_str = path.to_s.downcase | ||
|
||
# We add the directory for a Core Data model, but not the items in it. | ||
next false if path_str =~ /.*xcdatamodeld\/.+/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of these next false
can just be next
3c6c093
to
d386c79
Compare
Looks good! @neonichu / @manuyavuz want to have a stab at this? |
Looks good from my end. Especially like the detailed comments, great work, @efirestone! An additional integration spec would indeed be great, though, maybe you can share the example(s) you used to test against Xcode? |
The BananaLib tarball now includes all of them, and you can see the differences here Namely, the following cases are important: Base Internationalization of XIB/Storyboards - If files exist named General Localized Files - If files exist with the same name in different localization folders (like Nested Localized Files - If directories exist with the same name in different localization folders (like Core Data Models with Multiple Versions - Create a Core Data model, then add a version by going to Image Asset Catalog - Create a standard asset catalog. This is actually just a |
After actually going through that, let me check that core data models are being put into the right build phase. I believe they may be added to |
CoreData models are indeed going into Thoughts @segiddins & @neonichu? I can add a special case in the "add resources" code to add these files to the compile phase instead of resources (matches Xcode), or we can just leave them as being copied into the resources phase (less code to maintain). Both work equally well. |
file_ref.should.be.not.nil | ||
end | ||
|
||
it "doesn't add file references for files within Asset Catalogs" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be inside 'Installation With Recursive Resources Glob'
section? BananaLib adds resources non-recursively by default, also explicitly sets xcassets path. This scenario seems to not testing your aim because there will be no resource paths for Pods/BananaLib/Resources/Images.xcassets/Logo.imageset/logo.png for example. Am I missing sth?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, good catch. Will move.
@efirestone this is great, really liked the good documentation and test coverage! I have one little concern that I commented on the code, other than that, one more LGTM. |
d386c79
to
3b85a59
Compare
Thanks guys! Everything's updated and should be ready to merge. There's the one outstanding question of whether we should automatically be adding Core Data models to the Arguments for
Arguments for
My slight personal inclination is to leave it in |
Let's leave it for now, but add a |
config.sandbox.project = @project | ||
|
||
@spec = fixture_spec('banana-lib/BananaLib.podspec') | ||
@spec.resource_bundle = { 'banana_bundle' => ['Resources/**/*'] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we should also set resources
attribute to nil because current state will cause resources to be added multiple times to the project, which is not the case you want to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and done.
3b85a59
to
6040dab
Compare
@segiddins Added |
Great! 🛥 |
Anything left before we can hit the merge button? |
I'll do a final review in the next couple of days |
👍 |
path_str = path.to_s.downcase | ||
|
||
# We add the directory for a Core Data model, but not the items in it. | ||
next if path_str =~ /.*xcdatamodeld\/.+/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.*\.xc
? (for the next line as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, along with the xcassets
regex below it.
👍 other than that one nitpick |
6040dab
to
5b6ec48
Compare
Fix issues with variant group, versioned, and asset catalog resources
Addresses issue #1653.
Summary
Xcode represents certain resources specially in its project structure, and without that special representation they will fail to be compiled correctly. The notable special cases are:
en.lproj/image.png
andde.lproj/image.png
are represented as a "variant group" namedimage.png
with two localizations within the Xcode project.Base.lproj/Main.xib
anden.lproj/Main.strings
are represented as a variant group namedMain.xib
xcdatamodeld
directory, and within them have individual versions with anxcdatamodel
extension. These are represented in the Xcode project as a "versioned group"xcassets
directory.Because of these special cases, the previous naive copying caused issues when using a recursive glob for collecting resources. Notably, you usually had two options:
Resources/*
(non-recursive), which would copy the.lproj
directories into the resources directly. Because the internals of these directories were ignored, strings, XIBs, and other resources weren't compiled.Resources/**/*
(recursive), which would add all the files, but use the default CocoaPods behavior of flattening everything into a single level (like the internals ofxcdatamodeld
directories), thus breaking these resources.Changes
Localizable.strings
rather than justLocalizable
image.strings
withimage.png
. The specific case where this is needed is Base Internationalization, which is handled specially (see previous item).xcdatamodeld
orxcassets
directory. Xcode only wants a reference to the root and will handle the rest.Other Considerations
Resources/*
,lproj
directories are still added directly to the project if none of their children are matched in the glob. In general, everyone should move to the more correctResources/**/*
glob, which now works correctly.Resources/Nested/Image.png
will become justImage.png
in the resulting bundle. This wasn't previously a problem because recursive globs didn't work and weren't used. This is consistent with how source and header files are handled, and so I think is a separate issue. A proper fix here might be to add something likeheader_mappings_dir
for resources.