Skip to content

Commit

Permalink
Support for Xcode 11 attributes and objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Jun 11, 2019
1 parent 4ad5b68 commit 43adc38
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 13 deletions.
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
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?
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

0 comments on commit 43adc38

Please sign in to comment.