Fix resources with PBXVariantGroups outside of a resource bundle

parent cae98c53
......@@ -12,6 +12,11 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Bug Fixes
* Fix build phase resource references to point at PBXVariantGroups where relevant.
[Wes Campaigne](https://github.com/Westacular)
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#6373](https://github.com/CocoaPods/CocoaPods/issues/6373)
* Add `--skip-import-validation` to skip linking a pod during lint.
[Samuel Giddins](https://github.com/segiddins)
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
......
......@@ -65,6 +65,31 @@ module Pod
settings
end
# Filters the given resource file references discarding empty paths which are
# added by their parent directory. This will also include references to the parent [PBXVariantGroup]
# for all resources underneath it.
#
# @param Array[<Pathname>] resource_file_references
# The array of all resource file references to filter.
# @return [Array<Pathname>] The filtered resource file references.
#
def filter_resource_file_references(resource_file_references)
resource_file_references.map do |resource_file_reference|
ref = project.reference_for_path(resource_file_reference)
# Some nested files are not directly present in the Xcode project, such as the contents
# of an .xcdatamodeld directory. These files are implicitly included by including their
# parent directory.
next if ref.nil?
# For variant groups, the variant group itself is added, not its members.
next ref.parent if ref.parent.is_a?(Xcodeproj::Project::Object::PBXVariantGroup)
ref
end
end
#-----------------------------------------------------------------------#
SOURCE_FILE_EXTENSIONS = Sandbox::FileAccessor::SOURCE_FILE_EXTENSIONS
......@@ -111,13 +136,7 @@ module Pod
next unless target.requires_frameworks?
resource_refs = file_accessor.resources.flatten.map do |res|
project.reference_for_path(res)
end
# Some nested files are not directly present in the Xcode project, such as the contents
# of an .xcdatamodeld directory. These files will return nil file references.
resource_refs.compact!
resource_refs = filter_resource_file_references(file_accessor.resources.flatten).compact
native_target.add_resources(resource_refs)
end
......@@ -138,19 +157,7 @@ module Pod
def add_resources_bundle_targets
target.file_accessors.each do |file_accessor|
file_accessor.resource_bundles.each do |bundle_name, paths|
file_references = paths.map do |path|
ref = project.reference_for_path(path)
# Some nested files are not directly present in the Xcode project, such as the contents
# of an .xcdatamodeld directory. These files are implicitly included by including their
# parent directory.
next if ref.nil?
# For variant groups, the variant group itself is added, not its members.
next ref.parent if ref.parent.is_a?(Xcodeproj::Project::Object::PBXVariantGroup)
ref
end
file_references = filter_resource_file_references(paths)
file_references = file_references.uniq.compact
label = target.resources_bundle_target_label(bundle_name)
......
......@@ -545,6 +545,50 @@ module Pod
end
end
describe 'concerning resources' do
before do
config.sandbox.prepare
@project = Project.new(config.sandbox.project_path)
config.sandbox.project = @project
@spec = fixture_spec('banana-lib/BananaLib.podspec')
@spec.resources = ['Resources/**/*']
@spec.resource_bundle = nil
@project.add_pod_group('BananaLib', fixture('banana-lib'))
@pod_target = fixture_pod_target(@spec)
@pod_target.stubs(:requires_frameworks? => true)
@pod_target.user_build_configurations = { 'Debug' => :debug, 'Release' => :release }
target_installer = PodTargetInstaller.new(config.sandbox, @pod_target)
# Use a file references installer to add the files so that the correct ones are added.
file_ref_installer = Installer::Xcode::PodsProjectGenerator::FileReferencesInstaller.new(config.sandbox, [@pod_target], @project)
file_ref_installer.install!
target_installer.install!
end
it 'adds variant groups directly to resources' do
native_target = @project.targets.first
# The variant group item should be present.
group_build_file = native_target.resources_build_phase.files.find do |bf|
bf.file_ref.path == 'Resources' && bf.file_ref.name == 'Main.storyboard'
end
group_build_file.should.be.not.nil
group_build_file.file_ref.is_a?(Xcodeproj::Project::Object::PBXVariantGroup).should.be.true
# An item within the variant group should not be present.
strings_build_file = native_target.resources_build_phase.files.find do |bf|
bf.file_ref.path == 'Resources/en.lproj/Main.strings'
end
strings_build_file.should.be.nil
end
end
describe 'concerning resource bundles' do
before do
config.sandbox.prepare
......@@ -572,7 +616,7 @@ module Pod
@bundle_target.should.be.not.nil
end
it 'adds variant groups directly to resources' do
it 'adds variant groups directly to resource bundle' do
# The variant group item should be present.
group_build_file = @bundle_target.resources_build_phase.files.find do |bf|
bf.file_ref.path == 'Resources' && bf.file_ref.name == 'Main.storyboard'
......@@ -587,7 +631,7 @@ module Pod
strings_build_file.should.be.nil
end
it 'adds Core Data models directly to resources' do
it 'adds Core Data models directly to resource bundle' do
# The model directory item should be present.
dir_build_file = @bundle_target.resources_build_phase.files.find { |bf| bf.file_ref.path == 'Resources/Sample.xcdatamodeld' }
dir_build_file.should.be.not.nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment