Skip to content

[flutter_tools] Delete globals.dart and context_runner.dart - #196095

Merged
auto-submit[bot] merged 236 commits into
flutter:masterfrom
bkonyi:di/31-remove-globals
Nov 24, 2026
Merged

auto-submit[bot] merged 236 commits into
flutter:masterfrom
bkonyi:di/31-remove-globals

Conversation

@bkonyi

@bkonyi bkonyi commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Deletes lib/src/globals.dart, lib/src/context_runner.dart, test/general.shard/globals_test.dart, and tool/global_count.dart:

  • Moves runInContext to test-only test/src/context_runner.dart (reusing DelegatingToolContext in test/src/fakes.dart) for legacy testUsingContext and TestBed suites, with fallback cycle coverage in test/general.shard/context_runner_test.dart.
  • Migrates the remaining globals.cache tests in test/general.shard/cache_test.dart to test and removes globals.localFileSystem from test/src/common.dart.
  • Updates test/integration.shard/forbidden_imports_test.dart, test/src/context.dart, test/src/testbed.dart, test/commands.shard/permeable/upgrade_test.dart, lib/src/build_system/build_system.dart, README.md, and AGENTS.md.

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.
…e-run-in-context

# Conflicts:
#	packages/flutter_tools/lib/executable.dart
#	packages/flutter_tools/lib/runner.dart
#	packages/flutter_tools/test/general.shard/runner/runner_test.dart
…l-dependencies-bootstrap

# Conflicts:
#	packages/flutter_tools/lib/src/context/android_context.dart
# Conflicts:
#	packages/flutter_tools/lib/runner.dart
… into di/runner-3-tool-dependencies-bootstrap

# Conflicts:
#	packages/flutter_tools/lib/executable.dart
#	packages/flutter_tools/lib/src/context/tool_dependencies.dart
#	packages/flutter_tools/test/general.shard/args_test.dart
#	packages/flutter_tools/test/general.shard/context/dependency_injection_test.dart
#	packages/flutter_tools/test/general.shard/runner/runner_test.dart
#	packages/flutter_tools/test/src/fakes.dart
Resolves merge conflicts onto di/runner-3-tool-dependencies-bootstrap, drops superseded test edits that already landed on master, aligns test/src/context_runner.dart and DelegatingToolContext with current master fallbacks, and migrates cache_test.dart off globals.cache.
@github-actions github-actions Bot removed platform-windows Building on or for Windows specifically a: desktop Running on desktop 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 18, 2026
…ter merge

Removes redundant tests from `forbidden_imports_test.dart` and `context_runner_test.dart`, and passes `featureFlags: TestFeatureFlags()` to `Environment.test` in `localizations_test.dart`.

Part of flutter#47161
@bkonyi
bkonyi marked this pull request as ready for review November 23, 2026 23:15
@bkonyi
bkonyi requested a review from chingjun November 23, 2026 23:15

@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 to remove legacy global variables and context runner fallbacks, moving the fallback context runner to the test directory and updating documentation and tests to promote dependency injection over ambient global singletons. The review feedback advises against caching fallback instances like BotDetector and AnsiTerminal globally across tests in fakes.dart to prevent test pollution and ensure context-specific dependencies are correctly resolved.

Comment on lines +1641 to +1651
LocalFileSystem? _fallbackLocalFileSystemInstance;
BotDetector? _fallbackBotDetector;
AnsiTerminal? _fallbackTerminal;

/// Disposes any fallback host [LocalFileSystem] and resets cached fallbacks on [DelegatingToolContext].
Future<void> disposeFallbackLocalFileSystem() async {
await _fallbackLocalFileSystemInstance?.dispose();
_fallbackLocalFileSystemInstance = null;
_fallbackBotDetector = null;
_fallbackTerminal = 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.

high

Caching _fallbackBotDetector and _fallbackTerminal globally across tests can lead to test pollution and subtle bugs. If a test overrides Platform or Stdio in the AppContext (which is very common), but botDetector or terminal falls back to these cached global instances, they will continue to use the Platform or Stdio instances from whichever test first initialized them.\n\nSince BotDetector and AnsiTerminal are lightweight and cheap to construct, we should avoid caching them globally. We can remove these global variables and simplify disposeFallbackLocalFileSystem.

LocalFileSystem? _fallbackLocalFileSystemInstance;\n\n/// Disposes any fallback host [LocalFileSystem] and resets cached fallbacks on [DelegatingToolContext].\nFuture<void> disposeFallbackLocalFileSystem() async {\n  await _fallbackLocalFileSystemInstance?.dispose();\n  _fallbackLocalFileSystemInstance = null;\n}
References
  1. Check for potential regressions: Look for changes that might break existing functionality or introduce unexpected behavior in related areas. (link)

Comment on lines +1717 to +1720
BotDetector get botDetector =>
_botDetector ??
context.get<BotDetector>() ??
(_fallbackBotDetector ??= BotDetector(platform: platform));

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.

high

Avoid caching BotDetector globally to prevent test pollution when Platform is overridden in the context. Constructing it on demand is extremely cheap and ensures that the correct, context-specific Platform is always used.

  BotDetector get botDetector =>\n      _botDetector ??\n      context.get<BotDetector>() ??\n      BotDetector(platform: platform);
References
  1. Check for potential regressions: Look for changes that might break existing functionality or introduce unexpected behavior in related areas. (link)

Comment on lines +1835 to +1842
AnsiTerminal get terminal =>
_terminal ??
context.get<AnsiTerminal>() ??
(_fallbackTerminal ??= AnsiTerminal(
stdio: stdio,
platform: platform,
shutdownHooks: shutdownHooks,
));

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.

high

Avoid caching AnsiTerminal globally to prevent test pollution when Platform or Stdio is overridden in the context. Constructing it on demand ensures that the correct, context-specific dependencies are always used.

  AnsiTerminal get terminal =>\n      _terminal ??\n      context.get<AnsiTerminal>() ??\n      AnsiTerminal(\n        stdio: stdio,\n        platform: platform,\n        shutdownHooks: shutdownHooks,\n      );
References
  1. Check for potential regressions: Look for changes that might break existing functionality or introduce unexpected behavior in related areas. (link)

@github-actions github-actions Bot removed the team-android Owned by Android platform team label Nov 23, 2026
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 24, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 24, 2026
Merged via the queue into flutter:master with commit be108a1 Nov 24, 2026
22 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 24, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 25, 2026
Roll Flutter from b75c5b30406a to 06f1c24345a2 (37 revisions)

flutter/flutter@b75c5b3...06f1c24

2026-11-25 [email protected] Roll Skia from a60d883b3fe3 to e84ecd98d9f2 (2 revisions) (flutter/flutter#197375)
2026-11-25 [email protected] Roll Skia from ca229e319550 to a60d883b3fe3 (4 revisions) (flutter/flutter#197371)
2026-11-25 [email protected] Roll Skia from 6f75212e5a23 to ca229e319550 (2 revisions) (flutter/flutter#197369)
2026-11-25 [email protected] Roll Skia from 75d95595f14e to 6f75212e5a23 (1 revision) (flutter/flutter#197364)
2026-11-25 [email protected] [Windows] Fix Korean 3-beolsik IME dropping space, digits and punctuation (flutter/flutter#194270)
2026-11-25 [email protected] [flutter_tools] Strip embedded credentials from repository URLs (flutter/flutter#197219)
2026-11-25 [email protected] [flutter_tools] Add structured extension.log notifications for tool extensions (flutter/flutter#196714)
2026-11-25 [email protected] [flutter_tools] Share Depfile in flutter_tools_core and make BuildTarget.targetPlatform optional (flutter/flutter#194965)
2026-11-25 [email protected] Reply null asynchronously to ignored web platform messages and unskip missing-asset tests (flutter/flutter#197267)
2026-11-25 [email protected] Roll Dart SDK from 87f515c52de9 to 5202130a51b8 (1 revision) (flutter/flutter#197363)
2026-11-25 [email protected] [web] Retain queued scene pictures via ContainerLayer render pinning (flutter/flutter#196748)
2026-11-25 [email protected] [flutter_tools] Include dependency manifests in copyAssets depfile (flutter/flutter#196596)
2026-11-25 [email protected] Print the Intel Mac deprecation warning on every command (flutter/flutter#194071)
2026-11-25 [email protected] Roll Skia from 243c0dc9f662 to 75d95595f14e (2 revisions) (flutter/flutter#197351)
2026-11-25 [email protected] iOS: Ignore platform messages after the engine is destroyed (flutter/flutter#197310)
2026-11-24 [email protected] Bump customer tests to pick up material_ui cache extent test updates (flutter/flutter#197266)
2026-11-24 [email protected] [flutter_tools] Use refreshed FlutterVersion for flutter doctor feature flags (flutter/flutter#196944)
2026-11-24 [email protected] [flutter_tools] Do not crash if buildXcodeProject temporary directory is deleted before cleanup (flutter/flutter#195918)
2026-11-24 [email protected] Fix some `parameter_assignments` warnings (flutter/flutter#196815)
2026-11-24 [email protected] [flutter_tools] Extract PlatformDebuggingOptions and move WebDebugConfig (flutter/flutter#197229)
2026-11-24 [email protected] Fix desktop apps installing to the system prefix after a failed build (flutter/flutter#196482)
2026-11-24 [email protected] [flutter_tools] Write flutter test native_assets.json outside targetDir (flutter/flutter#196300)
2026-11-24 [email protected] iOS: Check the presented composition order in platform view tests (flutter/flutter#197302)
2026-11-24 [email protected] Run the shared Vulkan embedder tests under Impeller as well as Skia (flutter/flutter#193004)
2026-11-24 [email protected] Roll Fuchsia Linux SDK from BOgXtIYxLYcCkRou2... to HtAKfFLbfAQ6g96RY... (flutter/flutter#197334)
2026-11-24 [email protected] Roll Skia from b3dec9325fe1 to 243c0dc9f662 (6 revisions) (flutter/flutter#197333)
2026-11-24 [email protected] [flutter_tools] Delete globals.dart and context_runner.dart (flutter/flutter#196095)
2026-11-24 [email protected] Update viewInsets docs for translucent and rounded system UI (flutter/flutter#196355)
2026-11-24 [email protected] [flutter_tools] Check that dartaotruntime can run before starting the frontend server (flutter/flutter#194206)
2026-11-24 [email protected] [framework] Fix DraggableScrollableSheet '_hold == null' assertion when touch lifts during snap (flutter/flutter#195771)
2026-11-24 [email protected] [web] Release ImageSource on GC and fix Picture finalizer cycles (flutter/flutter#197245)
2026-11-24 [email protected] [flutter_tools] Fix web compiler output tracking in web builds (flutter/flutter#196563)
2026-11-24 [email protected] Upgrade CI to Xcode 27.2 (flutter/flutter#196807)
2026-11-24 [email protected] Roll Packages from 5b93485 to f455dfa (6 revisions) (flutter/flutter#197316)
2026-11-24 [email protected] [Linux] Fix deadlock presenting to a Wayland subsurface (flutter/flutter#196945)
2026-11-24 [email protected] Roll Skia from 2140958ee284 to b3dec9325fe1 (1 revision) (flutter/flutter#197309)
2026-11-24 [email protected] Roll Fuchsia Test Scripts from oEU515sDqSTvD8Spx... to GPtykFNizlaauBqzs... (flutter/flutter#197313)

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

...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD 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