Skip to content

[flutter_tools] Remove last remaining context.get calls in lib/ - #197253

Merged
auto-submit[bot] merged 247 commits into
flutter:masterfrom
bkonyi:di/33a-remove-last-context-get
Nov 25, 2026
Merged

auto-submit[bot] merged 247 commits into
flutter:masterfrom
bkonyi:di/33a-remove-last-context-get

Conversation

@bkonyi

@bkonyi bkonyi commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Removes all four remaining context.get<T>() lookups in packages/flutter_tools/lib/ and replaces them with explicit dependency injection.

Compare against parent branch (di/remove-test-without-context): bkonyi/flutter@di/remove-test-without-context...di/33a-remove-last-context-get

Summary

  • lib/src/vmservice.dart: inject optional @visibleForTesting WebSocketConnector? webSocketConnector into connectToVmService, createVmServiceDelegate, and _defaultOpenChannel, and inline _connect into connectToVmService.
  • lib/src/resident_runner.dart, lib/src/test/integration_test_device.dart, lib/src/test/flutter_platform.dart: inject VMServiceConnector (defaulting to connectToVmService) via constructor parameters.
  • lib/src/compile.dart, lib/src/resident_runner.dart, lib/src/test/web_test_compiler.dart: remove top-level residentCompilerFactory getter and call const ResidentCompilerFactory().create(...) directly.
  • lib/src/runner/flutter_command.dart: remove unused FlutterCommand.current getter and the redundant context.run wrapper in FlutterCommand.run.
  • Migrate vmservice_test.dart, flutter_platform_test.dart, and integration_test_device_test.dart from testUsingContext to test, and update the two VMServiceConnector sites in resident_runner_test.dart.

Verification

  • dart format --set-exit-if-changed: 0 changed
  • dart analyze --fatal-infos packages/flutter_tools/lib packages/flutter_tools/test: 0 issues
  • test/general.shard/vmservice_test.dart: +42 passed
  • test/general.shard/flutter_platform_test.dart: +13 passed
  • test/general.shard/integration_test_device_test.dart: +10 passed
  • test/general.shard/resident_runner_test.dart: +64 passed
  • test/general.shard/runner/flutter_command_test.dart: +93 passed
  • test/general.shard/runner/runner_test.dart: +24 passed

Part of #47161

bkonyi added 30 commits October 1, 2026 04:25
… project

Inject dependencies into FlutterApplicationMigration, buildMacOS, and XcodeBasedProject (IosProject and MacOSProject) to remove direct globals.dart usages.
Updates buildXcodeProject in packages/flutter_tools/lib/src/ios/mac.dart to require ToolContext along with explicit Apple dependencies instead of accepting individual ToolContext fields with fallback instantiations.

Also restores running SwiftPackageManagerIntegrationMigration unconditionally when building via IOSDevice and IOSSimulator.
…ix FlutterProject.fromDirectoryTest logger fallback
# Conflicts:
#	packages/flutter_tools/test/commands.shard/hermetic/update_packages_test.dart
…and-simulators

# Conflicts:
#	packages/flutter_tools/test/commands.shard/hermetic/update_packages_test.dart
# Conflicts:
#	packages/flutter_tools/test/commands.shard/hermetic/update_packages_test.dart
# Conflicts:
#	packages/flutter_tools/lib/src/context/tool_dependencies.dart
…ication packages

Eliminates ambient `globals` usage in `ios/application_package.dart`, `macos/application_package.dart`, `windows/application_package.dart`, and `flutter_application_package.dart` by injecting `FileSystem`, `Logger`, `OperatingSystemUtils`, `Platform`, and `PlistParser` explicitly.
…devices

Migrates buildLinux, buildWindows, DesktopDevice, and CustomDevice away from globals.dart to explicit dependency injection via ToolContext.

Part of flutter#188471
Eliminates ambient `globals` usage from `packages/flutter_tools/lib/src/build_info.dart` by requiring explicit `Config`, `FileSystem`, `OperatingSystemUtils`, and `Platform` parameters across `getCurrentHostPlatform` and the build directory helper functions. The unreachable unsupported-host fallback in `getCurrentHostPlatform` no longer logs a warning.
…thout-context

# Conflicts:
#	packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart
…thout-context

# Conflicts:
#	packages/flutter_tools/AGENTS.md
#	packages/flutter_tools/README.md
#	packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart
#	packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart
#	packages/flutter_tools/test/general.shard/compile_batch_test.dart
#	packages/flutter_tools/test/general.shard/compile_incremental_test.dart
#	packages/flutter_tools/test/src/common.dart
…emove-last-context-get

# Conflicts:
#	packages/flutter_tools/AGENTS.md
#	packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart
#	packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart
#	packages/flutter_tools/test/general.shard/compile_batch_test.dart
#	packages/flutter_tools/test/general.shard/compile_incremental_test.dart
#	packages/flutter_tools/test/general.shard/context_runner_test.dart
#	packages/flutter_tools/test/integration.shard/forbidden_imports_test.dart
@bkonyi
bkonyi marked this pull request as ready for review November 24, 2026 22:43
@bkonyi
bkonyi requested a review from chingjun November 24, 2026 22:43
@bkonyi
bkonyi requested review from a team as code owners November 24, 2026 22:43
@bkonyi
bkonyi requested review from mboetger and removed request for a team November 24, 2026 22:43

@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 replaces testWithoutContext with the standard test function across the codebase and updates the test analyzer. It also removes Zone-based AppContext lookups for ResidentCompilerFactory, WebSocketConnector, VMServiceConnector, and FlutterCommand.current, opting instead to inject these dependencies. The reviewer identified critical compilation errors in IntegrationTestTestDevice, FlutterPlatform, and FlutterDevice where initializing private fields directly in named constructor parameters makes the parameter names private and inaccessible.

Comment on lines 32 to 36
required super.toolContext,
required this.userIdentifier,
this.ddsShutdownTimeout = const Duration(seconds: 5),
this._vmServiceConnector = connectToVmService,
});

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.

critical

Using a private field initializer this._vmServiceConnector in a constructor with named parameters makes the parameter name private (_vmServiceConnector). This prevents it from being accessed from other files (such as flutter_platform.dart) and causes a compilation error when trying to pass it as vmServiceConnector.

To fix this, define a public named parameter vmServiceConnector in the constructor and initialize the private field _vmServiceConnector in the initializer list.

Suggested change
required super.toolContext,
required this.userIdentifier,
this.ddsShutdownTimeout = const Duration(seconds: 5),
this._vmServiceConnector = connectToVmService,
});
required super.toolContext,
required this.userIdentifier,
this.ddsShutdownTimeout = const Duration(seconds: 5),
VMServiceConnector vmServiceConnector = connectToVmService,
}) : _vmServiceConnector = vmServiceConnector;

Comment on lines 324 to 329
this.testAssetDirectory,
this.testTimeRecorder,
this.updateGoldens,
@visibleForTesting this._vmServiceConnector = connectToVmService,
this.watcher,
}) {

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.

critical

Using a private field initializer this._vmServiceConnector in a constructor with named parameters makes the parameter name private (_vmServiceConnector). This prevents it from being accessed from other files (such as tests) and causes a compilation error when trying to pass it as vmServiceConnector.

To fix this, define a public named parameter vmServiceConnector in the constructor and initialize the private field _vmServiceConnector in the initializer list.

Suggested change
this.testAssetDirectory,
this.testTimeRecorder,
this.updateGoldens,
@visibleForTesting this._vmServiceConnector = connectToVmService,
this.watcher,
}) {
this.testAssetDirectory,
this.testTimeRecorder,
this.updateGoldens,
this.watcher,
@visibleForTesting VMServiceConnector vmServiceConnector = connectToVmService,
}) : _vmServiceConnector = vmServiceConnector {

Comment on lines 61 to 65
required this.targetPlatform,
@visibleForTesting this.logFlushDelay = const Duration(milliseconds: 500),
this.userIdentifier,
@visibleForTesting this._vmServiceConnector = connectToVmService,
});

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.

critical

Using a private field initializer this._vmServiceConnector in a constructor with named parameters makes the parameter name private (_vmServiceConnector). This prevents it from being accessed from other files (such as tests) and causes a compilation error when trying to pass it as vmServiceConnector.

To fix this, define a public named parameter vmServiceConnector in the constructor and initialize the private field _vmServiceConnector in the initializer list.

Suggested change
required this.targetPlatform,
@visibleForTesting this.logFlushDelay = const Duration(milliseconds: 500),
this.userIdentifier,
@visibleForTesting this._vmServiceConnector = connectToVmService,
});
required this.targetPlatform,
@visibleForTesting this.logFlushDelay = const Duration(milliseconds: 500),
this.userIdentifier,
@visibleForTesting VMServiceConnector vmServiceConnector = connectToVmService,
}) : _vmServiceConnector = vmServiceConnector;

chingjun
chingjun previously approved these changes Nov 25, 2026
…thout-context

# Conflicts:
#	packages/flutter_tools/test/general.shard/base/logger_test.dart
#	packages/flutter_tools/test/general.shard/device_test.dart
#	packages/flutter_tools/test/general.shard/flutter_validator_test.dart
#	packages/flutter_tools/test/general.shard/isolated/native_assets_test.dart
#	packages/flutter_tools/test/general.shard/web/web_asset_server_test.dart
…thout-context

# Conflicts:
#	packages/flutter_tools/test/general.shard/build_system/depfile_test.dart
#	packages/flutter_tools/test/general.shard/build_system/targets/extension_test.dart
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 25, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 25, 2026
Merged via the queue into flutter:master with commit ccba1f2 Nov 25, 2026
21 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 25, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 26, 2026
Roll Flutter from 06f1c24345a2 to 82ec4242da79 (33 revisions)

flutter/flutter@06f1c24...82ec424

2026-11-26 [email protected] Roll Dart SDK from 7663c79b8a29 to 7fcaf46b0308 (1 revision) (flutter/flutter#197465)
2026-11-26 [email protected] Roll Skia from 8bf5f2e2b358 to cef5963c1bb2 (1 revision) (flutter/flutter#197453)
2026-11-26 [email protected] Roll Dart SDK from 771539f4435a to 7663c79b8a29 (2 revisions) (flutter/flutter#197451)
2026-11-26 [email protected] Roll Skia from 535259fe7750 to 8bf5f2e2b358 (1 revision) (flutter/flutter#197449)
2026-11-26 [email protected] Roll Skia from f20b7f274ec8 to 535259fe7750 (4 revisions) (flutter/flutter#197442)
2026-11-26 [email protected] Roll Fuchsia Test Scripts from 56keLr8vaDtnH6vqW... to d5xIJpr0Hxkwjlpnr... (flutter/flutter#197441)
2026-11-26 [email protected] Roll Skia from 168ddb88c5b6 to f20b7f274ec8 (1 revision) (flutter/flutter#197438)
2026-11-26 [email protected] Roll Dart SDK from dcfa4247aa49 to 771539f4435a (1 revision) (flutter/flutter#197431)
2026-11-26 [email protected] Roll Skia from 67badb88843a to 168ddb88c5b6 (1 revision) (flutter/flutter#197430)
2026-11-26 [email protected] iOS: Pass composition order NSArray instead of std::vector (flutter/flutter#197418)
2026-11-26 [email protected] Migrate function type define to use the dart style define (flutter/flutter#197419)
2026-11-26 [email protected] iOS: Submit platform view frames from IOSExternalViewEmbedder (flutter/flutter#197411)
2026-11-26 [email protected] Roll Skia from fc1230e8afbb to 67badb88843a (1 revision) (flutter/flutter#197422)
2026-11-25 [email protected] Roll Fuchsia Linux SDK from HtAKfFLbfAQ6g96RY... to 0bgCrr76CM4IqPO0v... (flutter/flutter#197415)
2026-11-25 [email protected] Roll Dart SDK from 6155a47022d7 to dcfa4247aa49 (2 revisions) (flutter/flutter#197413)
2026-11-25 [email protected] Roll Skia from c2d40fc8f6b3 to fc1230e8afbb (2 revisions) (flutter/flutter#197407)
2026-11-25 [email protected] [flutter_tools] Add ProjectExtensionFinder and ExtensionKernelCompiler (flutter/flutter#194772)
2026-11-25 [email protected] [flutter_tools] Migrate resident runner, hot/cold, and TestBed tests off testUsingContext (flutter/flutter#197256)
2026-11-25 [email protected] [flutter_tools] Migrate create, packages, upgrade, runner, and args tests off testUsingContext (flutter/flutter#197255)
2026-11-25 [email protected] [flutter_tools] Migrate Darwin platform and build command tests off testUsingContext (flutter/flutter#197254)
2026-11-25 [email protected] [flutter_tools] Migrate Android, desktop, and web build tests off testUsingContext (flutter/flutter#197252)
2026-11-25 [email protected] iOS: Move platform view frame state to IOSExternalViewEmbedder (flutter/flutter#197362)
2026-11-25 [email protected] [flutter_tools] Migrate build target and native assets tests off testUsingContext (flutter/flutter#197246)
2026-11-25 [email protected] [flutter_tools] Migrate hermetic command tests off testUsingContext (flutter/flutter#197250)
2026-11-25 [email protected] [flutter_tools] Migrate widget preview, asset, plugin, compiler, and device tests off testUsingContext (flutter/flutter#197257)
2026-11-25 [email protected] Roll Skia from e84ecd98d9f2 to c2d40fc8f6b3 (2 revisions) (flutter/flutter#197398)
2026-11-25 [email protected] Roll Fuchsia Test Scripts from GPtykFNizlaauBqzs... to 56keLr8vaDtnH6vqW... (flutter/flutter#197382)
2026-11-25 [email protected] [flutter_tools] Remove last remaining context.get calls in lib/ (flutter/flutter#197253)
2026-11-25 [email protected] [Impeller] Subtract global pass position from backdrop filter local-to-pass transform (flutter/flutter#197324)
2026-11-25 [email protected] [Impeller] Skip mipmaps for decoded images that are resized on the GPU (flutter/flutter#197013)
2026-11-25 [email protected] [flutter_tools] Remove testWithoutContext in favor of test (flutter/flutter#197259)
2026-11-25 [email protected] Roll Packages from f455dfa to 105a874 (10 revisions) (flutter/flutter#197386)
2026-11-25 [email protected] Roll Dart SDK from 5202130a51b8 to 6155a47022d7 (1 revision) (flutter/flutter#197384)

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:
...
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 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