From 42df5c0932e11228f9ad9e901b7cae6205d80fe4 Mon Sep 17 00:00:00 2001 From: Ben Asher Date: Fri, 10 Jun 2016 17:28:49 -0700 Subject: [PATCH 1/2] Expand extension methods to all embeded targets --- lib/xcodeproj/project.rb | 38 +++++++++++++++++++------------------- spec/project_spec.rb | 24 ++++++------------------ 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/lib/xcodeproj/project.rb b/lib/xcodeproj/project.rb index 5283ea82b..9f2e9dcaf 100644 --- a/lib/xcodeproj/project.rb +++ b/lib/xcodeproj/project.rb @@ -526,37 +526,37 @@ def native_targets root_object.targets.grep(PBXNativeTarget) end - # Checks the native target for any targets in the project that are - # extensions of that target + # Checks the native target for any targets in the project + # that are dependent on the native target and would be + # embedded in it at build time # - # @param [PBXNativeTarget] native target to check for extensions + # @param [PBXNativeTarget] native target to check for + # embedded targets # # - # @return [Array] A list of all targets that are - # extensions of the passed in target. + # @return [Array] A list of all targets that + # are embedded in the passed in target # - def extensions_for_native_target(native_target) - return [] if native_target.extension_target_type? + def embedded_targets_in_native_target(native_target) native_targets.select do |target| - next unless target.extension_target_type? - host_targets_for_extension_target(target).map(&:uuid).include? native_target.uuid + host_targets_for_embedded_target(target).map(&:uuid).include? native_target.uuid end end - # Returns the native targets, in which the extension target are embedded. - # This works by traversing the targets to find those where the extension - # target is a dependency. + # Returns the native targets, in which the embedded target is + # embedded. This works by traversing the targets to find those + # where the target is a dependency. # - # @param [PBXNativeTarget] native target where target.extension_target_type? - # is true + # @param [PBXNativeTarget] native target that might be embedded + # in another target # - # @return [Array] the native targets that host the extension + # @return [Array] the native targets that host the + # embedded target # - def host_targets_for_extension_target(extension_target) - raise ArgumentError, "#{extension_target} is not an extension" unless extension_target.extension_target_type? + def host_targets_for_embedded_target(embedded_target) native_targets.select do |native_target| - ((extension_target.uuid != native_target.uuid) && - (native_target.dependencies.map(&:target).map(&:uuid).include? extension_target.uuid)) + ((embedded_target.uuid != native_target.uuid) && + (native_target.dependencies.map(&:target).map(&:uuid).include? embedded_target.uuid)) end end diff --git a/spec/project_spec.rb b/spec/project_spec.rb index c7ead2d9a..7fe2be7d9 100644 --- a/spec/project_spec.rb +++ b/spec/project_spec.rb @@ -608,7 +608,7 @@ def touch_project(name) #-------------------------------------------------------------------------# - describe 'Extension target relationships' do + describe 'Embedded target relationships' do before do dir = Pathname(fixture_path('Sample Project')) path = dir + 'Extensions/Extensions.xcodeproj' @@ -623,33 +623,21 @@ def target_for_target_name(name) it 'identifies host of watch extension' do watch_extension = target_for_target_name('Extensions WatchKit 1 Extension') - @project.host_targets_for_extension_target(watch_extension).map(&:name).should == ['Extensions'] + @project.host_targets_for_embedded_target(watch_extension).map(&:name).should == ['Extensions'] end it 'identifies host of extension' do today_extension = target_for_target_name('Today') - @project.host_targets_for_extension_target(today_extension).map(&:name).should == ['Extensions'] + @project.host_targets_for_embedded_target(today_extension).map(&:name).should == ['Extensions'] end - it 'rejects identifying the host of targets that are not extensions' do - watch_app = target_for_target_name('Extensions WatchKit 1 App') - should.raise ArgumentError do - @project.host_targets_for_extension_target(watch_app) - end.message.should.equal "#{watch_app} is not an extension" - end - - it 'identifies list of extensions given a host target' do + it 'identifies list of embedded targets given a host target' do main_app_target = target_for_target_name('Extensions') - extension_bundle_ids = @project.extensions_for_native_target(main_app_target).map(&:name) + extension_bundle_ids = @project.embedded_targets_in_native_target(main_app_target).map(&:name) extension_bundle_ids.should == ['Extensions WatchKit 1 Extension', + 'WatchOS 2 App', 'Today'] end - - it 'returns an empty list extensions given an extension target' do - watch_extension = target_for_target_name('Extensions WatchKit 1 Extension') - extension_bundle_ids = @project.extensions_for_native_target(watch_extension).map(&:name) - extension_bundle_ids.should == [] - end end #-------------------------------------------------------------------------# From 2a35c5e9aefdc378881acd382eff4e1bbafe34bd Mon Sep 17 00:00:00 2001 From: Ben Asher Date: Fri, 10 Jun 2016 18:25:04 -0700 Subject: [PATCH 2/2] changelog entry --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ce13ba11..447a53dd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ ##### Enhancements +* Expand `Project` helpers for finding a target's extension targets + and their hosts to include all embedded targets + [Ben Asher](https://github.com/benasher44) + [#385](https://github.com/CocoaPods/Xcodeproj/pull/385) + * Add helpers to `Project` for finding an extension target's host targets and a host target's extension targets. [Ben Asher](https://github.com/benasher44)