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

Add XCLocalSwiftPackageReference Support #799

Merged
merged 21 commits into from
Oct 15, 2023

Conversation

art-divin
Copy link
Contributor

@art-divin art-divin commented Oct 8, 2023

Resolves krzysztofzablocki/Sourcery#1206

Short description 📝

This PR implements parsing of new element type named XCLocalSwiftPackageReference which seems to be introduced with the release of Xcode 15.

Solution 📦

To support the new element type, I simply copied everything related to XCRemoteSwiftPackageReference and removed all code related to VersionMatching and "URL". Instead, only path argument is supported for instantiating XCLocalSwiftPackageReference.

Implementation 👩‍💻👨‍💻

  • Adopt XCRemoteSwiftPackageReference to XCLocalSwiftPackageReference
  • Add XCLocalSwiftPackageReference to PBXObjectParser switch statement
  • Add caching of XCLocalSwiftPackageReference objects in PBXObjects
  • Add XCLocalSwiftPackageReference support in PBXProject
  • Add integration tests to PBXProjEncoderTests

@netlify
Copy link

netlify bot commented Oct 8, 2023

Deploy Preview for xcodeproj ready!

Name Link
🔨 Latest commit 61c3f90
🔍 Latest deploy log https://app.netlify.com/sites/xcodeproj/deploys/65287f2d07f6280008b884d1
😎 Deploy Preview https://deploy-preview-799--xcodeproj.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@art-divin art-divin changed the title Add XCLocalSwiftPackageReferenceSupport 👍 Add XCLocalSwiftPackageReference Support 👍 Oct 8, 2023
@art-divin
Copy link
Contributor Author

Hello @kwridan, @pepicrft, @yonaskolb 👋🏻

Firstly, thank you very much for supporting this project. It is used by me in many different Swift scripts I wrote.

Could you please review this PR? It is mentioned in Sourcery (krzysztofzablocki/Sourcery#1206) and other projects which face this issue on Xcode 15.
I am surprised that it was already implemented in Xcodeproj, but not here 🕵🏻

I hope I did not miss anything, but if I did, could you please be so kind informing me, I'll apply the change as soon as I can.

Thank you 🙏🏻

Copy link
Collaborator

@kwridan kwridan left a comment

Choose a reason for hiding this comment

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

Thanks for contributing this @art-divin

I wasn't aware Xcode 15 changed this 😅, local packages were previously supported as file references and Xcode somehow deals with them correctly. It seems this is still the case in Xcode 15 if you add a local package via dragging from Finder to Xcode, however if you use the Package editor UI and select "Add Local" this is where this new format is used.

xc15

From testing locally, it seems we may be missing a few pieces. I created a project with a local package, read it via XcodeProj and wrote it back to disk again - the expectation was that it would result in no diffs, however noticed a few things got omitted 🤔

-                       packageReferences = (
-                               FBE04FC42AD3E7F70014D6BD /* XCLocalSwiftPackageReference "../LocalPackage" */,
-                       );
 /* End XCConfigurationList section */
 
-/* Begin XCLocalSwiftPackageReference section */
-               FBE04FC42AD3E7F70014D6BD /* XCLocalSwiftPackageReference "../LocalPackage" */ = {
-                       isa = XCLocalSwiftPackageReference;
-                       relativePath = ../LocalPackage;
-               };
-/* End XCLocalSwiftPackageReference section */
-

It'll be helpful to include a small fixture of a project with a local package using this new format in Fixtures folder and performing a similar integration test (see some of the example test in XcodeProjIntegrationTests).

@art-divin
Copy link
Contributor Author

👋🏻 Hello @kwridan ,

thank you very much for your test!

Apparently, decoding was not set properly. So I have added an integration test to PBXProjEncoderTests and the missing implementation to PBXProjEncoder.swift.

What I have discovered is that addSwiftPackage is missing for "the new way" of adding local references.

I guess it is better to split this feature into multiple PRs, and firstly, implement support to unblock further work.

What do you think?
Any other tests I'd be better adding?

Thank you 🙏🏻

@art-divin
Copy link
Contributor Author

Hey @kwridan ,

I have added one more integration test, and seems that everything1 is settled now.

Please let me know if this PR can be merged or still it is missing somethig.

P.S. when run locally, I got failed unit tests related to git checks, specifically, locally I have enabled all commits signed by default with gpg. So when run, these unit tests fail with the following error:

test_read_write_produces_no_diff(): failed: caught error: "Error Domain=NSPOSIXErrorDomain Code=128 "Unknown error: 128""

in file XCTestCase+Shell.swift on line 21. Console states the following:

Test Case '-[XcodeProjTests.XcodeProjIntegrationTests test_read_write_produces_no_diff]' started.
error: cannot run gpg: No such file or directory
error: gpg failed to sign the data
fatal: failed to write commit object

Footnotes

  1. except for addSwiftPackage which lacks functionality to add local package as XCLocalSwiftPackageReference.

@art-divin
Copy link
Contributor Author

cc @pepicrft, @yonaskolb

Copy link
Collaborator

@kwridan kwridan left a comment

Choose a reason for hiding this comment

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

I have added one more integration test, and seems that everything1 is settled now.

Thanks for the updates @art-divin and for adding the fixture, note the fixture can be simplified and slimmed down to focus primarily on the local package (i.e. it wouldn't need any of the extra schemes / breakpoint files / remote packages etc...) Locally I created a dummy project with a local package and used that test.

when run locally, I got failed unit tests related to git checks, specifically, locally I have enabled all commits signed by default with gpg. So when run, these unit tests fail with the following error:

Interesting, indeed looks like it may be related to the signed commits, as locally and on CI those seem to be ok. Perhaps locally only to get it working you can modify the test helper that invokes the git command to include the appropriate extra arguments?

On the topic of this sort of test, I re-ran it against a local project I created with a local swift package and it seems a diff is still produced with the comments:

(Xcode uses relative path, vs the changes in PR utilise the name)

@@ -117,7 +117,7 @@
                        );
                        mainGroup = FBF72AFE2AD3E600003BEEEF;
                        packageReferences = (
-                               FBE04FC42AD3E7F70014D6BD /* XCLocalSwiftPackageReference "../LocalPackage" */,
+                               FBE04FC42AD3E7F70014D6BD /* XCLocalSwiftPackageReference "LocalPackage" */,
                        );
                        productRefGroup = FBF72B082AD3E600003BEEEF /* Products */;
                        projectDirPath = "";
@@ -366,7 +366,7 @@
 /* End XCConfigurationList section */
 
 /* Begin XCLocalSwiftPackageReference section */
-               FBE04FC42AD3E7F70014D6BD /* XCLocalSwiftPackageReference "../LocalPackage" */ = {
+               FBE04FC42AD3E7F70014D6BD /* XCLocalSwiftPackageReference "LocalPackage" */ = {
                        isa = XCLocalSwiftPackageReference;
                        relativePath = ../LocalPackage;
                };

it might be worth including that sort of test against the fixture?

Comment on lines +131 to +132
/// Remote Swift packages.
public var remotePackages: [XCRemoteSwiftPackageReference] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

to ensure we don't introduce a breaking API change can we maintain the old variable and mark it as deprecated?

Suggested change
/// Remote Swift packages.
public var remotePackages: [XCRemoteSwiftPackageReference] {
/// Remote Swift packages.
@available(*, deprecated, message: "use remotePackages or localPackages.")
public var packages: [XCRemoteSwiftPackageReference] {
remotePackages
}
/// Remote Swift packages.
public var remotePackages: [XCRemoteSwiftPackageReference] {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thank you ✅

@art-divin
Copy link
Contributor Author

👋🏻 Hey @kwridan ,

Thank you for your throughout review 🤝

I have addressed all the points mentioned and hopefully this time PR is ready.

However, I noticed that some other PRs also include changes related to contributors. Should I do it here as well? Anything else?

Thank you

@kwridan
Copy link
Collaborator

kwridan commented Oct 13, 2023

@all-contributors add @art-divin for code

@allcontributors
Copy link
Contributor

@kwridan

I've put up a pull request to add @art-divin! 🎉

Copy link
Collaborator

@kwridan kwridan left a comment

Choose a reason for hiding this comment

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

I have addressed all the points mentioned and hopefully this time PR is ready.

Awesome thank you for the great work on this, testing locally it's all working nicely now 👍

I noticed that some other PRs also include changes related to contributors. Should I do it here as well? Anything else?

Done via #800

@kwridan kwridan requested a review from pepicrft October 13, 2023 07:17
@luispadron luispadron changed the title Add XCLocalSwiftPackageReference Support 👍 Add XCLocalSwiftPackageReference Support Oct 13, 2023
@luispadron
Copy link
Collaborator

One nit would be to squash this PR before merging there are few commits in here

@art-divin
Copy link
Contributor Author

Thank you for your approvals 🤝

Please merge this MR at your convenience, I do not have enough privileges, thank you 👍🏻

@kwridan kwridan merged commit 8b5b4cf into tuist:main Oct 15, 2023
9 checks passed
@ileitch
Copy link
Contributor

ileitch commented Oct 29, 2023

@pepicrft Any chance this change can be released soon? People creating new projects in Xcode 15 that use local package references are currently unable to use XcodeProj (or tools that depend on it) because project parsing fails with an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XCLocalSwiftPackageReference is not supported
4 participants