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

Feature: Xcode 16.0 support #942

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion lib/xcodeproj/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Constants

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

# @return [String] The last known Xcode version to Xcodeproj.
#
Expand Down Expand Up @@ -132,6 +132,7 @@ module Constants
# @return [Hash] The compatibility version string for different object versions.
#
COMPATIBILITY_VERSION_BY_OBJECT_VERSION = {
77 => 'Xcode 16.0',
63 => 'Xcode 15.3',
60 => 'Xcode 15.0',
56 => 'Xcode 14.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 @@ -533,3 +533,5 @@ def inspect
require 'xcodeproj/project/object/root_object'
require 'xcodeproj/project/object/target_dependency'
require 'xcodeproj/project/object/reference_proxy'
require 'xcodeproj/project/object/file_system_synchronized_root_group'
require 'xcodeproj/project/object/file_system_synchronized_build_file_exception_set'
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'xcodeproj/project/object_attributes'
require 'xcodeproj/project/object/helpers/groupable_helper'

module Xcodeproj
class Project
module Object
# This class represents a file system synchronized build file exception set.
class PBXFileSystemSynchronizedBuildFileExceptionSet < AbstractObject
has_one :target, AbstractTarget
attribute :membership_exceptions, Array

def display_name
"Exceptions for \"#{GroupableHelper.parent(self).display_name}\" folder in \"#{target.name}\" target"
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'xcodeproj/project/object/file_system_synchronized_build_file_exception_set'

module Xcodeproj
class Project
module Object
# This class represents a file system synchronized root group.
class PBXFileSystemSynchronizedRootGroup < AbstractObject
Copy link
Contributor

Choose a reason for hiding this comment

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

@Brett-Best thank you for working on this!

Unfortunately, from what I was able to gather, the implementation is a tiny bit incomplete.

  1. There are a few attributes that PBXFileSystemSynchronizedRootGroup has in common with PBXGroup, such as tabs/indent properties.

  2. There are also some properties unique to PBXFileSystemSynchronizedRootGroup that need to be added, such as explicitFileTypes, explicitFolders and exceptions (which require a further PBXFileSystemSynchronizedBuildFileExceptionSet object to represent).

Without this, I believe the representation will be incomplete and cause crashes.

I can recommend this article on synchronized groups by @pepicrft or this Tuist PR by the same for further info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the reply, yeah, it would be nice if the project file specification was published somewhere 🙃.
Yep, I expect if the project file uses these additional attributes that warnings/errors/crashes should be emitted.

I basically just added support to unblock the current utilization of the PBXFileSystemSynchronizedRootGroup in a project I was working on.

I may or may not end up updating this PR with the additional types, given CocoaPods is now in maintenance mode 😄.

Unfortunately, can't migrate off of CocoaPods to SPM yet because React Native 😢

Copy link
Contributor

Choose a reason for hiding this comment

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

You know, I don't think you're that far away! There are only a few things missing:

  • Copy attributes from PBXGroup to PBXFileSystemSynchronizedRootGroup: name, uses_tabs, indent_width, tab_width, wraps_lines
  • Add new attributes to PBXFileSystemSynchronizedRootGroup:
    • explicit_file_types (type Hash)
    • explicit_folders (type Array)
    • exceptions (relation, has_many of type PBXFileSystemSynchronizedBuildFileExceptionSet)
  • Add new type PBXFileSystemSynchronizedBuildFileExceptionSet with attributes:
    • target (relation, has_one AbstractTarget)
    • membership_exceptions (type Array)
    • public_headers (type Array)
    • private_headers (type Array)
    • additional_compiler_flags_by_relative_path (type Hash)
    • attributes_by_relative_path (type Hash)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the reply, I've run into a new issue:

When a build configuration uses an xcconfig in the new folders the baseConfigurationReference is removed and replaced with baseConfigurationReferenceAnchor (PBXFileSystemSynchronizedRootGroup) and baseConfigurationReferenceRelativePath.

I managed to add that to the xcodeproj mostly fine but on the cocoapods side it needs some love at least in this section:
https://github.com/CocoaPods/CocoaPods/blob/85e6d43ca63f8acf0bb3f3d910e8ff1f6558a4e8/lib/cocoapods/installer/user_project_integrator/target_integrator/xcconfig_integrator.rb#L44-L66

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another issue is that my change adds file_system_synchronized_groups to all entries which is fine but when you edit the project file in Xcode, it removes the entries that are empty arrays.

Would you have any idea how I can stop Xcodeproj from adding empty array entries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same issue above with the exceptions key of a PBXFileSystemSynchronizedRootGroup.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Brett-Best I've looked at the rest of the uses of has_many - I think it's not possible to avoid initializing the empty ObjectList. Is this causing any issues? From what I know, many other things generated by Xcodeproj get modified by Xcode, and this has never been a concern.

In any case, great work! There are just a few more attributes to add, I think all of those are simple value types:

  • Copy attributes from PBXGroup to PBXFileSystemSynchronizedRootGroup: name, uses_tabs, indent_width, tab_width, wraps_lines
  • Add new attributes to PBXFileSystemSynchronizedRootGroup:
    • explicit_file_types (type Hash)
    • explicit_folders (type Array)
  • Add new attributes to PBXFileSystemSynchronizedBuildFileExceptionSet:
    • public_headers (type Array)
    • private_headers (type Array)
    • additional_compiler_flags_by_relative_path (type Hash)
    • attributes_by_relative_path (type Hash)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@igor-makarov along with the additional attributes listed, hopefully they don't also add empty groups.
Yes it is an issue, other things in the Pod project can sometimes change if you open it in Xcode to inspect the settings etc but this far less likely to be done on a day to day basis.
Whereas changing the settings of your own project is much more common.
Where I work atm we have churn of this getting added in / removed.
As a workaround I did come up with some regex but I couldn't get it to work on shell cause multiline hah...

attribute :path, String
attribute :source_tree, String, 'group'
has_many :exceptions, PBXFileSystemSynchronizedBuildFileExceptionSet

def display_name
return path if path
super
end
end
end
end
end
3 changes: 2 additions & 1 deletion lib/xcodeproj/project/object/group.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'xcodeproj/project/object/helpers/groupable_helper'
require 'xcodeproj/project/object/helpers/file_references_factory'
require 'xcodeproj/project/object/file_system_synchronized_root_group'

module Xcodeproj
class Project
Expand All @@ -13,7 +14,7 @@ class PBXGroup < AbstractObject
# @return [ObjectList<PBXGroup, PBXFileReference>]
# the objects contained by the group.
#
has_many :children, [PBXGroup, PBXFileReference, PBXReferenceProxy]
has_many :children, [PBXGroup, PBXFileReference, PBXReferenceProxy, PBXFileSystemSynchronizedRootGroup]

# @return [String] the directory to which the path is relative.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/xcodeproj/project/object/native_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class AbstractTarget < AbstractObject
#
has_many :dependencies, PBXTargetDependency

has_many :file_system_synchronized_groups, PBXFileSystemSynchronizedRootGroup

public

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

# @return [String] preferred project object version
#
attribute :preferred_project_object_version, String, '77'

# @return [PBXGroup] the group containing the references to products of
# the project.
#
Expand Down
4 changes: 4 additions & 0 deletions spec/project/object/root_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ module ProjectSpecs
@root_object.minimized_project_reference_proxies.should == '0'
end

it 'returns the preferred project object version' do
@root_object.preferred_project_object_version.should == '77'
end

it 'returns the products group' do
@root_object.product_ref_group.class.should == PBXGroup
end
Expand Down
Loading