Repository navigation
[tool] Wire dependency injection into runner and executable with required non-nullable contexts - #190922
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors dependency injection in flutter_tools by introducing AndroidContext, AppleContext, ToolContext, and ToolDependencies to manage and bootstrap tool dependencies instead of relying on global variables. Feedback on these changes highlights opportunities to improve testability and efficiency, such as using the shared finalShutdownHooks for the file system, utilizing finalSystemClock.now() for the terminal, preferring injected analytics over global analytics, avoiding a potential null pointer crash with DevtoolsLauncher.instance, and optimizing path traversal in _gatherProjectPaths by using fs.path.basename.
cf41bc2 to
cb1f566
Compare
cb1f566 to
5533bb8
Compare
flutter#190724) ## Summary Part 1 of the modular dependency injection migration. Defines the foundational modular dependency injection containers and bootstrapper for `flutter_tools`: 1. **`ToolContext`**: Layer 1 OS wrappers (`HostEnvironment`) and Layer 2 SDK state (`ToolConfiguration`). 2. **Nullable Sub-contexts**: `AndroidContext` and `AppleContext` for clean platform isolation. 3. **`ToolDependencies`**: Topologically instantiates and manages the dependency graph at startup with explicit overrides and lazy closures. 4. **Hermetic Test Doubles**: Includes `dependency_injection_test.dart` and fake context doubles. Followed by Part 2 (flutter#190922) for runner wiring. Part of flutter#47161
# Conflicts: # packages/flutter_tools/lib/src/context/tool_dependencies.dart # packages/flutter_tools/test/general.shard/context/dependency_injection_test.dart
… globals fallback
…ctly in FlutterCommandRunner
…ool_dependencies.dart
…stFlutterCommandRunner to NoOpAnalytics
…tion at bootstrap
# Conflicts: # packages/flutter_tools/lib/executable.dart
|
hey @bkonyi, this seemed to have regressed this benchmark about 1s. I just wanted to let you know so you can determine if thats a fair tradeoff. |
This PR is constructing In particular, Tasks like macOS app compilation are seeing increased latency because they now create an |
Yikes, I'm surprised we're doing blocking IO in a constructor like that. I'll send a couple of PRs out to lazily run the initialization when we actually go to access the state instead of when we create the object. |
Summary
Part 2 of the modular dependency injection migration (stacked on #190724).
Wires explicit dependency injection into the Flutter tool entrypoints:
ToolDependencies.bootstrapintorunner.dartto initialize dependencies at startup.FlutterCommandRunnerto accept non-nullabletoolContext,androidContext,appleContext, andtoolDependencies.executable.dartto forwardToolDependenciesintogenerateCommands.test_flutter_command_runner.dartand hermetic test doubles.Part of #47161