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

Xcodegen cache bug? #1457

Closed
Snikss opened this issue Mar 1, 2024 · 2 comments · Fixed by #1476
Closed

Xcodegen cache bug? #1457

Snikss opened this issue Mar 1, 2024 · 2 comments · Fixed by #1476

Comments

@Snikss
Copy link

Snikss commented Mar 1, 2024

I have a git hook post-checkout, when i checkout i start a script it's just a one line - "xcodegen generate --use-cache".
So the bug is that it's not work in my case.
My case:
Everything happens in local repo.
I create new branch from develop for example branch-1.
I create a new file on branch-1 with some swift class, commit it in local repo and then go back to develop.
When i checkout hook start a command - "xcodegen generate --use-cache" but it says "Project ProjectName has not changed since cache was written", but develop doesn't has a new file which i created on branch-1.
For this case i need to write xcodegen generate on terminal by hand.
Whats wrong why it doesn't work and how fix it?

@yonaskolb
Copy link
Owner

Yeah it's possible to get some false positive cache hits when regenerating a project that is in the same project configuration state it was in last time, but the underlying xcode project has had a change made via the interface.
This happens as the cache uses the project spec and the files in all sources as the cache key. If you make changes to the project like adding a file, XcodeGen doesn't know about this. When you revert the changes, and try and regenerate, XcodeGen doesn't know the underlying project has been changed.

Thinking about it now, XcodeGen could theoretically use the xcode project contents as part of the cache key, but that could also lead to less caching as the project could change underneath as Xcode saves it's own state, and doesn't always 100% equal what XcodeGen generates.

One workaround for now, is running xcodegen with cache after each commit (in a post-commit hook). That would add your new file to the cache, so that when you go back to develop it notices a change. But this is perhaps non workable if you use swift packages, as Xcode likes to resolve packages each time it detects project changes (or is opened), which can get annoying rather quickly

Thoughts?

@yonaskolb
Copy link
Owner

yonaskolb commented Apr 24, 2024

Just had an idea about this, as the issue came up in a project I'm working on. We have xcodegen run with cache on post-rewrite, post-merge and post-checkout. Your above issue can happen, but there's another one.
If someone:

  • checks out a branch (post-checkout and xcodegen runs and writes caches)
  • adds a file and commits
  • amends that commit with any change (post-rewrite will run, and then xcodegen will see the cache is different due to the added file and so generate)
  • xcode will now see a changed project on disk and decide to resolve packages which can get annoying, especially when it decides to just delete package.resolved entirely.

So the idea is to add a new command to xcodegen that tells it to just update it's cache without generating. This can then run in a post-commit command, and would fix both issues.

Then the only way I can foresee the cache getting out of date is if someone adds a file in xcode, and then discards the changes in git. XcodeGen wouldn't know about that (there's no discard changes git hook as far as I'm aware), and the project would be invalid. There's a rarer case though.

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 a pull request may close this issue.

2 participants