tuist / tuist

Tuist's CLI
https://tuist.io
MIT License
4.5k stars 537 forks source link

Unexpected Glob behavior #6567

Open ainopara opened 1 month ago

ainopara commented 1 month ago

What happened?

When I use "folder/" to specify resources in Tuist, it returns all results within the folder as well as the folder itself, which is not what I expected and is inconsistent with other tools, such as Ruby's `Dir.glob('folder/')and the output of thefind folder/**` command.

This behavior comes from the following piece of code: https://github.com/tuist/tuist/blob/f2c636e3d0c2e89b0ba9e330f0ef6bee86fe691c/Sources/TuistSupport/Utils/Glob.swift#L134-L137

How do we reproduce it?

  1. Create a directory with the following structure:
    folder
    ├── file1.json
    └── file2.pb
  2. Call Glob(pattern: "folder/**") directly and observe the output.

Error log

N/A

macOS version

15.0 beta3

Tuist version

3.42.2

Xcode version

16.0 beta4

fortmarek commented 1 month ago

@kyounh12 is it possible this would be fixed by your PR?

@ainopara it'd be great if you could create a reproducible sample that showcases when the difference in the glob behavior is an issue 🙏

kyounh12 commented 1 month ago

@kyounh12 is it possible this would be fixed by your PR?

@ainopara it'd be great if you could create a reproducible sample that showcases when the difference in the glob behavior is an issue 🙏

I don't think so. The code mentioned on this issue is still there.

ainopara commented 1 month ago

@ainopara it'd be great if you could create a reproducible sample that showcases when the difference in the glob behavior is an issue 🙏

I tried to create a Project.swift file to reproduce this issue and found that Tuist filters the results of Glob based on the return value of TuistGraph.Target.isResource(path: path) when specifying resource files.

As a result, additional output folders from Glob are filtered out in most cases as they are determined not to be resource files.

However, I noticed that if the folder's extension is "bundle", it will be treated as a resource, leading to unexpected results.

Therefore, I created a demo project that can reproduce this issue: https://github.com/ainopara/BugReportDemo/tree/tuist/tuist-1

In this demo, I expected Tuist to add all files in demo.bundle individually to the project; however, the actual result was that Tuist added the bundle to the project.

fortmarek commented 1 month ago

However, I noticed that if the folder's extension is "bundle", it will be treated as a resource, leading to unexpected results.

Yes, that's expected. .bundle is a special extension and should be treated as a single file.

ainopara commented 1 month ago

However, I noticed that if the folder's extension is "bundle", it will be treated as a resource, leading to unexpected results.

Yes, that's expected. .bundle is a special extension and should be treated as a single file.

If I need to treat demo.bundle as a file, I can use demo.bundle or a notation like *.bundle. Currently, due to the unexpected behavior of the Glob function, I cannot simply include the contents of demo.bundle in the project.

Therefore, I believe this issue, while not significantly impacting users, is still worth fixing.

fortmarek commented 1 month ago

Gotcha. Yeah, happy to take a contribution for this 😌