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

Do not raise an exception on a Swift Package dependency #881

Merged
merged 2 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
[lemonspike](https://github.com/LemonSpike)
[#709](https://github.com/CocoaPods/Xcodeproj/issues/709)

* Do not raise an exception on a Swift Package dependency.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: please add two empty spaces at the end of this line for markdown formattin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

[Vincent Isambart](https://github.com/vincentisambart)
[#743](https://github.com/CocoaPods/Xcodeproj/issues/743)

##### Bug Fixes

* Fix undefined method 'downcase' for `nil`
Expand Down
15 changes: 9 additions & 6 deletions lib/xcodeproj/project/object/target_dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ class PBXTargetDependency < AbstractObject
#
attribute :platform_filters, Array

# @return [String] the product reference for this target dependency.
# @return [XCSwiftPackageProductDependency] the Swift Package product
# for this target dependency.
#
attribute :product_ref, String
has_one :product_ref, XCSwiftPackageProductDependency
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to change attribute to has_one to easily get the product name in the display_name method.


public

Expand All @@ -49,20 +50,22 @@ def display_name
return name if name
return target.name if target
return target_proxy.remote_info if target_proxy
return product_ref.product_name if product_ref
end

def ascii_plist_annotation
" #{isa} "
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
# @return [String] the uuid of the target if the dependency is a native
# target, the uuid of the target in the sub-project if the
# dependency is a target proxy, nil if the dependency is a Swift
# Package.
#
def native_target_uuid
return target.uuid if target
return target_proxy.remote_global_id_string if target_proxy
return nil if product_ref
raise "Expected target or target_proxy, from which to fetch a uuid for target '#{display_name}'." \
"Find and clear the PBXTargetDependency entry with uuid '#{@uuid}' in your .xcodeproj."
end
Expand Down
18 changes: 17 additions & 1 deletion spec/project/object/target_dependency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ module ProjectSpecs
@target_dependency.target_proxy = proxy
@target_dependency.display_name.should == 'Pods'
end

it 'returns the product name if needed' do
product_ref = @project.new(XCSwiftPackageProductDependency)
product_ref.product_name = 'SwiftPackage'
@target_dependency.product_ref = product_ref
@target_dependency.display_name.should == 'SwiftPackage'
end
end

#----------------------------------------#
Expand All @@ -111,10 +118,19 @@ module ProjectSpecs
@target_dependency.native_target_uuid.should == @target_dependency.target.uuid
end

it "raises if target and target_proxy aren't set" do
it 'returns nil for a Swift Package product' do
product_ref = @project.new(XCSwiftPackageProductDependency)
product_ref.product_name = 'SwiftPackage'

@target_dependency.product_ref = product_ref
@target_dependency.native_target_uuid.nil?.should == true
end

it "raises if target, target_proxy, and product_ref aren't set" do
@target_dependency.name = 'TargetName'
@target_dependency.target.nil?.should == true
@target_dependency.target_proxy.nil?.should == true
@target_dependency.product_ref.nil?.should == true
should.raise do
@target_dependency.native_target_uuid
end.message.should.include "Expected target or target_proxy, from which to fetch a uuid for target 'TargetName'." \
Expand Down