Commit 7b23498e authored by Tim Bodeit's avatar Tim Bodeit

[Project] Make separate variant groups for different directory levels

It is possible that a pod lib creator includes multiple assets with the same
name, but different file extensions.
Instead of just putting localized files by name, they are now also grouped by
the path of the directory their .lproj folder is in.

For example the library Foo could include a localized Foo.storyboard as well as
a localized Foo.png
Now two separate variant groups would be created for Foo.storyboard and Foo.png
as long as the two files are in different .lproj bundles in different folders.
parent 15678e3a
......@@ -20,6 +20,7 @@ module Pod
super(path, skip_initialization, object_version)
@support_files_group = new_group('Targets Support Files')
@refs_by_absolute_path = {}
@variant_groups_by_path_and_name = {}
@pods = new_group('Pods')
@development_pods = new_group('Development Pods')
self.symroot = LEGACY_BUILD_ROOT
......@@ -265,6 +266,11 @@ module Pod
#
attr_reader :refs_by_absolute_path
# @return [Hash{[Pathname, String] => PBXVariantGroup}] The variant groups
# grouped by absolute path of parent dir and name.
#
attr_reader :variant_groups_by_path_and_name
# Returns the group for an absolute file path in another group.
# Creates subgroups to reflect the file system structure if
# reflect_file_system_structure is set to true.
......@@ -308,7 +314,9 @@ module Pod
if relative_dir.basename.to_s =~ lproj_regex
filename = absolute_pathname.basename.sub_ext('').to_s
lproj_parent_dir = absolute_pathname.dirname.dirname
group = group[filename] || group.new_variant_group(filename, lproj_parent_dir)
group = @variant_groups_by_path_and_name[[lproj_parent_dir, filename]] ||
group.new_variant_group(filename, lproj_parent_dir)
@variant_groups_by_path_and_name[[lproj_parent_dir, filename]] = group
end
group
......
......@@ -224,13 +224,15 @@ module Pod
describe '#group_for_path_in_group' do
before do
@project.add_pod_group('BananaLib', config.sandbox.pod_dir('BananaLib'), false)
@file = config.sandbox.pod_dir('BananaLib') + 'file.m'
subdir = config.sandbox.pod_dir('BananaLib') + 'Dir/SubDir/'
poddir = config.sandbox.pod_dir('BananaLib')
subdir = poddir + 'Dir/SubDir/'
@file = poddir + 'file.m'
@nested_file = subdir + 'nested_file.h'
@nested_file2 = subdir + 'nested_file.m'
@localized_base_foo = subdir + 'Base.lproj/Foo.storyboard'
@localized_de_foo = subdir + 'de.lproj/Foo.strings'
@localized_de_bar = subdir + 'de.lproj/Bar.strings'
@localized_different_foo = poddir + 'Base.lproj/Foo.jpg'
@group = @project.group_for_spec('BananaLib')
end
......@@ -272,7 +274,7 @@ module Pod
group.real_path.should == config.sandbox.pod_dir('BananaLib') + 'Dir/SubDir'
end
it "doesn't duplicate variant groups for same name" do
it "doesn't duplicate variant groups for same name and directory" do
group_1 = @project.group_for_path_in_group(@localized_base_foo, @group, false)
group_2 = @project.group_for_path_in_group(@localized_de_foo, @group, false)
group_1.uuid.should == group_2.uuid
......@@ -286,6 +288,13 @@ module Pod
@group.children.count.should == 2
end
it 'makes separate variant groups for different directory levels' do
group_1 = @project.group_for_path_in_group(@localized_base_foo, @group, false)
group_2 = @project.group_for_path_in_group(@localized_different_foo, @group, false)
group_1.uuid.should != group_2.uuid
@group.children.count.should == 2
end
it 'raises if the given path is not absolute' do
should.raise ArgumentError do
@project.add_file_reference('relative/path/to/file.m', @group, true)
......
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