Skip to content

[flutter_tools] Remove globals usage from artifacts.dart - #193654

Open
bkonyi wants to merge 2 commits into
flutter:masterfrom
bkonyi:di/29a-1-artifacts
Open

bkonyi wants to merge 2 commits into
flutter:masterfrom
bkonyi:di/29a-1-artifacts

Conversation

@bkonyi

@bkonyi bkonyi commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Migrates Artifacts and CachedArtifacts away from globals.dart to explicit dependency injection via ToolContext.

Part of #188471

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.

Eliminates ambient globals.dart usage from packages/flutter_tools/lib/src/artifacts.dart by injecting required dependencies into Artifacts.getLocalEngine, using package:path basename in LocalEngineInfo, and using a local FileSystem instance in _getFileGeneratorsPath.
@bkonyi bkonyi added tool Affects the "flutter" command-line tool. See also t: labels. CICD Run CI/CD labels Oct 1, 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 Artifacts.getLocalEngine to accept explicit dependencies instead of relying on global context, and updates FlutterCommandRunner and associated tests accordingly. Feedback on these changes includes correcting the Dart 3 pattern matching syntax in flutter_command_runner.dart to prevent compilation errors, instantiating LocalFileSystem locally within _getFileGeneratorsPath to avoid top-level side effects, and using platform-agnostic paths in the new unit test to ensure compatibility on Windows.

Comment thread packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
Comment thread packages/flutter_tools/lib/src/artifacts.dart Outdated
Comment thread packages/flutter_tools/test/general.shard/artifacts_test.dart
@bkonyi
bkonyi marked this pull request as draft October 1, 2026 15:23
@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.

…ess review comments

Accepts required ToolContext toolContext in Artifacts.getLocalEngine, moves localFileSystem inside _getFileGeneratorsPath, and uses platform-agnostic paths in artifacts_test.dart.
@bkonyi
bkonyi marked this pull request as ready for review October 2, 2026 16:52

@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 Artifacts.getLocalEngine and related components to accept and use ToolContext directly instead of relying on global variables from globals.dart. It also updates FlutterCommandRunner to destructure _toolContext and pass it down, and updates associated tests to use testWithoutContext with FakeToolContext. Feedback suggests extracting the instantiation of LocalFileSystem in _getFileGeneratorsPath to a top-level private variable to avoid recreating it on every invocation.

Comment thread packages/flutter_tools/lib/src/artifacts.dart
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.

1 participant