Skip to content

Commit

Permalink
Merge pull request #668 from dnkoutso/compatibility_version_mapping
Browse files Browse the repository at this point in the history
Set root object compatibility version depending on object version.
  • Loading branch information
dnkoutso authored Mar 21, 2019
2 parents 2f9015f + 2adfeb8 commit 0ec1f7f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

##### Bug Fixes

* Set root object compatibility version depending on object version.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso) & [Doug Mead](https://github.com/dmead28)
[#668](https://github.com/CocoaPods/Xcodeproj/pull/668)

* Normalize xcconfig path when generating includes.
[bclymer](https://github.com/bclymer)

Expand Down
14 changes: 14 additions & 0 deletions lib/xcodeproj/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ module Constants
LAST_KNOWN_OSX_SDK = '10.14'

# @return [String] The last known tvOS SDK (stable).
#
LAST_KNOWN_TVOS_SDK = '12.0'

# @return [String] The last known watchOS SDK (stable).
#
LAST_KNOWN_WATCHOS_SDK = '5.0'

# @return [String] The last known archive version to Xcodeproj.
Expand All @@ -25,6 +27,7 @@ module Constants
LAST_KNOWN_SWIFT_VERSION = '4.0'

# @return [String] The default object version for Xcodeproj.
#
DEFAULT_OBJECT_VERSION = 46

# @return [String] The last known object version to Xcodeproj.
Expand Down Expand Up @@ -120,6 +123,17 @@ module Constants
'zip' => 'archive.zip',
}.freeze

# @return [Hash] The compatibility version string for different object versions.
#
COMPATIBILITY_VERSION_BY_OBJECT_VERSION = {
51 => 'Xcode 10.0',
50 => 'Xcode 9.3',
48 => 'Xcode 8.0',
47 => 'Xcode 6.3',
46 => 'Xcode 3.2',
45 => 'Xcode 3.1',
}.freeze

# @return [Hash] The uniform type identifier of various product types.
#
PRODUCT_TYPE_UTI = {
Expand Down
4 changes: 4 additions & 0 deletions lib/xcodeproj/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def initialize(path, skip_initialization = false, object_version = Constants::DE
unless skip_initialization
initialize_from_scratch
@object_version = object_version.to_s
unless Constants::COMPATIBILITY_VERSION_BY_OBJECT_VERSION.key?(object_version)
raise ArgumentError, "[Xcodeproj] Unable to find compatibility version string for object version `#{object_version}`."
end
root_object.compatibility_version = Constants::COMPATIBILITY_VERSION_BY_OBJECT_VERSION[object_version]
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ module ProjectSpecs
@project.root_object.main_group.class.should == PBXGroup
end

it 'initializes the root object compatibility version' do
@project.root_object.compatibility_version.should == 'Xcode 3.2'
end

it 'initializes the root object compatibility version on different object version' do
project = Xcodeproj::Project.new('foo.xcodeproj', false, 50)
project.root_object.compatibility_version.should == 'Xcode 9.3'
end

it 'raises when a compatibiliy version string cannot be found for an unknown object version' do
e = should.raise ArgumentError do
Xcodeproj::Project.new('foo.xcodeproj', false, 999)
end
e.message.should == '[Xcodeproj] Unable to find compatibility version string for object version `999`.'
end

it 'initializes the root object products group' do
product_ref_group = @project.root_object.product_ref_group
product_ref_group.class.should == PBXGroup
Expand Down

0 comments on commit 0ec1f7f

Please sign in to comment.