Skip to content

[scan] default_derived_data supports build for running off#22231

Merged
iBotPeaches merged 5 commits into
fastlane:masterfrom
jmihaliczas3d:fix-scan-derived-data
May 6, 2026
Merged

[scan] default_derived_data supports build for running off#22231
iBotPeaches merged 5 commits into
fastlane:masterfrom
jmihaliczas3d:fix-scan-derived-data

Conversation

@jmihaliczas3d

@jmihaliczas3d jmihaliczas3d commented Sep 18, 2024

Copy link
Copy Markdown
Contributor

Checklist

  • I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • I see several green ci/circleci builds in the "All checks have passed" section of my PR (connect CircleCI to GitHub if not)
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.
  • I've added or updated relevant unit tests.

Motivation and Context

Resolves #22230

Description

In cases when build_settings does not work for the project with the given scheme, because build for running is OFF, detect_derived_data will just keep derived_data_path unset instead of using an invalid path.
Error message is displayed to guide the user for fixing the issue, but chances that leaving derived data to xcodebuild will also work, so we do not stop execution.

Testing Steps

I tested this change in my setup, and it worked nicely. Presented the error, but scan did not override derived data in the xcodebuild command, so it just used the right one.

@jmihaliczas3d

Copy link
Copy Markdown
Contributor Author

@iBotPeaches this is a very little change, and CI looks happy. Would you mind taking a look, is there anything needed to get it merged?

@iBotPeaches

Copy link
Copy Markdown
Member

thanks. So best I understand if we can't programmatically determine the derived data path - we previously just threw some directory traversal on top of a blank path - making something invalid. This now catches the missing value - throws an error and returns nil - which downstream code handles? or errors out?

@iBotPeaches iBotPeaches changed the title Scan: default_derived_data supports build for running off [scan] default_derived_data supports build for running off May 6, 2026
@jmihaliczas3d

Copy link
Copy Markdown
Contributor Author

thanks. So best I understand if we can't programmatically determine the derived data path - we previously just threw some directory traversal on top of a blank path - making something invalid. This now catches the missing value - throws an error and returns nil - which downstream code handles? or errors out?

Thanks for taking a look.
Yes, in the error case without the fix derived data becomes just ../../.., and the result of it can range from cross-talk on CI or polluting the user's folders.
The symptomatic fix is to display the error message and leave derived data unset in config, which means not specifying it for xcodebuild, see

proj << "-derivedDataPath #{options[:derived_data_path].shellescape}" if options[:derived_data_path]
, which will work if the project is set up correctly. Certainly better than specifying ../../.., and imho better than erroring out because of this (debatable).

@iBotPeaches iBotPeaches merged commit bc81ad9 into fastlane:master May 6, 2026
9 checks passed

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey @jmihaliczas3d 👋

Thank you for your contribution to fastlane and congrats on getting this pull request merged 🎉
The code change now lives in the master branch, however it wasn't released to RubyGems yet.
We usually ship about once a month, and your PR will be included in the next one.

Please let us know if this change requires an immediate release by adding a comment here 👍
We'll notify you once we shipped a new release with your changes 🚀"

PratikPatil131 pushed a commit to PratikPatil131/fastlane that referenced this pull request May 9, 2026
…h if BUILT_PRODUCTS_DIR missing (fastlane#22231)

* Scan: default_derived_data supports build for running off

* Fix default_path nil check

* Empty commit to trigger CI validation

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Congratulations! 🎉 This was released as part of fastlane 2.234.0 🚀

ajpallares added a commit to RevenueCat/purchases-ios that referenced this pull request May 12, 2026
The previous commit added the test bundle to the scheme's <BuildAction>
to fix `xcodebuild -showBuildSettings` returning empty settings. That
worked in theory, but in practice CI showed that once xcodebuild has a
buildable in the scheme it enforces scheme-level destination validation
against the test target's effective platforms, and rejects iOS Simulator
destinations:

    xcodebuild: error: Unable to find a destination matching the
    provided destination specifier:
            { platform:iOS Simulator, id:... }
    Available destinations for the "SPMIntegration" scheme:
            { platform:visionOS Simulator, ...Designed for [iPad,iPhone]... }

The empty <BuildAction> in the original scheme was effectively the
escape hatch that let fastlane pass an iOS Simulator destination and
have it accepted. Removing that escape hatch broke the build.

Revert the scheme and project.pbxproj changes back to main and instead
fix the real symptom: tell `fastlane scan` where to put / find derived
data. Once `derived_data_path` is set, `Scan::DetectValues
.default_derived_data` short-circuits before the
`BUILT_PRODUCTS_DIR is nil` early-return introduced in
fastlane/fastlane#22231 (fastlane 2.234.0), and the `.xcresult` lookup
works the same way it did under 2.233.1.

Use the same value (`scan_derived_data`) that the BackendIntegrationTests
and v3/v4 LoadShedderIntegration lanes already use in `fastlane/Fastfile`.

Co-authored-by: Cursor <cursoragent@cursor.com>
ajpallares added a commit to RevenueCat/purchases-ios that referenced this pull request May 12, 2026
* Fix Custom Entitlement Computation SPM installation test scheme

The `SPMIntegration` scheme in `SPMCustomEntitlementComputationInstallation` had
an empty `<BuildAction>` and a dangling `<LaunchAction>` reference to a
non-existent `SPMInstallation.app` target. That meant
`xcodebuild -showBuildSettings -scheme SPMIntegration` returned no settings
at all (no `BUILT_PRODUCTS_DIR`, no `SUPPORTED_PLATFORMS`).

Until fastlane 2.233.1 this was masked: scan silently fell back to
`File.expand_path("../../..", nil)` as `derived_data_path`, which happened
to be a writable path on CI, so the test ran and scan found the
`.xcresult`. fastlane 2.234.0 (PR fastlane/fastlane#22231) added an
explicit nil-guard in `Scan::DetectValues.default_derived_data`, so
`derived_data_path` is now left unset. `xcodebuild test` then uses its
default `~/Library/Developer/Xcode/DerivedData/...`, scan can't find the
result bundle there, and the installation test fails with
"Cannot find .xcresult in derived data which is needed to determine test
results" even though the test itself passes.

Fix the scheme to match the pattern already used by other test-only
schemes in the repo (e.g. `BackendIntegrationTests.xcscheme`):

- Add a `<BuildActionEntry buildForTesting="YES" .../>` for the
  `SPMInstallationTests.xctest` target so the scheme has a real buildable.
- Replace the dangling `SPMInstallation.app` reference in
  `<LaunchAction><MacroExpansion>` with the test bundle (the app target
  doesn't exist in this project).
- Declare `SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"` on the test
  target so `xcodebuild -showBuildSettings -scheme` resolves cleanly
  regardless of Xcode version.
- Drop the now-unnecessary Scanfile workaround
  (`skip_build(true)` + accompanying comment) — the scheme is no longer
  "only setup for testing, not building".

Co-authored-by: Cursor <cursoragent@cursor.com>

* Revert scheme edit and set derived_data_path explicitly instead

The previous commit added the test bundle to the scheme's <BuildAction>
to fix `xcodebuild -showBuildSettings` returning empty settings. That
worked in theory, but in practice CI showed that once xcodebuild has a
buildable in the scheme it enforces scheme-level destination validation
against the test target's effective platforms, and rejects iOS Simulator
destinations:

    xcodebuild: error: Unable to find a destination matching the
    provided destination specifier:
            { platform:iOS Simulator, id:... }
    Available destinations for the "SPMIntegration" scheme:
            { platform:visionOS Simulator, ...Designed for [iPad,iPhone]... }

The empty <BuildAction> in the original scheme was effectively the
escape hatch that let fastlane pass an iOS Simulator destination and
have it accepted. Removing that escape hatch broke the build.

Revert the scheme and project.pbxproj changes back to main and instead
fix the real symptom: tell `fastlane scan` where to put / find derived
data. Once `derived_data_path` is set, `Scan::DetectValues
.default_derived_data` short-circuits before the
`BUILT_PRODUCTS_DIR is nil` early-return introduced in
fastlane/fastlane#22231 (fastlane 2.234.0), and the `.xcresult` lookup
works the same way it did under 2.233.1.

Use the same value (`scan_derived_data`) that the BackendIntegrationTests
and v3/v4 LoadShedderIntegration lanes already use in `fastlane/Fastfile`.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scan default_derived_data works incorrectly for schemes having build for running off

2 participants