[stable] Only exclude platform directories that actually exist in analysis_options.yaml - #191530
Conversation
…ions.yaml (flutter#191151) `AnalysisOptionsMigration` wrote a fixed seven-entry `exclude` list (`android/**`, `ios/**`, `web/**`, `windows/**`, `macos/**`, `linux/**`, plus `build/**`) into `analysis_options.yaml` on every `flutter pub get` / `flutter analyze` / `flutter run` / `flutter build`, regardless of what the project actually contains. Two concrete problems from this: - A Dart-only package (e.g. `dart create -t web`) that uses `web/` as a real source directory gets it silently excluded from analysis the first time any `flutter` command touches the package (this happens in mixed Flutter/Dart monorepos and Dart workspaces). - A Flutter app created with `flutter create --platforms=android,ios` still gets exclusions for `web/`, `windows/`, `macos/`, and `linux/`, which it doesn't have, and `ProjectMigrator` has no opt-out — every command restores the full list. Fix: - `AnalysisOptionsMigration.migrate()` now skips entirely when the package has no `flutter` dependency (i.e. it isn't a Flutter project at all — the discriminator suggested in the issue). - The exclude list is now built conditionally from `project.<platform>.existsSync()` for each platform, so only directories the project actually has as platform scaffolds are excluded. `build/**` stays unconditional. - `templates/app/analysis_options.yaml.tmpl` (used by `flutter create`) gets the same per-platform conditionals via the existing mustache context (`{{#android}}`, `{{#ios}}`, etc.), so newly created projects don't get the fixed list either. Fixes flutter#191131 ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] 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. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [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/ [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
|
@AlexV525 please fill out the PR description above, afterwards the release team will review this request. |
|
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. |
There was a problem hiding this comment.
Code Review
This pull request updates the analysis options migration and template generation to only exclude platform-specific directories (such as android/, ios/, etc.) if they actually exist in the project. It also skips the migration entirely for pure Dart packages that do not depend on Flutter. Unit and integration tests have been added and updated to verify these behaviors, including refactoring the test context to use a real FlutterProject view of an in-memory directory instead of a fake. There are no review comments, and I have no feedback to provide.
This pull request is created by automatic cherry pick workflow
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.
Issue Link:
#191131
Impact Description:
AnalysisOptionsMigration(shipped in 3.47.0) writes a fixed seven-entryexcludelist (android/**,ios/**,web/**,windows/**,macos/**,linux/**,build/**) intoanalysis_options.yamlon everyflutter pub get/analyze/run/build, regardless of which directories the project actually contains. A Dart-only package (e.g.dart create -t web) that usesweb/as a source directory gets it silently excluded from analysis the first time any Flutter command touches the package, and there is no opt-out — the entries are restored on every command.Changelog Description:
[flutter/191131] Only exclude platform directories that actually exist, so
web/**sources in Dart web packages are no longer silently dropped from analysis.Workaround:
None — every Flutter command that reaches
ensureReadyForPlatformSpecificToolingrestores the full exclude list; the only way to keep the entries out is to not run Flutter tooling in the package.Risk:
What is the risk level of this cherry-pick?
Test Coverage:
Are you confident that your fix is well-tested by automated tests?
Validation Steps:
dart create -t web repro && cd repro && flutter pub get— confirmweb/**is not added to theexcludelist anddart analyzestill reports errors inweb/main.dart.flutter create --platforms=android,ios app— confirmanalysis_options.yamlonly excludesbuild/**,android/**, andios/**.packages/flutter_tools/test/general.shard/migrations/analysis_options_migration_test.dartandpackages/flutter_tools/test/commands.shard/permeable/create_test.dart.