Elijah Okoroh e04f0bcfc3
Fix Xcode cache errors (#175659)
This PR fixes a race condition that causes intermittent build failures
on iOS with errors like no such file or directory. These failures were
frequently observed in CI tests running on macOS.

The root cause is that the background wireless device discovery process,
which uses `devicectl`, was not being terminated after a target device
was selected. This background process could then delete Xcode's module
caches while `xcodebuild` was actively using them, leading to a build
failure.

The fix ensures that the wireless device discovery process is explicitly
stopped at all logical exit points of the device discovery flow. This is
achieved by calling stopExtendedWirelessDeviceDiscovery() as soon as:

- A single specified device is found and validated.

- An ephemeral device is chosen.

- A user interactively selects a device from a list.

- The discovery process concludes in a non-interactive environment (like
CI).

This change prevents the devicectl process from running concurrently
with the app build, thus resolving the race condition and improving the
reliability of iOS builds.

### Testing: 

- This is tested by checking the bringup to make sure the following
tests are passing:
* [Mac_arm64_ios
integration_test_test_ios](https://ci.chromium.org/ui/p/flutter/builders/prod/Mac_arm64_ios%20integration_test_test_ios?limit=200)
* [Mac_ios
wide_gamut_ios](https://ci.chromium.org/ui/p/flutter/builders/prod/Mac_ios%20wide_gamut_ios?limit=200)
* [Mac_ios
native_assets_ios](https://ci.chromium.org/ui/p/flutter/builders/prod/Mac_ios%20native_assets_ios?limit=200)
* [Mac_ios
spell_check_test](https://ci.chromium.org/ui/p/flutter/builders/prod/Mac_ios%20spell_check_test?limit=200)
* [Mac_ios
channels_integration_test_ios](https://ci.chromium.org/ui/p/flutter/builders/prod/Mac_ios%20channels_integration_test_ios?limit=200)


fixes #174444 

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [X] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-10-09 19:18:12 +00:00
..