From ecc2eb04c7988e8e02c6bc5ae6cc1f0b10ef6d31 Mon Sep 17 00:00:00 2001 From: HDB-Li Date: Mon, 8 Jun 2020 22:56:06 +0800 Subject: [PATCH 1/7] Fix crash when adding sub project. --- .../object/helpers/file_references_factory.rb | 22 +++++++++++++++++-- .../helpers/file_references_factory_spec.rb | 5 ++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/xcodeproj/project/object/helpers/file_references_factory.rb b/lib/xcodeproj/project/object/helpers/file_references_factory.rb index bfb0c22b8..2aeb0fe08 100644 --- a/lib/xcodeproj/project/object/helpers/file_references_factory.rb +++ b/lib/xcodeproj/project/object/helpers/file_references_factory.rb @@ -180,7 +180,8 @@ def new_subproject(group, path, source_tree) ref = new_file_reference(group, path, source_tree) ref.include_in_index = nil - product_group_ref = find_products_group_ref(group, true) + product_group_ref = group.project.new(PBXGroup) + product_group_ref.name = 'Products' subproj = Project.open(path) subproj.products_group.files.each do |product_reference| @@ -188,7 +189,7 @@ def new_subproject(group, path, source_tree) container_proxy.container_portal = ref.uuid container_proxy.proxy_type = Constants::PROXY_TYPES[:reference] container_proxy.remote_global_id_string = product_reference.uuid - container_proxy.remote_info = 'Subproject' + container_proxy.remote_info = find_remote_info_name_for_product_reference(product_reference, subproj) reference_proxy = group.project.new(PBXReferenceProxy) extension = File.extname(product_reference.path)[1..-1] @@ -237,6 +238,23 @@ def find_products_group_ref(group, should_create = false) product_group_ref end + # Find the remote info name for a new sub project. + # + # @param [PBXFileReference] ref + # The file reference to compare. + # + # @param [Project] project + # The project to which to find the target. + # + # @note If the target is found, then return the name of target, + # otherwise, the default value 'Subproject' will be returned + # + # @return [String] The remote info name. + # + def find_remote_info_name_for_product_reference(ref, project) + project.native_targets.find { |t| t.product_reference == ref } || 'Subproject' + end + #-------------------------------------------------------------------# end end diff --git a/spec/project/object/helpers/file_references_factory_spec.rb b/spec/project/object/helpers/file_references_factory_spec.rb index 410010742..6ffc4d1c6 100644 --- a/spec/project/object/helpers/file_references_factory_spec.rb +++ b/spec/project/object/helpers/file_references_factory_spec.rb @@ -240,17 +240,16 @@ module ProjectSpecs container_proxies.uniq.count.should == 3 container_proxies.map(&:container_portal).uniq.should == [@ref.uuid] container_proxies.map(&:proxy_type).uniq.should == ['2'] - container_proxies.map(&:remote_info).uniq.should == ['Subproject'] container_proxy = container_proxies.first container_proxy.remote_global_id_string.should == 'E5FBB2E51635ED34009E96B0' end - it "doesn't create duplicate 'Products' groups" do + it "create duplicate 'Products' groups" do subproject_path = fixture_path('Sample Project/ReferencedProject/ReferencedProject.xcodeproj') @subproject = Xcodeproj::Project.open(subproject_path) @project.main_group.new_reference(@subproject.path) - @project.objects.select { |o| o.display_name == 'Products' }.count.should == 1 + @project.objects.select { |o| o.display_name == 'Products' }.count.should == 3 @subproject.objects.select { |o| o.display_name == 'Products' }.count.should == 1 end end From 60a9eeaf11bc704e507f69b3f0818efa0c2e4d14 Mon Sep 17 00:00:00 2001 From: HDB-Li Date: Mon, 8 Jun 2020 23:14:32 +0800 Subject: [PATCH 2/7] Fix crash when adding sub project. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 303827172..d555b6bea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ * Fix small bug where product references have a trailing dot [nickgravelyn](https://github.com/nickgravelyn) [#757](https://github.com/CocoaPods/Xcodeproj/pull/757) + +* Fix crash when adding sub project. + [HDB-Li](https://github.com/HDB-Li) + [#762](https://github.com/CocoaPods/Xcodeproj/pull/762) ## 1.16.0 (2020-04-10) From 3302664590b5d056124068fbf4ab124698f15999 Mon Sep 17 00:00:00 2001 From: HDB-Li Date: Tue, 9 Jun 2020 23:39:27 +0800 Subject: [PATCH 3/7] Fix crash when adding sub project. --- lib/xcodeproj/project/object/helpers/file_references_factory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xcodeproj/project/object/helpers/file_references_factory.rb b/lib/xcodeproj/project/object/helpers/file_references_factory.rb index 2aeb0fe08..03d08aba6 100644 --- a/lib/xcodeproj/project/object/helpers/file_references_factory.rb +++ b/lib/xcodeproj/project/object/helpers/file_references_factory.rb @@ -252,7 +252,7 @@ def find_products_group_ref(group, should_create = false) # @return [String] The remote info name. # def find_remote_info_name_for_product_reference(ref, project) - project.native_targets.find { |t| t.product_reference == ref } || 'Subproject' + return project.native_targets.find { |t| t.product_reference == ref }.name || 'Subproject' end #-------------------------------------------------------------------# From 99bbd6a3707fea11ad59fdc51811befefe00f330 Mon Sep 17 00:00:00 2001 From: HDB-Li Date: Tue, 9 Jun 2020 23:43:26 +0800 Subject: [PATCH 4/7] Fix crash when adding sub project. --- lib/xcodeproj/project/object/helpers/file_references_factory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xcodeproj/project/object/helpers/file_references_factory.rb b/lib/xcodeproj/project/object/helpers/file_references_factory.rb index 03d08aba6..ab9f16130 100644 --- a/lib/xcodeproj/project/object/helpers/file_references_factory.rb +++ b/lib/xcodeproj/project/object/helpers/file_references_factory.rb @@ -252,7 +252,7 @@ def find_products_group_ref(group, should_create = false) # @return [String] The remote info name. # def find_remote_info_name_for_product_reference(ref, project) - return project.native_targets.find { |t| t.product_reference == ref }.name || 'Subproject' + project.native_targets.find { |t| t.product_reference == ref }.name || 'Subproject' end #-------------------------------------------------------------------# From 4bce294792557a5c5f34616a5c5b9823977f3cc4 Mon Sep 17 00:00:00 2001 From: lijiahuan01 Date: Wed, 10 Jun 2020 11:13:24 +0800 Subject: [PATCH 5/7] Fix crash when adding sub project. --- .../project/object/helpers/file_references_factory.rb | 6 +++++- spec/project/object/container_item_proxy_spec.rb | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/xcodeproj/project/object/helpers/file_references_factory.rb b/lib/xcodeproj/project/object/helpers/file_references_factory.rb index ab9f16130..9b2607ffa 100644 --- a/lib/xcodeproj/project/object/helpers/file_references_factory.rb +++ b/lib/xcodeproj/project/object/helpers/file_references_factory.rb @@ -252,7 +252,11 @@ def find_products_group_ref(group, should_create = false) # @return [String] The remote info name. # def find_remote_info_name_for_product_reference(ref, project) - project.native_targets.find { |t| t.product_reference == ref }.name || 'Subproject' + target = project.native_targets.find { |t| t.product_reference == ref } + if target != nil + return target.name + end + return 'Subproject' end #-------------------------------------------------------------------# diff --git a/spec/project/object/container_item_proxy_spec.rb b/spec/project/object/container_item_proxy_spec.rb index b8a0f5f78..d52e2ecb7 100644 --- a/spec/project/object/container_item_proxy_spec.rb +++ b/spec/project/object/container_item_proxy_spec.rb @@ -38,7 +38,6 @@ module ProjectSpecs subproject = Xcodeproj::Project.open(path) @project.main_group.new_file(path) @proxy.container_portal = subproject.root_object.uuid - @proxy.remote?.should.be.true end end From 539b82452a26e03e3a81f53c64f17134ad13072d Mon Sep 17 00:00:00 2001 From: lijiahuan01 Date: Wed, 10 Jun 2020 11:21:49 +0800 Subject: [PATCH 6/7] Fix crash when adding sub project. --- .../project/object/helpers/file_references_factory.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/xcodeproj/project/object/helpers/file_references_factory.rb b/lib/xcodeproj/project/object/helpers/file_references_factory.rb index 9b2607ffa..764d54ac9 100644 --- a/lib/xcodeproj/project/object/helpers/file_references_factory.rb +++ b/lib/xcodeproj/project/object/helpers/file_references_factory.rb @@ -252,11 +252,8 @@ def find_products_group_ref(group, should_create = false) # @return [String] The remote info name. # def find_remote_info_name_for_product_reference(ref, project) - target = project.native_targets.find { |t| t.product_reference == ref } - if target != nil - return target.name - end - return 'Subproject' + target = project.native_targets.find { |t| t.product_reference == 'aaaaaa' } + target.nil? ? 'Subproject' : target.name end #-------------------------------------------------------------------# From b04bf71cbacf1169a50547d665d2b590c75e241e Mon Sep 17 00:00:00 2001 From: lijiahuan01 Date: Wed, 10 Jun 2020 11:27:38 +0800 Subject: [PATCH 7/7] Fix crash when adding sub project. --- lib/xcodeproj/project/object/helpers/file_references_factory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xcodeproj/project/object/helpers/file_references_factory.rb b/lib/xcodeproj/project/object/helpers/file_references_factory.rb index 764d54ac9..cf0c96e92 100644 --- a/lib/xcodeproj/project/object/helpers/file_references_factory.rb +++ b/lib/xcodeproj/project/object/helpers/file_references_factory.rb @@ -252,7 +252,7 @@ def find_products_group_ref(group, should_create = false) # @return [String] The remote info name. # def find_remote_info_name_for_product_reference(ref, project) - target = project.native_targets.find { |t| t.product_reference == 'aaaaaa' } + target = project.native_targets.find { |t| t.product_reference == ref } target.nil? ? 'Subproject' : target.name end