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 Xcode 11 attributes and objects. #687

Merged
merged 1 commit into from
Jun 11, 2019
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

##### Enhancements

* None.
* Support for Xcode 11 attributes and objects.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#687](https://github.com/CocoaPods/Xcodeproj/pull/687)

##### Bug Fixes

Expand Down
7 changes: 4 additions & 3 deletions lib/xcodeproj/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ module Constants

# @return [String] The last known object version to Xcodeproj.
#
LAST_KNOWN_OBJECT_VERSION = 51
LAST_KNOWN_OBJECT_VERSION = 52

# @return [String] The last known object version to Xcodeproj.
#
LAST_UPGRADE_CHECK = '1020'
LAST_UPGRADE_CHECK = '1100'

# @return [String] The last known object version to Xcodeproj.
#
LAST_SWIFT_UPGRADE_CHECK = '1020'
LAST_SWIFT_UPGRADE_CHECK = '1100'

# @return [String] The version of `.xcscheme` files supported by Xcodeproj
#
Expand Down Expand Up @@ -126,6 +126,7 @@ module Constants
# @return [Hash] The compatibility version string for different object versions.
#
COMPATIBILITY_VERSION_BY_OBJECT_VERSION = {
52 => 'Xcode 11.0',
51 => 'Xcode 10.0',
50 => 'Xcode 9.3',
48 => 'Xcode 8.0',
Expand Down
2 changes: 2 additions & 0 deletions lib/xcodeproj/project/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ def inspect
end

# Now load the concrete subclasses.
require 'xcodeproj/project/object/swift_package_remote_reference'
require 'xcodeproj/project/object/swift_package_product_dependency'
require 'xcodeproj/project/object/build_configuration'
require 'xcodeproj/project/object/build_file'
require 'xcodeproj/project/object/build_phase'
Expand Down
10 changes: 9 additions & 1 deletion lib/xcodeproj/project/object/build_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PBXBuildFile < AbstractObject
#
attribute :settings, Hash

# @return [PBXFileReference] the file that to build.
# @return [PBXFileReference] the file to build.
#
# @todo I think that is possible to add any kind of group (for
# example folders linked to a path).
Expand All @@ -31,6 +31,14 @@ class PBXBuildFile < AbstractObject
PBXReferenceProxy,
]

# @return [XCSwiftPackageProductDependency] the Swift Package file to build.
#
has_one :product_ref, XCSwiftPackageProductDependency

# @return [String] the platform filter for this build file.
#
attribute :platform_filter, String

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

public
Expand Down
5 changes: 5 additions & 0 deletions lib/xcodeproj/project/object/build_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class PBXBuildRule < AbstractObject
#
attribute :is_editable, String, '1'

# @return [ObjectList<PBXFileReference>] the file references for the
# input files files.
#
attribute :input_files, Array

# @return [ObjectList<PBXFileReference>] the file references for the
# output files.
#
Expand Down
27 changes: 24 additions & 3 deletions lib/xcodeproj/project/object/native_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def new_shell_script_build_phase(name = nil)
# Adds a file reference for one or more system framework to the project
# if needed and adds them to the Frameworks build phases.
#
# @param [Array<String>, String] name
# @param [Array<String>, String] names
# The name or the list of the names of the framework.
#
# @note Xcode behaviour is following: if the target has the same SDK
Expand Down Expand Up @@ -359,7 +359,7 @@ def add_system_framework(names)
# Adds a file reference for one or more system dylib libraries to the project
# if needed and adds them to the Frameworks build phases.
#
# @param [Array<String>, String] name
# @param [Array<String>, String] names
# The name or the list of the names of the libraries.
#
# @return [void]
Expand All @@ -385,7 +385,7 @@ def add_system_library_extension(names, extension)
# Adds a file reference for one or more system tbd libraries to the project
# if needed and adds them to the Frameworks build phases.
#
# @param [Array<String>, String] name
# @param [Array<String>, String] names
# The name or the list of the names of the libraries.
#
# @return [void]
Expand Down Expand Up @@ -432,6 +432,11 @@ class PBXNativeTarget < AbstractTarget
#
has_one :product_reference, PBXFileReference

# @return [ObjectList<XCSwiftPackageProductDependency>] the Swift package products necessary to
# build this target.
#
has_many :package_product_dependencies, XCSwiftPackageProductDependency

# @return [String] the install path of the product.
#
attribute :product_install_path, String
Expand Down Expand Up @@ -622,6 +627,22 @@ def sort(_options = nil)
end
end
end

def to_hash_as(method = :to_hash)
hash_as = super
if !hash_as['packageProductDependencies'].nil? && hash_as['packageProductDependencies'].empty?
hash_as.delete('packageProductDependencies')
end
hash_as
end

def to_ascii_plist
plist = super
if !plist.value['packageProductDependencies'].nil? && plist.value['packageProductDependencies'].empty?
plist.value.delete('packageProductDependencies')
end
plist
Copy link
Member

Choose a reason for hiding this comment

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

is this covered by any tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is already covered by existing tests but I might add an explicit one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added explicit tests.

end
end

#-----------------------------------------------------------------------#
Expand Down
13 changes: 13 additions & 0 deletions lib/xcodeproj/project/object/root_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class PBXProject < AbstractObject
#
attribute :project_root, String, ''

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

# @return [Array<ObjectDictionary>] any reference to other projects.
#
has_many_references_by_keys :project_references,
Expand All @@ -76,9 +80,18 @@ def ascii_plist_annotation
' Project object '
end

def to_hash_as(method = :to_hash)
hash_as = super
if !hash_as['packageReferences'].nil? && hash_as['packageReferences'].empty?
Copy link
Contributor Author

@dnkoutso dnkoutso Jun 10, 2019

Choose a reason for hiding this comment

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

@segiddins these values are "optional" as in a default Xcode 11 project will not include them in its plist unless at least one SPM package is added. Is there a better way in Xcodeproj to handle this?

The way I have it here is passing all tests but felt its a bit ugly. Alternatively, we can update all tests to ensure packageReferences => [] is taken into consideration even though they are none in the actual .pbxproj.

hash_as.delete('packageReferences') if !hash_as['packageReferences'].nil? && hash_as['packageReferences'].empty?
end
hash_as
end

def to_ascii_plist
plist = super
plist.value.delete('projectReferences') if plist.value['projectReferences'].empty?
plist.value.delete('packageReferences') if !plist.value['packageReferences'].nil? && plist.value['packageReferences'].empty?
plist
end
end
Expand Down
19 changes: 19 additions & 0 deletions lib/xcodeproj/project/object/swift_package_product_dependency.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Xcodeproj
class Project
module Object
# This class represents a Swift package product dependency.
#
class XCSwiftPackageProductDependency < AbstractObject
# @!group Attributes

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

# @return [String] the product name of this Swift package.
#
attribute :product_name, String
end
end
end
end
19 changes: 19 additions & 0 deletions lib/xcodeproj/project/object/swift_package_remote_reference.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Xcodeproj
class Project
module Object
# This class represents a Swift package reference.
#
class XCRemoteSwiftPackageReference < AbstractObject
# @!group Attributes

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

# @return [Hash] the version requirements for this Swift package.
#
attribute :requirement, Hash
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1100"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1100"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1100"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1100"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
26 changes: 26 additions & 0 deletions spec/project/object/native_target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,32 @@ module ProjectSpecs
@target.build_phases.map(&:isa).should == %w(PBXHeadersBuildPhase PBXSourcesBuildPhase PBXFrameworksBuildPhase PBXSourcesBuildPhase PBXHeadersBuildPhase PBXSourcesBuildPhase)
end
end

describe '#to_hash_as' do
it "does not include package product dependencies in its hash if there aren't any" do
@target.to_hash_as['packageProductDependencies'].should.be.nil
end

it 'include package product dependencies in its hash if it contains at least one' do
@target.package_product_dependencies << XCSwiftPackageProductDependency.new(@project, 'uuid')
@target.to_hash_as['packageProductDependencies'].should == ['uuid']
end
end

describe '#to_ascii_plist' do
it "does not include package product dependencies in its plist if there aren't any" do
@target.to_ascii_plist.value['packageProductDependencies'].should.be.nil
end

it 'include package product dependencies in its plist if it contains at least one' do
@target.package_product_dependencies << XCSwiftPackageProductDependency.new(@project, 'uuid1')
@target.package_product_dependencies << XCSwiftPackageProductDependency.new(@project, 'uuid2')
@target.to_ascii_plist.value['packageProductDependencies'].should == [
Nanaimo::String.new('uuid1', ' SwiftPackageProductDependency '),
Nanaimo::String.new('uuid2', ' SwiftPackageProductDependency '),
]
end
end
end

#----------------------------------------#
Expand Down
2 changes: 1 addition & 1 deletion spec/scheme_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ module ProjectSpecs
expected = <<-XML.gsub(/^ {8}/, '')
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1100"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down