Skip to content

[flutter_tools] Eliminate globals.dart from project.dart - #194066

Merged
auto-submit[bot] merged 60 commits into
flutter:masterfrom
bkonyi:di/29b-2-project
Nov 3, 2026
Merged

auto-submit[bot] merged 60 commits into
flutter:masterfrom
bkonyi:di/29b-2-project

Conversation

@bkonyi

@bkonyi bkonyi commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Eliminates ambient globals.dart usage from packages/flutter_tools/lib/src/project.dart by injecting dependencies via ToolContext into FlutterProjectFactory, FlutterProject, AndroidProject, and WebProject.

Part of #47161

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

bkonyi added 3 commits October 9, 2026 01:43
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.
Inject dependencies (Analytics, CocoaPods, Config, FeatureFlags, FileSystem, FileSystemUtils, FlutterVersion, Logger, OperatingSystemUtils, Platform, ProcessUtils, SystemClock, TemplateRenderer) explicitly into flutter_plugins.dart functions instead of reading from globals.dart.
Removes the `globals.dart` import from `packages/flutter_tools/lib/src/project.dart` by injecting `Config`, `FileSystem`, `Logger`, `TemplateRenderer`, and related dependencies explicitly into `FlutterProjectFactory`, `FlutterProject`, `AndroidProject`, and `WebProject`.
@bkonyi
bkonyi requested review from a team as code owners October 9, 2026 08:45
@bkonyi bkonyi added the CICD Run CI/CD label Oct 9, 2026
@bkonyi
bkonyi requested review from a team as code owners October 9, 2026 08:45
@bkonyi
bkonyi requested review from gmackall and removed request for a team October 9, 2026 08:45
@github-actions github-actions Bot added platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels. 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 Oct 9, 2026

@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 pass dependencies like FileSystem, Logger, TemplateRenderer, and Config to various commands, devices, and project-related classes, reducing reliance on global variables. A review comment identifies a potential regression in FlutterProject.current and fromDirectory where the custom build directory configuration is ignored because the Config instance is not propagated, and provides a code suggestion to resolve this issue.

@bkonyi
bkonyi marked this pull request as draft October 9, 2026 16:46
@flutter-dashboard

Copy link
Copy Markdown

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

# Conflicts:
#	packages/flutter_tools/lib/src/linux/application_package.dart
#	packages/flutter_tools/lib/src/test/runner.dart
…ugins

# Conflicts:
#	packages/flutter_tools/bin/fuchsia_tester.dart
# Conflicts:
#	packages/flutter_tools/lib/src/build_info.dart
@github-actions github-actions Bot removed platform-windows Building on or for Windows specifically platform-linux Building on or for Linux specifically labels Oct 28, 2026

@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 codebase to explicitly pass dependencies such as FileSystem, Logger, Config, and ProcessManager to FlutterProject instantiation methods and factories, reducing reliance on global variables. The review feedback suggests optimizing performance in build targets by instantiating FlutterProject once and reusing the instance instead of repeatedly recreating it or calling FlutterProject.fromDirectory inside loops.

Comment on lines 413 to 419
Future<void> build(Environment environment) async {
_components ??=
FlutterProject.fromDirectory(environment.projectDir).manifest.deferredComponents ??
FlutterProject.fromDirectory(
environment.projectDir,
logger: environment.logger,
).manifest.deferredComponents ??
<DeferredComponent>[];

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

To avoid redundant disk I/O and parsing of the project manifest, we can instantiate the FlutterProject once at the beginning of the build method and reuse it throughout the method.

Suggested change
Future<void> build(Environment environment) async {
_components ??=
FlutterProject.fromDirectory(environment.projectDir).manifest.deferredComponents ??
FlutterProject.fromDirectory(
environment.projectDir,
logger: environment.logger,
).manifest.deferredComponents ??
<DeferredComponent>[];
Future<void> build(Environment environment) async {
final FlutterProject project = FlutterProject.fromDirectory(
environment.projectDir,
logger: environment.logger,
);
_components ??= project.manifest.deferredComponents ??
<DeferredComponent>[];

Comment on lines +433 to +436
FlutterProject.fromDirectory(
environment.projectDir,
logger: environment.logger,
).buildDirectory,

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

Reuse the project instance created at the beginning of the build method to avoid recreating and re-parsing the FlutterProject.

Suggested change
FlutterProject.fromDirectory(
environment.projectDir,
logger: environment.logger,
).buildDirectory,
project.buildDirectory,

Comment on lines +212 to +217
final Directory componentOutputDir =
FlutterProject.fromDirectory(environment.projectDir, logger: environment.logger)
.buildDirectory
.childDirectory(componentEntries.key)
.childDirectory('intermediates')
.childDirectory('flutter');

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

Since this is inside a map loop over deferredComponentsEntries, calling FlutterProject.fromDirectory here will read and parse the project manifest repeatedly for every deferred component. To improve efficiency, consider instantiating the FlutterProject once outside of the map loop and reusing it inside the callback.

chingjun
chingjun previously approved these changes Oct 28, 2026
bkonyi added a commit to bkonyi/flutter that referenced this pull request Oct 28, 2026
# Conflicts:
#	packages/flutter_tools/lib/src/macos/macos_device.dart
#	packages/flutter_tools/lib/src/project.dart
#	packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart
#	packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart
#	packages/flutter_tools/test/commands.shard/permeable/create_test.dart
#	packages/flutter_tools/test/general.shard/macos/macos_project_migration_test.dart
#	packages/flutter_tools/test/general.shard/project_test.dart
@github-actions github-actions Bot removed the platform-macos Building on or for macOS specifically label Oct 29, 2026
chingjun
chingjun previously approved these changes Oct 29, 2026
@bkonyi
bkonyi dismissed stale reviews from chingjun via c15f675 October 30, 2026 16:15
@bkonyi
bkonyi requested a review from chingjun October 30, 2026 16:17
chingjun
chingjun previously approved these changes Oct 30, 2026
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 3, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 3, 2026
Merged via the queue into flutter:master with commit 6c7f2c3 Nov 3, 2026
22 of 23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 3, 2026
JadeCong pushed a commit to CloudEngineHub/flutter that referenced this pull request Nov 3, 2026
…ges to ToolContext (flutter#190797)

Completes the elimination of `runInContext` and ambient `AppContext`
lookups across `flutter_tools` by migrating remaining commands, runners,
and toolchain classes to explicit `ToolContext` dependency injection.

Stacked on flutter#194066 (`di/29b-2-project`).
Fork diff:
bkonyi/flutter@di/29b-2-project...di/26-context-elimination

Part of flutter#47161

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 3, 2026
Roll Flutter from fcfb4f203eae to 934720261be0 (38 revisions)

flutter/flutter@fcfb4f2...9347202

2026-11-03 [email protected] Roll Skia from 5bceaa033999 to c733ad3e37cb (5 revisions) (flutter/flutter#195872)
2026-11-03 [email protected] Roll Skia from 34d2bf479385 to 5bceaa033999 (9 revisions) (flutter/flutter#195864)
2026-11-03 [email protected] fix: prefer pointer events over semantics tap for mouse clicks on web (flutter/flutter#191529)
2026-11-03 [email protected] [VPAT] Expose a semantics text field value while it is not being edited (flutter/flutter#195445)
2026-11-03 [email protected] [Impeller] Make a GL context current before constructing an AiksContext without a surface (flutter/flutter#195629)
2026-11-03 [email protected] [flutter_tools] Eliminate globals.dart from project.dart (flutter/flutter#194066)
2026-11-03 [email protected] [tool] Complete context runner elimination and migrate AppContext usages to ToolContext (flutter/flutter#190797)
2026-11-03 [email protected] [web] Unify font collections between CanvasKit and Skwasm (flutter/flutter#195539)
2026-11-03 [email protected] [Android] Replay predictive back state for retained engines (flutter/flutter#192286)
2026-11-03 [email protected] [vulkan]: Adds depth/stencil synchronization for subpasses (flutter/flutter#195689)
2026-11-03 [email protected] [web] Honor requested upscaling in instantiateImageCodecWithSize and ImageDescriptor.instantiateCodec (flutter/flutter#195836)
2026-11-03 [email protected] Roll Skia from 866b61ca92c9 to 34d2bf479385 (9 revisions) (flutter/flutter#195848)
2026-11-03 [email protected] Roll Fuchsia Test Scripts from xl1LWBuppzu-BnOzV... to B6zarykZp6PKWRueg... (flutter/flutter#195847)
2026-11-03 [email protected] Remove unused ffi (flutter/flutter#195710)
2026-11-02 [email protected] Revert: [Android] Let the raster thread use every core of a chip without little cores (flutter/flutter#195838)
2026-11-02 [email protected] Run 10 impeller iOS benchmarks as one devicelab task (flutter/flutter#195661)
2026-11-02 [email protected] Use named uniforms instead of setFloat in StretchEffect (flutter/flutter#195372)
2026-11-02 [email protected] [flutter_tools] Report when the browser disconnects during a web test run (flutter/flutter#192198)
2026-11-02 [email protected] fix: Resolve memory leak in image_list example (flutter/flutter#189526)
2026-11-02 [email protected] Only run the common local engine configurations in presubmit (flutter/flutter#195688)
2026-11-02 [email protected] Update gcloud_version to version [email protected] (flutter/flutter#195769)
2026-11-02 [email protected] [Impeller] Order the Vulkan copy-texture-to-texture layout transition after the copy (flutter/flutter#195814)
2026-11-02 [email protected] [Impeller] Order the Vulkan ResizeTexture layout transition after its blit (flutter/flutter#195721)
2026-11-02 [email protected] [web] Fix CanvasKit fragment shader uniforms being freed or mutated after recording (flutter/flutter#195718)
2026-11-02 [email protected] Roll Fuchsia Linux SDK from MqypI6RNyVZ_FLUE-... to T_-6-6X1lDMghhAvX... (flutter/flutter#195809)
2026-11-02 [email protected] [Android] Log why Impeller falls back to OpenGLES (flutter/flutter#194764)
2026-11-02 [email protected] Roll Skia from 3f35fb6e591b to 866b61ca92c9 (11 revisions) (flutter/flutter#195802)
2026-11-02 [email protected] Roll Skia from 3f35fb6e591b to 866b61ca92c9 (11 revisions) (flutter/flutter#195802)
2026-11-02 [email protected] Only run the common local engine configurations in presubmit (flutter/flutter#195688)
2026-11-02 [email protected] Balance tool_integration_tests subshards by expected duration (flutter/flutter#195628)
2026-11-02 [email protected] [web_paragraph] Map code units without a cluster to a cluster (flutter/flutter#195384)
2026-11-02 [email protected] [web] Hide synthetic autofill inputs from assistive technology (flutter/flutter#195618)
2026-11-02 [email protected] Roll Packages from 3742a4e to 3f34a6f (8 revisions) (flutter/flutter#195795)
2026-11-02 [email protected] [web] Unskip web tests that pass on CanvasKit and Skwasm: platform_view_test, route_notification_messages_test (flutter/flutter#195605)
2026-11-02 [email protected] Roll Skia from e5ad3868b8db to 3f35fb6e591b (1 revision) (flutter/flutter#195789)
2026-11-02 [email protected] Roll Skia from f5215e74aa16 to e5ad3868b8db (3 revisions) (flutter/flutter#195779)
2026-11-02 [email protected] Roll Skia from e43478a2f9f8 to f5215e74aa16 (1 revision) (flutter/flutter#195776)
2026-11-01 [email protected] Roll Fuchsia Linux SDK from kW0A0xxNkqf38ljm4... to MqypI6RNyVZ_FLUE-... (flutter/flutter#195768)

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

a: desktop Running on desktop CICD Run CI/CD platform-ios iOS applications 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