Skip to content

Commit

Permalink
Add support for parsing XCLocalSwiftPackageReference objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Jun 10, 2023
1 parent 2fe1a20 commit 94b1e77
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

##### Enhancements

* Add support for parsing XCLocalSwiftPackageReference objects.
[Dimitris Koutsogiorgas](https:/dnkoutso)
[#911](https:/CocoaPods/Xcodeproj/pull/911)

* Add Xcode 15.0 object version support.
[Dimitris Koutsogiorgas](https:/dnkoutso)
[#910](https:/CocoaPods/Xcodeproj/pull/910)
Expand Down
1 change: 1 addition & 0 deletions lib/xcodeproj/project/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ def inspect

# Now load the concrete subclasses.
require 'xcodeproj/project/object/swift_package_remote_reference'
require 'xcodeproj/project/object/swift_package_local_reference'
require 'xcodeproj/project/object/swift_package_product_dependency'
require 'xcodeproj/project/object/build_configuration'
require 'xcodeproj/project/object/build_file'
Expand Down
4 changes: 2 additions & 2 deletions lib/xcodeproj/project/object/root_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class PBXProject < AbstractObject
#
attribute :project_root, String, ''

# @return [Array<XCRemoteSwiftPackageReference>] the list of Swift package references.
# @return [Array<XCRemoteSwiftPackageReference, XCLocalSwiftPackageReference>] the list of Swift package references.
#
has_many :package_references, XCRemoteSwiftPackageReference
has_many :package_references, [XCRemoteSwiftPackageReference, XCLocalSwiftPackageReference]

# @return [Array<ObjectDictionary>] any reference to other projects.
#
Expand Down
29 changes: 29 additions & 0 deletions lib/xcodeproj/project/object/swift_package_local_reference.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Xcodeproj
class Project
module Object
# This class represents a local Swift package reference.
#
class XCLocalSwiftPackageReference < AbstractObject
# @!group Attributes

# @return [String] the repository url this Swift package was installed from.
#
attribute :path, String

# @!group AbstractObject Hooks
#--------------------------------------#

def ascii_plist_annotation
" #{isa} \"#{File.basename(display_name)}\" "
end

# @return [String] the path of the local Swift package reference.
#
def display_name
return path if path
super
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module Object
class XCSwiftPackageProductDependency < AbstractObject
# @!group Attributes

# @return [XCRemoteSwiftPackageReference] the Swift package reference.
# @return [XCRemoteSwiftPackageReference, XCLocalSwiftPackageReference] the Swift package reference.
#
has_one :package, XCRemoteSwiftPackageReference
has_one :package, [XCRemoteSwiftPackageReference, XCLocalSwiftPackageReference]

# @return [String] the product name of this Swift package.
#
Expand All @@ -17,7 +17,7 @@ class XCSwiftPackageProductDependency < AbstractObject
# @!group AbstractObject Hooks
#--------------------------------------#

# @return [String] the name of the Swift package.
# @return [String] the name of the Swift package product dependency.
#
def display_name
return product_name if product_name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Xcodeproj
class Project
module Object
# This class represents a Swift package reference.
# This class represents a remote Swift package reference.
#
class XCRemoteSwiftPackageReference < AbstractObject
# @!group Attributes
Expand All @@ -21,7 +21,7 @@ def ascii_plist_annotation
" #{isa} \"#{File.basename(display_name)}\" "
end

# @return [String] the name of the Swift package repository.
# @return [String] the name of the remote Swift package reference.
#
def display_name
return repositoryURL if repositoryURL
Expand Down
23 changes: 23 additions & 0 deletions spec/project/object/swift_package_local_reference_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require File.expand_path('../../../spec_helper', __FILE__)

module ProjectSpecs
describe Xcodeproj::Project::Object::XCLocalSwiftPackageReference do
before do
@proxy = @project.new(XCLocalSwiftPackageReference)
end

it 'returns default display_name if path is not set' do
@proxy.display_name.should == 'LocalSwiftPackageReference'
end

it 'returns path for display_name if path is set' do
@proxy.path = '../path'
@proxy.display_name.should == '../path'
end

it 'returns the ascii plist annotation with the last component of path' do
@proxy.path = '../path'
@proxy.ascii_plist_annotation.should == ' XCLocalSwiftPackageReference "path" '
end
end
end

0 comments on commit 94b1e77

Please sign in to comment.