Skip to content

Conversation

@dcharkes
Copy link
Contributor

@dcharkes dcharkes commented Nov 28, 2025

Issue Link:

#178954

(beta CP: #179211)

Impact Description:

Running flutter test on Linux or MacOS which does not have a clang starts failing on projects that target only Android otherwise (and do not require a Linux or MacOS toolchain) when there are build hooks anywhere in the dependencies.

This PR changes the behavior for flutter test to only pass clang and friends if they are installed. This means that if a Linux/MacOS toolchain is installed on the system, it will be used for both flutter run -d Linux/MacOS and flutter test (so that the same native compiler is used), but if it's not installed on the system both flutter run -d AndroidDevice and flutter test run successfully.

This means end users don't have to go modify their systems/CIs to install Linux/MacOS toolchains for Android projects.

Changelog Description:

[flutter/178954] Fixes running flutter test on Linux/MacOS for Android projects with build hooks without the desktop native tooling installed.

Workaround:

All end users have to install clang and ldd on Linux/MacOS hosts and CI bots.

Risk:

What is the risk level of this cherry-pick?

  • Low
  • Medium
  • High

It changes the flow in Flutter tools from throwing an error to returning a nullable value.

Test Coverage:

Are you confident that your fix is well-tested by automated tests?

  • Yes
  • No

Validation Steps:

On a Linux and MacOS system, make a Flutter app that only targets Android. Add a build hook. And ensure there's no clang on the PATH (Can be verified by flutter doctor -v finding no tooling for Flutter desktop). Run flutter test and it shouldn't fail due to clang not being installed. For MacOS, XCode needs to not be installed.

@dcharkes dcharkes requested a review from a team as a code owner November 28, 2025 12:07
@dcharkes dcharkes added the cp: review Cherry-picks in the review queue label Nov 28, 2025
@flutter-dashboard
Copy link

This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter.

Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed.

@github-actions github-actions bot added tool Affects the "flutter" command-line tool. See also t: labels. a: desktop Running on desktop team-ios Owned by iOS platform team labels Nov 28, 2025
@dcharkes dcharkes changed the title [stable] Build hooks: Don't require toolchain for unit tests [CP-stable] Build hooks: Don't require toolchain for unit tests Nov 28, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the native toolchain discovery for Linux and macOS to be optional, which is a great improvement. This fixes an issue where flutter test would fail on systems without a native desktop toolchain (e.g., clang) when a project had dependencies with build hooks, even if the project only targeted Android. The changes correctly make cCompilerConfigLinux and cCompilerConfigMacOS return null instead of throwing an error if the toolchain isn't found, controlled by a new throwIfNotFound parameter. This parameter is appropriately set to false for test runs. I also appreciate the improvement to the macOS toolchain discovery to use xcrun --find, which is more robust. The changes are well-tested with new unit tests verifying the new behavior. I have a couple of minor suggestions to improve an error message and a test assertion.

);

if (found == null && throwIfNotFound) {
throwToolExit('Failed to find any of $possibleExecutableNames in $path');
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better log readability, consider using path.path here to avoid printing the Directory: prefix in the error message.

Suggested change
throwToolExit('Failed to find any of $possibleExecutableNames in $path');
throwToolExit('Failed to find any of $possibleExecutableNames in ${path.path}');

}

await fileSystem.file('/a/path/to/clang++').create(recursive: true);
expect(cCompilerConfigLinux(throwIfNotFound: false), completes);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The completes matcher is correct, but not very specific. Since cCompilerConfigLinux is expected to return null in this scenario, using isNull would make the test's intent clearer and more precise. This also improves consistency with the corresponding test for macOS which uses isNull.

Suggested change
expect(cCompilerConfigLinux(throwIfNotFound: false), completes);
expect(await cCompilerConfigLinux(throwIfNotFound: false), isNull);

@dcharkes
Copy link
Contributor Author

cc @goderbauer

@eyebrowsoffire eyebrowsoffire added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 2, 2025
@auto-submit auto-submit bot merged commit 3ddc40e into flutter-3.38-candidate.0 Dec 2, 2025
146 checks passed
@auto-submit auto-submit bot deleted the cp-178954-to-stable branch December 2, 2025 19:05
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop autosubmit Merge PR when tree becomes green via auto submit App cp: review Cherry-picks in the review queue team-ios Owned by iOS platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants