Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for identifying hosts of embedded targets from sub-projects #396

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe raise otherwise to ensure this doesn't return nil?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually fixed in the line below, but it didn't close this comment since I didn't change these lines :)

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