kronenthaler / mod-pbxproj

A python module to manipulate XCode projects
MIT License
1.2k stars 294 forks source link

[BUG] Local package XCLocalSwiftPackageReference is not getting parsed properly #340

Closed michalszelagsonos closed 5 months ago

michalszelagsonos commented 5 months ago

Describe the bug I have a xcode project where there is a local package defined as follows:

packageReferences = (
                                BABB55E92B30EE41003E224D /* XCLocalSwiftPackageReference "Foo" */
                        );
...
/* Begin XCLocalSwiftPackageReference section */
                BABB55E92B30EE41003E224D /* XCLocalSwiftPackageReference "Foo" */ = {
                        isa = XCLocalSwiftPackageReference;
                        relativePath = Foo;
                };
/* End XCLocalSwiftPackageReference section */

If I load the project and save it like this:

project = pbxproj.XcodeProject.load(project_file)
project.save()

I end up with this:

packageReferences = (
                                BABB55E92B30EE41003E224D
                        );
...
/* Begin XCLocalSwiftPackageReference section */
                BABB55E92B30EE41003E224D = {
                        isa = XCLocalSwiftPackageReference;
                        relativePath = Foo;
                };
/* End XCLocalSwiftPackageReference section */

Looks like the comment markers get stripped since there is no XCLocalSwiftPackageReference object type in the project to support this.

System information

  1. pbxproj version used: 4.0.0
  2. python version used: 3.11
  3. Xcode version used: 15.2

To Reproduce Steps to reproduce the behavior:

  1. Add a local dependency to your Xcode project
  2. Save the project.
  3. Load the project in python
    project = pbxproj.XcodeProject.load("path to your project.pbxproj file")
    project.save()
  4. Inspect your project.pbxproj file, you will see that XCLocalSwiftPackageReference comments are gone in the file.

Expected behavior Loading and saving the project should preserve the entries, as is.

michalszelagsonos commented 5 months ago

Note, I think I know how to fix this, I may take a shot at opening a PR with a fix.