Skip to content

Commit

Permalink
Merge pull request #396 from benasher44/basher_embedded_remote_target
Browse files Browse the repository at this point in the history
Support for identifying hosts of embedded targets from sub-projects
  • Loading branch information
segiddins authored Aug 3, 2016
2 parents 6f5a359 + 346a751 commit 2f8cc93
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

##### Enhancements

* None.
* Add support for identify the host of an embedded target,
when the embedded target belongs to a sub-project
[Ben Asher](https://github.com/benasher44)
[#396](https://github.com/CocoaPods/Xcodeproj/pull/396)

##### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion lib/xcodeproj/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def embedded_targets_in_native_target(native_target)
def host_targets_for_embedded_target(embedded_target)
native_targets.select do |native_target|
((embedded_target.uuid != native_target.uuid) &&
(native_target.dependencies.map(&:target).map(&:uuid).include? embedded_target.uuid))
(native_target.dependencies.map(&:native_target_uuid).include? embedded_target.uuid))
end
end

Expand Down
11 changes: 11 additions & 0 deletions lib/xcodeproj/project/object/target_dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ def display_name
return target_proxy.remote_info if target_proxy
end

# @return [String] uuid of the target, if the dependency
# is a native target, otherwise the uuid of the
# target in the sub-project if the dependency is
# a target proxy
#
def native_target_uuid
return target.uuid if target
return target_proxy.remote_global_id_string if target_proxy
raise 'Expected target or target_proxy, from which to fetch a uuid'
end

# @note This override is necessary because Xcode allows for circular
# target dependencies.
#
Expand Down
31 changes: 31 additions & 0 deletions spec/project/object/target_dependency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,36 @@ module ProjectSpecs
end

#----------------------------------------#

describe '#native_target_uuid' do
it "returns the target_proxy's remote_global_uuid_string" do
target = @project.new_target(:static, 'Pods', :ios)

proxy = @project.new(PBXContainerItemProxy)
proxy.container_portal = @project.root_object.uuid
proxy.remote_info = 'Pods'
proxy.proxy_type = '1'
proxy.remote_global_id_string = target.uuid

@target_dependency.target_proxy = proxy
@target_dependency.target_proxy.remote_global_id_string.nil?.should == false
@target_dependency.native_target_uuid.should == @target_dependency.target_proxy.remote_global_id_string
end

it "returns the target's uuid" do
target = @project.new_target(:static, 'Pods', :ios)
@target_dependency.target = target
@target_dependency.target.uuid.nil?.should == false
@target_dependency.native_target_uuid.should == @target_dependency.target.uuid
end

it "raises if target and target_proxy aren't set" do
@target_dependency.target.nil?.should == true
@target_dependency.target_proxy.nil?.should == true
should.raise do
@target_dependency.native_target_uuid
end.message.should.match /Expected target or target_proxy, from which to fetch a uuid/
end
end
end
end
21 changes: 21 additions & 0 deletions spec/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,27 @@ def target_for_target_name(name)
end
end

describe 'Remote embedded target relationships' do
before do
dir = Pathname(fixture_path('Sample Project'))
project_path = dir + 'ContainsSubproject/ContainsSubproject.xcodeproj'
subproject_path = dir + 'ReferencedProject/ReferencedProject.xcodeproj'
@project = Xcodeproj::Project.open(project_path)
@subproject = Xcodeproj::Project.open(subproject_path)
end

def subproject_target_for_target_name(name)
@subproject.native_targets.find do |target|
target.name == name
end
end

it 'identifies host of target from a sub-project' do
subproject_target = subproject_target_for_target_name('ReferencedProject')
@project.host_targets_for_embedded_target(subproject_target).map(&:name).should == ['ContainsSubproject']
end
end

#-------------------------------------------------------------------------#
end
end

0 comments on commit 2f8cc93

Please sign in to comment.