Skip to content

Make FlutterCommand.toolContext non-nullable and remove globals from command runner - #195551

Merged
auto-submit[bot] merged 204 commits into
flutter:masterfrom
bkonyi:di/30a-non-nullable-command-tool-context
Nov 4, 2026
Merged

auto-submit[bot] merged 204 commits into
flutter:masterfrom
bkonyi:di/30a-non-nullable-command-tool-context

Conversation

@bkonyi

@bkonyi bkonyi commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Makes FlutterCommand.toolContext non-nullable (required this.toolContext) across all FlutterCommand subclasses and wires runner-level dependencies (DeviceManager, Doctor, AndroidContext, CocoaPods, PlistParser, and TemplateRenderer) through FlutterCommandRunner and FlutterCommand, removing globals.dart imports from flutter_command.dart and flutter_command_runner.dart.

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.
…-command-tool-context

# Conflicts:
#	packages/flutter_tools/lib/executable.dart
#	packages/flutter_tools/lib/src/commands/channel.dart
#	packages/flutter_tools/lib/src/commands/create_base.dart
#	packages/flutter_tools/lib/src/commands/downgrade.dart
#	packages/flutter_tools/lib/src/commands/ide_config.dart
#	packages/flutter_tools/lib/src/commands/packages.dart
#	packages/flutter_tools/lib/src/commands/upgrade.dart
#	packages/flutter_tools/lib/src/flutter_application_package.dart
#	packages/flutter_tools/lib/src/globals.dart
#	packages/flutter_tools/lib/src/runner/flutter_command.dart
#	packages/flutter_tools/test/commands.shard/permeable/create_test.dart
#	packages/flutter_tools/test/general.shard/ios/mac_test.dart
#	packages/flutter_tools/test/src/test_flutter_command_runner.dart
@bkonyi
bkonyi marked this pull request as ready for review November 3, 2026 17:08
@bkonyi
bkonyi requested review from a team as code owners November 3, 2026 17:08

@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 dependency injection in FlutterCommand and its subclasses by making toolContext a required, non-nullable field and removing redundant overrides. It also updates FlutterCommandRunner to explicitly manage and expose key dependencies instead of relying on global variables. Feedback on the changes highlights a potential null-assertion crash when accessing runner!.templateRenderer! in FlutterCommand, suggesting a safer fallback to MustacheTemplateRenderer.

@github-actions github-actions Bot removed 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 labels Nov 3, 2026
chingjun
chingjun previously approved these changes Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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