Skip to content

[flutter_tools] Remove ambient Doctor, FeatureFlags, and device getters - #196572

Merged
auto-submit[bot] merged 6 commits into
flutter:masterfrom
bkonyi:di/context-get-1-doctor-targets
Nov 18, 2026
Merged

auto-submit[bot] merged 6 commits into
flutter:masterfrom
bkonyi:di/context-get-1-doctor-targets

Conversation

@bkonyi

@bkonyi bkonyi commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Removes ambient context.get<T>() getters across doctor workflows and validators (androidWorkflow, androidValidator, androidLicenseValidator, windowsWorkflow, visualStudioValidator), featureFlags in lib/src/features.dart, Cache local-engine checks, deviceManager, emulatorManager, and PersistentToolState.instance, and threads these dependencies explicitly through ToolDependencies, commands, build targets, resident runners, device discoverers, and FlutterVersion.

Part of #47161

Remove ambient `context.get<T>()` getters across doctor workflows, feature flags, cache local-engine checks, device and emulator managers, and persistent tool state, and pass dependencies explicitly through constructors and methods:

- Remove top-level `androidWorkflow`, `androidValidator`, `androidLicenseValidator`, `windowsWorkflow`, `visualStudioValidator`, `featureFlags` (in `lib/src/features.dart`), `deviceManager`, `emulatorManager`, and `PersistentToolState.instance` getters.
- Construct `AndroidValidator`, `AndroidLicenseValidator`, and `VisualStudioValidator` lazily inside `DoctorValidatorsProvider` and `DoctorCommand` using injected `AndroidContext`, `ToolContext`, and workflows.
- Pass `isLocalEngineBuilder` into `Cache` and `FlutterCache` instead of reading `context.get<Artifacts>()` during cache stamp resolution.
- Thread `FeatureFlags`, `DeviceManager`, `EmulatorManager`, and `PersistentToolState` explicitly through commands, build targets, resident runners, device discoverers, and `FlutterVersion`.

Part of flutter#47161
@bkonyi bkonyi added tool Affects the "flutter" command-line tool. See also t: labels. CICD Run CI/CD labels Nov 14, 2026
@github-actions github-actions Bot added platform-ios iOS applications specifically platform-macos Building on or for macOS specifically platform-windows Building on or for Windows specifically platform-linux Building on or for Linux specifically a: desktop Running on desktop team-android Owned by Android platform team team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-windows Owned by the Windows platform team team-linux Owned by the Linux platform team labels Nov 14, 2026
…doctor-targets

# Conflicts:
#	packages/flutter_tools/test/general.shard/isolated/macos/native_assets_test.dart
@bkonyi
bkonyi marked this pull request as ready for review November 16, 2026 21:56
@bkonyi
bkonyi requested review from a team as code owners November 16, 2026 21:57
@bkonyi
bkonyi requested review from camsim99 and chingjun and removed request for a team November 16, 2026 21:57

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors the flutter_tools package to explicitly thread FeatureFlags through constructors, methods, and build environments, reducing reliance on global context lookups. It also introduces dynamic dependency resolution via resolveDependencies on Target and dynamic source resolution via Source.fromEnvironment. The review feedback suggests documenting the distinction between static and dynamic dependencies on Target, passing the FeatureFlags instance directly to buildPatternStemsFor for extensibility, and avoiding bypassing FeatureFlags in the global allConfigurableFeatures getter to preserve testability.

Comment on lines 145 to +149
/// The dependencies of this target.
List<Target> get dependencies;

/// Resolves the dependencies of this target for the given [environment].
List<Target> resolveDependencies(Environment environment) => dependencies;

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.

medium

With the introduction of dynamic dependency resolution via resolveDependencies, the dependencies getter now only returns static dependencies. It would be highly beneficial to document this distinction on both members so that future target implementers know to override resolveDependencies for dynamic dependencies and to use resolveDependencies when querying a target's dependencies within a build pipeline.

Suggested change
/// The dependencies of this target.
List<Target> get dependencies;
/// Resolves the dependencies of this target for the given [environment].
List<Target> resolveDependencies(Environment environment) => dependencies;
/// The static dependencies of this target.
///
/// Prefer using [resolveDependencies] to obtain the full list of dependencies
/// for a specific build environment.
List<Target> get dependencies;
/// Resolves the full list of dependencies of this target for the given [environment],
/// including any dynamic dependencies.
List<Target> resolveDependencies(Environment environment) => dependencies;

Map<String, Object?> getBuildConfig(Environment environment) => buildConfig;
Iterable<File> buildFiles(Environment environment);
Iterable<String> get buildPatternStems;
Iterable<String> buildPatternStemsFor({required bool isRecordUseEnabled});

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.

medium

Instead of passing a specific boolean parameter isRecordUseEnabled to buildPatternStemsFor, consider passing the FeatureFlags instance directly. This makes the method signature more robust and extensible if other feature flags need to influence the build pattern stems in the future.

Suggested change
Iterable<String> buildPatternStemsFor({required bool isRecordUseEnabled});
Iterable<String> buildPatternStemsFor(FeatureFlags featureFlags);

Comment on lines +139 to +140
Iterable<Feature> get allConfigurableFeatures =>
allFlutterFeatures.where((Feature feature) => feature.configSetting != null);

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.

medium

By changing the global allConfigurableFeatures getter to directly reference allFlutterFeatures, we bypass the FeatureFlags instance. This introduces a global dependency and prevents mocking or overriding configurable features in tests. Since FeatureFlags already has an allConfigurableFeatures getter, we should instead thread the FeatureFlags dependency to any callers and use featureFlags.allConfigurableFeatures directly, eventually deprecating or removing this global getter.

chingjun
chingjun previously approved these changes Nov 17, 2026
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 17, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 17, 2026
@auto-submit

auto-submit Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/196572, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

  • The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label.

Pass `featureFlags: TestFeatureFlags()` to the `Environment.test` call in `setUpWebProject` added on `master`, matching the required `featureFlags` parameter introduced on `Environment.test`.
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 18, 2026
Merged via the queue into flutter:master with commit cb38e79 Nov 18, 2026
22 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026
bkonyi added a commit to bkonyi/flutter that referenced this pull request Nov 18, 2026
Resolves merge conflicts with flutter#196571, picks up flutter#196572 and flutter#196740, and converts the remaining prebuilt-binary filter test in `drive_test.dart` to `testWithoutContext`.

Fixes flutter#134073
LouiseHsu pushed a commit to flutter/packages that referenced this pull request Nov 18, 2026
flutter/flutter@2f09f96...06f32f8

2026-11-18 [email protected] Move macOS
desktop builds to ThinLTO (flutter/flutter#196804)
2026-11-18 [email protected] Roll Dart SDK from
5ed55b4b2ebc to 753488ede427 (2 revisions) (flutter/flutter#196893)
2026-11-18 [email protected] Roll Packages from
9af69be to dca2e58 (7 revisions) (flutter/flutter#196892)
2026-11-18 [email protected] Roll Skia from 503a380ebecc
to 81ee7327e81c (29 revisions) (flutter/flutter#196889)
2026-11-18 [email protected] Roll Dart SDK from
26e38955d9d4 to 5ed55b4b2ebc (4 revisions) (flutter/flutter#196843)
2026-11-18 [email protected] Fix permissions for action updates
(flutter/flutter#196791)
2026-11-18 [email protected] iOS: Apply platform view mutators from
FlutterPlatformViewLayer (flutter/flutter#196753)
2026-11-18 [email protected] [flutter_tools] Remove ambient Doctor,
FeatureFlags, and device getters (flutter/flutter#196572)
2026-11-18 [email protected] Fix
RelativeRect.lerp crash when b is null (flutter/flutter#196655)
2026-11-18 [email protected] [web] Harden
WebP and GIF header readers against truncated and malformed buffers
(flutter/flutter#196075)
2026-11-17 [email protected] Enable apps to
control focus behavior during app lifecycle changes via
`FocusLifecyclePolicy` (flutter/flutter#190570)
2026-11-17 [email protected] Don't re-run the code freeze check
on label changes (flutter/flutter#196745)
2026-11-17 [email protected] Android: Report
FlutterView as a text editor while a text input client is attached
(flutter/flutter#193074)
2026-11-17 [email protected] Roll Packages from
4c6a7d3 to 9af69be (5 revisions) (flutter/flutter#196812)
2026-11-17 [email protected] [flutter_tools] Handle target VM filesystem
errors in DevFS.create (flutter/flutter#196234)
2026-11-17 [email protected] [flutter_tools] Clarify analytics reporting
status when on a feature branch (flutter/flutter#194496)
2026-11-17 [email protected] [web] Recover
CanvasKit surfaces from WebGL failures without per-frame null crashes
(flutter/flutter#196257)
2026-11-17 [email protected] [devicelab] Trigger navigation tap via
Flutter Driver in service_extensions_test (flutter/flutter#194456)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to
ensure that a human
is aware of the problem.

To file a bug in Packages:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
chingjun added a commit to chingjun/flutter that referenced this pull request Nov 20, 2026
The branch was rebased onto master (752015c), which dropped its
three merges of master. Those merges held the conflict resolutions and
the regenerated lock files and converter output, and the conflicts of
the replayed commits were resolved in favour of the replayed commit. So
the commits below this one are not expected to build on this base.

This commit restores what the merges held and adds what master's 94
commits since need. Its tree is the tree of a merge of the same master
into the branch as it was before the rebase, and that tree was checked:
gn_to_bazel's tests (301) and --check, check_build_configs.sh,
check_generated_bazel_files.sh, bazel_ci_test.py (23),
engine_build_configs (84), bazel_tools (46), buildifier,
tools/gn_test.py (7), ci/pylint.sh, ci/format.sh (its Python step
through yapf directly), the analyzer over dev/bots and flutter_tools,
dev/bots' tests (51) and the tool test files the branch touches (391
tests); Bazel analysis of ci_host_debug, of host_release_test, of
//:tool_tests //:dart_tests, and of every Linux build under its own
configuration (47). Nothing was compiled or run under Bazel on it.

In it:
- deps.lock.bzl for master's DEPS (the Skia, Dart and ICU rolls) and
  pub.lock.bzl for its pubspec.lock; the converter's output:
  builds.json, configs.bazelrc, ci/builders/BUILD.bazel and six
  generated BUILD.bazel files, lib/gpu's and shell/platform/darwin/ios's
  among them for the sources master added.
- What the merges had ported: flutter#196282 (a Mac's
  impeller_unittests without the Vulkan variants, and
  --use-glfw-swiftshader in linux_host_engine_test.json) in
  bazel_mapping.dart, its test and wrapped_gn_builds.md.
- New with this base: two calls in the tool tests the branch added get
  the arguments flutter#196572 made required
  (isLocalEngineBuilder for Cache, featureFlags for
  FlutterTesterDevice). The merge was clean as text; the analyzer found
  them.
- Upstream's side of hunks both sides had changed: dev/bots
  (run_command.dart, utils.dart and run_command_test.dart, after
  flutter#196479), and the tool's test/runner.dart without the
  559 lines flutter#196123 removed, which the replay of the
  branch's own change to that file had put back.
jmagman pushed a commit to jmagman/flutter that referenced this pull request Nov 24, 2026
…#197269)

Passes the missing required `featureFlags: TestFeatureFlags()` argument
to `Environment.test` in
`packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart`.
This fixes an analysis failure caused when
[flutter#194500](flutter#194500) landed after
[flutter#196572](flutter#196572) made
`featureFlags` required on `Environment.test`.

Previous output:
```
Analyzing flutter_tools...

  error - test/general.shard/build_system/targets/localizations_test.dart:208:27
          - The named parameter 'featureFlags' is required, but there's no
          corresponding argument. Try adding the required argument. -
          missing_required_argument

1 issue found.
```

Current output:
```
Analyzing flutter_tools...
No issues found!
```
chingjun added a commit to chingjun/flutter that referenced this pull request Nov 24, 2026
The branch was rebased onto master (752015c), which dropped its
three merges of master. Those merges held the conflict resolutions and
the regenerated lock files and converter output, and the conflicts of
the replayed commits were resolved in favour of the replayed commit. So
the commits below this one are not expected to build on this base.

This commit restores what the merges held and adds what master's 94
commits since need. Its tree is the tree of a merge of the same master
into the branch as it was before the rebase, and that tree was checked:
gn_to_bazel's tests (301) and --check, check_build_configs.sh,
check_generated_bazel_files.sh, bazel_ci_test.py (23),
engine_build_configs (84), bazel_tools (46), buildifier,
tools/gn_test.py (7), ci/pylint.sh, ci/format.sh (its Python step
through yapf directly), the analyzer over dev/bots and flutter_tools,
dev/bots' tests (51) and the tool test files the branch touches (391
tests); Bazel analysis of ci_host_debug, of host_release_test, of
//:tool_tests //:dart_tests, and of every Linux build under its own
configuration (47). Nothing was compiled or run under Bazel on it.

In it:
- deps.lock.bzl for master's DEPS (the Skia, Dart and ICU rolls) and
  pub.lock.bzl for its pubspec.lock; the converter's output:
  builds.json, configs.bazelrc, ci/builders/BUILD.bazel and six
  generated BUILD.bazel files, lib/gpu's and shell/platform/darwin/ios's
  among them for the sources master added.
- What the merges had ported: flutter#196282 (a Mac's
  impeller_unittests without the Vulkan variants, and
  --use-glfw-swiftshader in linux_host_engine_test.json) in
  bazel_mapping.dart, its test and wrapped_gn_builds.md.
- New with this base: two calls in the tool tests the branch added get
  the arguments flutter#196572 made required
  (isLocalEngineBuilder for Cache, featureFlags for
  FlutterTesterDevice). The merge was clean as text; the analyzer found
  them.
- Upstream's side of hunks both sides had changed: dev/bots
  (run_command.dart, utils.dart and run_command_test.dart, after
  flutter#196479), and the tool's test/runner.dart without the
  559 lines flutter#196123 removed, which the replay of the
  branch's own change to that file had put back.
chingjun added a commit to chingjun/flutter that referenced this pull request Nov 24, 2026
Not a change of this branch's. Master's head (ac8f87e) is red
without it, and a pull request based on that commit would show
upstream's failure as its own.

flutter#194500 added a test to
test/general.shard/build_system/targets/localizations_test.dart
("GenerateLocalizationsTarget rebuilds when pubspec.yaml dependencies
change") that calls Environment.test without featureFlags. The
argument has been required since flutter#196572, which landed
five days earlier, so the file does not compile: the analyzer reports
missing_required_argument, and every shard that loads the file fails.
The file's other call of it passes TestFeatureFlags(); this one does
now.

To be dropped at the next rebase, when upstream has fixed or reverted
it.

Checked: the analyzer over flutter_tools reports no issue with it
(one, this one, without), and the file's 8 tests pass.
chingjun added a commit to chingjun/flutter that referenced this pull request Nov 27, 2026
The branch was rebased onto master (752015c), which dropped its
three merges of master. Those merges held the conflict resolutions and
the regenerated lock files and converter output, and the conflicts of
the replayed commits were resolved in favour of the replayed commit. So
the commits below this one are not expected to build on this base.

This commit restores what the merges held and adds what master's 94
commits since need. Its tree is the tree of a merge of the same master
into the branch as it was before the rebase, and that tree was checked:
gn_to_bazel's tests (301) and --check, check_build_configs.sh,
check_generated_bazel_files.sh, bazel_ci_test.py (23),
engine_build_configs (84), bazel_tools (46), buildifier,
tools/gn_test.py (7), ci/pylint.sh, ci/format.sh (its Python step
through yapf directly), the analyzer over dev/bots and flutter_tools,
dev/bots' tests (51) and the tool test files the branch touches (391
tests); Bazel analysis of ci_host_debug, of host_release_test, of
//:tool_tests //:dart_tests, and of every Linux build under its own
configuration (47). Nothing was compiled or run under Bazel on it.

In it:
- deps.lock.bzl for master's DEPS (the Skia, Dart and ICU rolls) and
  pub.lock.bzl for its pubspec.lock; the converter's output:
  builds.json, configs.bazelrc, ci/builders/BUILD.bazel and six
  generated BUILD.bazel files, lib/gpu's and shell/platform/darwin/ios's
  among them for the sources master added.
- What the merges had ported: flutter#196282 (a Mac's
  impeller_unittests without the Vulkan variants, and
  --use-glfw-swiftshader in linux_host_engine_test.json) in
  bazel_mapping.dart, its test and wrapped_gn_builds.md.
- New with this base: two calls in the tool tests the branch added get
  the arguments flutter#196572 made required
  (isLocalEngineBuilder for Cache, featureFlags for
  FlutterTesterDevice). The merge was clean as text; the analyzer found
  them.
- Upstream's side of hunks both sides had changed: dev/bots
  (run_command.dart, utils.dart and run_command_test.dart, after
  flutter#196479), and the tool's test/runner.dart without the
  559 lines flutter#196123 removed, which the replay of the
  branch's own change to that file had put back.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop CICD Run CI/CD platform-ios iOS applications specifically platform-linux Building on or for Linux specifically platform-macos Building on or for macOS specifically platform-windows Building on or for Windows specifically team-android Owned by Android platform team team-ios Owned by iOS platform team team-linux Owned by the Linux platform team team-macos Owned by the macOS platform team team-windows Owned by the Windows 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.

2 participants