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: Previews crash when accessing resources from cached XCFrameworks #6028

Conversation

anlaital-oura
Copy link
Collaborator

@anlaital-oura anlaital-oura commented Mar 5, 2024

This is continuation of #6008.

Short description 📝

SPM has the #if DEBUG guard within which ProcessInfo is used. It works because SPM doesn't precompile anything, so compiling the bundle accessor happens with debug configuration.

However, if you run tuist cache for all dependencies and then tuist generate SomeFramework, it will cause a crash when running Previews as tuist cache builds for release mode and resulting code will bypass this check. It still works with the previous implementation if running tuist generate SomeFramework DependencyWithResources, but that defeats the point of caching and makes using Previews less predictable.

While I wanted to stay as close to the original SPM implementation as possible, I don't think there is any harm in checking for this environment variable in release configuration either. It will simply be not set.

How to test the changes locally 🧐

  1. cd fixtures/app_with_previews
  2. tuist install
  3. tuist cache
  4. tuist generate PreviewsFramework
  5. Open TestView.swift and tap on the button in Previews and it will crash

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.

As you mention, removing the DEBUG compiler directive should be fine as the PACKAGE_RESOURCE_BUNDLE_PATH variable should be simply not defined outside of previews

@fortmarek fortmarek added the changelog:fixed PR will be listed in the Fixed section of CHANGELOG label Mar 5, 2024
@pepicrft pepicrft merged commit 70f7636 into tuist:main Mar 5, 2024
2 of 8 checks passed
@anlaital-oura anlaital-oura deleted the anlaital/remove-debug-guard-from-module-accessor branch March 5, 2024 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:fixed PR will be listed in the Fixed section of CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants