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

Fix globstar expansion logic to prevent infinite loop when file path contains ** #6174

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kyounh12
Copy link

@kyounh12 kyounh12 commented Apr 11, 2024

Short description 📝

This PR fixes the crash happens when a Swift Package with source file paths containing ** (ex. **(_:_:)) is added to Tuist/Package.swift.

How to test the changes locally 🧐

It can be easily reproduced by adding BigDecimal Swift Package in Tuist/Package.swift

.package(url: "https://github.com/mgriebling/BigDecimal", exact: "2.2.3")

and then run tuist install tuist generate.

It will stuck in the line below and eventually finishes with a non-zero exit code.

Loading and constructing the graph
It might take a while if the cache is empty

The package contains a file with path Sources/BigDecimal/BigDecimal.docc/BigDecimal.doccarchive/documentation/bigdecimal/bigdecimal/**(_:_:)/index.html

Contributor checklist ✅

  • The code has been linted using run mise run lint:fix
  • The change is tested via unit testing or acceptance testing, or both
  • The title of the PR is formulated in a way that is usable as a changelog entry
  • In case the PR introduces changes that affect users, the documentation has been updated

Reviewer checklist ✅

  • The code architecture and patterns are consistent with the rest of the codebase
  • Reviewer has checked that, if needed, the PR includes the label changelog:added, changelog:fixed, or changelog:changed, and the title is usable as a changelog entry

Copy link
Member

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

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

I'm not sure how I feel about this. That's a lot of code in a foundational utility for a case that's more of a misconfiguration on the package side.

I'd rather consider two alternatives:

  • Investigate why this file is being globbed in the first place when it should be considered a regular file returned from the original Sources glob
  • Strip .doccarchive from the generated project – it doesn't make sense to include the individual files in the .doccarchive. That's actually how vanilla SPM behaves, so we can align with that instead:
    image

@kyounh12
Copy link
Author

kyounh12 commented Apr 12, 2024

@fortmarek I agree that .doccarchive should be stripped from the generated project and it may feel like too much code for a little utility function.
However, I still believe wrong interpretation of globstar may cause other problems in the future.

So how about resetting this branch to 00f32ab and open another PR for stripping .doccarchive from the project?

@kyounh12
Copy link
Author

kyounh12 commented Apr 12, 2024

  • Investigate why this file is being globbed in the first place when it should be considered a regular file returned from the original Sources glob

When expanding a globstar, it loops through subpaths and filter paths which is a directory by calling FileManager.isDirectory(path: String) function.

The function calls FileManager.fileExists(atPath path: String, isDirectory: UnsafeMutablePointer<ObjCBool>?) function internally and this fileExists function considers .doccarchive file as a directory.

스크린샷 2024-04-12 오후 10 59 43

This causes the program to continue to search through subpaths under a .doccarchive bundle.

@kyounh12
Copy link
Author

  • Strip .doccarchive from the generated project – it doesn't make sense to include the individual files in the .doccarchive. That's actually how vanilla SPM behaves, so we can align with that instead:

Seems like Xcode is already doing this for us if the project is generated correctly.

스크린샷 2024-04-12 오후 11 16 48

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.

None yet

2 participants