Skip to content

[tool] Refactor artifacts.dart to use enhanced enums and reduce duplication#187063

Merged
auto-submit[bot] merged 6 commits into
flutter:masterfrom
bkonyi:refactor-artifacts-enhanced-enums-20260525
May 26, 2026
Merged

[tool] Refactor artifacts.dart to use enhanced enums and reduce duplication#187063
auto-submit[bot] merged 6 commits into
flutter:masterfrom
bkonyi:refactor-artifacts-enhanced-enums-20260525

Conversation

@bkonyi

@bkonyi bkonyi commented May 25, 2026

Copy link
Copy Markdown
Contributor

Refactors Artifact and HostArtifact to enhanced enums, encapsulating filename mapping logic and introducing a .directory() constructor for directory-representing values.

Also simplifies getHostArtifact implementations across different Artifacts classes by delegating non-engine artifacts and consolidating web SDK artifact resolution to a shared helper.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 25, 2026
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label May 25, 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 Artifact and HostArtifact enums in packages/flutter_tools/lib/src/artifacts.dart to store their associated file names and metadata directly within the enum definitions. This allows removing the large, centralized helper functions _artifactToFileName and _hostArtifactToFileName in favor of calling getFileName directly on the enum instances. A review comment suggests refactoring getFileName to throw errors instead of returning null or using assert for invalid states, which would allow changing the return type from String? to String and removing numerous trailing ! null assertions at call sites.

Comment on lines +108 to +121
String? getFileName(Platform hostPlatform, [BuildMode? mode]) {
if (isPatchedSdk) {
assert(false, 'No filename for sdk path, should not be invoked');
return null;
}
if (isFuchsiaRunner) {
assert(mode != null, 'BuildMode is required for fuchsiaFlutterRunner');
final jitOrAot = mode!.isJit ? '_jit' : '_aot';
final productOrNo = mode.isRelease ? '_product' : '';
return 'flutter$jitOrAot${productOrNo}_runner-0.far';
}
final exe = (isExecutable && hostPlatform.isWindows) ? '.exe' : '';
return '$_fileName$exe';
}

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

By throwing a StateError instead of returning null when isPatchedSdk is true, and throwing an ArgumentError instead of using assert when mode is null for isFuchsiaRunner, we can change the return type of getFileName from String? to String.

This makes the API much safer (since assert is ignored in release builds, which could lead to unexpected null pointer exceptions later) and allows us to remove all the trailing ! null assertion operators at the call sites throughout this file (e.g., lines 565, 622, 625, 628, 770, 858, 896, 914, 931, 963, 980, 1066, 1210, 1227).

This simplification aligns with the repository style guide's principles of optimizing for readability and suggesting refactoring to enhance maintainability.

  String getFileName(Platform hostPlatform, [BuildMode? mode]) {
    if (isPatchedSdk) {
      throw StateError('No filename for sdk path, should not be invoked');
    }
    if (isFuchsiaRunner) {
      if (mode == null) {
        throw ArgumentError('BuildMode is required for fuchsiaFlutterRunner');
      }
      final jitOrAot = mode.isJit ? '_jit' : '_aot';
      final productOrNo = mode.isRelease ? '_product' : '';
      return 'flutter$jitOrAot${productOrNo}_runner-0.far';
    }
    final exe = (isExecutable && hostPlatform.isWindows) ? '.exe' : '';
    return '$_fileName$exe';
  }
References
  1. Suggest simplification and refactoring: Assess whether the code can be made simpler or refactored to enhance readability and maintainability. (link)

@github-actions github-actions Bot removed the CICD Run CI/CD label May 25, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 25, 2026
@bkonyi bkonyi requested a review from chingjun May 26, 2026 14:09
@bkonyi bkonyi requested review from a team as code owners May 26, 2026 14:27
@bkonyi bkonyi requested review from reidbaker and removed request for a team May 26, 2026 14:27
@github-actions github-actions Bot added 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 and removed CICD Run CI/CD labels May 26, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 26, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request is not mergeable in its current state, likely because of a merge conflict. Pre-submit CI jobs were not triggered. Pushing a new commit to this branch that resolves the issue will result in pre-submit jobs being scheduled.

bkonyi added 4 commits May 26, 2026 14:29
…cation

Refactors `Artifact` and `HostArtifact` to enhanced enums, encapsulating filename mapping logic and introducing a `.directory()` constructor for directory-representing values.

Also simplifies `getHostArtifact` implementations across different `Artifacts` classes by delegating non-engine artifacts and consolidating web SDK artifact resolution to a shared helper.
Addresses review comment from gemini-code-assist:

- Refactors `Artifact.getFileName` to throw `StateError` or `ArgumentError` instead of returning `null` or using `assert`.

- Changes the return type of `Artifact.getFileName` from `String?` to non-nullable `String`.

- Removes all trailing null assertions (`!`) at call sites of `getFileName`.
Refactors the HostPlatform enum in packages/flutter_tools/lib/src/base/os.dart to an enhanced enum.

Stores cliName and platformName in the constructor, removing getNameForHostPlatform.

TAG=agy

CONV=f3b1231c-cf85-4cdb-a44a-6dbc7369d139
…e getters

TAG=agy

CONV=f3b1231c-cf85-4cdb-a44a-6dbc7369d139
@bkonyi bkonyi force-pushed the refactor-artifacts-enhanced-enums-20260525 branch from aa456ce to eabc55b Compare May 26, 2026 14:31
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
…rgetPlatform

Restores `getNameForHostPlatform`, `getNameForTargetPlatform`, and `getTargetPlatformForName` as deprecated compatibility shims.

This prevents breaking internal Google tools or other plugins that might be importing these private helper APIs, while keeping the main enum designs clean.

Also formats the conflicted test files.
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 26, 2026
- Add flutter_ignore comment to deprecation shims to bypass dev/bots/analyze.dart custom syntax checks.

- Fix CWD check in localizations_utils.dart to support Git worktrees (.git file check).

- Format all modified test files to comply with formatting rules.
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 26, 2026
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label May 26, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue May 26, 2026
Merged via the queue into flutter:master with commit 5a5b546 May 26, 2026
174 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 26, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request May 27, 2026
flutter/flutter@f3a4b98...c8f2f16

2026-05-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Flutter GPU] Add explicit draw counts (#186639)" (flutter/flutter#187170)
2026-05-27 engine-flutter-autoroll@skia.org Roll Dart SDK from 7dcea971af6b to f3db7b7d9801 (2 revisions) (flutter/flutter#187144)
2026-05-27 bdero@google.com [Flutter GPU] Add explicit draw counts (flutter/flutter#186639)
2026-05-27 engine-flutter-autoroll@skia.org Roll Skia from f9db7748563e to fa944af10f91 (1 revision) (flutter/flutter#187139)
2026-05-27 bdero@google.com [Flutter GPU] Flutter GPU ShaderLibrary in-place reload for shader hot reload (flutter/flutter#186793)
2026-05-27 engine-flutter-autoroll@skia.org Roll Skia from a692cbf38952 to f9db7748563e (8 revisions) (flutter/flutter#187135)
2026-05-27 burak.karahan@mail.ru Use local semantics tester in Material button tests (flutter/flutter#186667)
2026-05-27 rmolivares@renzo-olivares.dev Filter out `a: text input` from `team-framework` PR triage  (flutter/flutter#187129)
2026-05-27 bkonyi@google.com [Engine] Fix silent buffer mismatch bug in FML Win32 CommandLineFromPlatform (flutter/flutter#187120)
2026-05-27 srawlins@google.com examples: Remove unused parameters (flutter/flutter#185819)
2026-05-27 116356835+AbdeMohlbi@users.noreply.github.com Remove another `String.valueOf` (flutter/flutter#186628)
2026-05-27 alex.medinsh@gmail.com Print trace when skipping flavor-specific and platform-specific assets (flutter/flutter#187045)
2026-05-26 adilhanney@disroot.org Fix `InteractiveViewer` memory leak from undisposed `CurvedAnimation`s (flutter/flutter#185826)
2026-05-26 meylis@divine.video Fix AccessibilityBridge startup crash on vendor-modified Android (flutter/flutter#184630)
2026-05-26 keertip@users.noreply.github.com Update data driven fixes docs (flutter/flutter#186217)
2026-05-26 ahmedsameha1@gmail.com Add more 0x0 size tests part10 (flutter/flutter#186201)
2026-05-26 46920873+gabrimatic@users.noreply.github.com Disable spell check for obscured text (flutter/flutter#186329)
2026-05-26 chris@bracken.jp [iOS] Migrate VSyncClient and DisplayLinkManager to Swift (flutter/flutter#187001)
2026-05-26 bkonyi@google.com [flutter_tools, devicelab] Add safety filesystem guard to tests (flutter/flutter#186748)
2026-05-26 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from Itd2Jq_ZIABH2rW7B... to k9EizfEGJO4WwQN9-... (flutter/flutter#187115)
2026-05-26 engine-flutter-autoroll@skia.org Roll Dart SDK from 00e625453c43 to 7dcea971af6b (1 revision) (flutter/flutter#187117)
2026-05-26 rmacnak@google.com Remove use of deprecated copy_trees. (flutter/flutter#187091)
2026-05-26 15619084+vashworth@users.noreply.github.com Use resolved implementation plugins with SwiftPM (flutter/flutter#187097)
2026-05-26 engine-flutter-autoroll@skia.org Roll Skia from 27a819894f7c to a692cbf38952 (3 revisions) (flutter/flutter#187109)
2026-05-26 engine-flutter-autoroll@skia.org Roll Packages from 69cf959 to fc795e5 (4 revisions) (flutter/flutter#187114)
2026-05-26 mvincentong@gmail.com Handle simctl process exceptions during discovery (flutter/flutter#186501)
2026-05-26 mvincentong@gmail.com Clarify precache enabled platforms help (flutter/flutter#186878)
2026-05-26 bkonyi@google.com [tool] Refactor artifacts.dart to use enhanced enums and reduce duplication (flutter/flutter#187063)
2026-05-26 jason-simmons@users.noreply.github.com Build script updates for syncing engine sources and building artifacts on linux-arm64 (flutter/flutter#186917)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC boetger@google.com,stuartmorgan@google.com 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

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#11795)

flutter/flutter@f3a4b98...c8f2f16

2026-05-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Flutter GPU] Add explicit draw counts (#186639)" (flutter/flutter#187170)
2026-05-27 engine-flutter-autoroll@skia.org Roll Dart SDK from 7dcea971af6b to f3db7b7d9801 (2 revisions) (flutter/flutter#187144)
2026-05-27 bdero@google.com [Flutter GPU] Add explicit draw counts (flutter/flutter#186639)
2026-05-27 engine-flutter-autoroll@skia.org Roll Skia from f9db7748563e to fa944af10f91 (1 revision) (flutter/flutter#187139)
2026-05-27 bdero@google.com [Flutter GPU] Flutter GPU ShaderLibrary in-place reload for shader hot reload (flutter/flutter#186793)
2026-05-27 engine-flutter-autoroll@skia.org Roll Skia from a692cbf38952 to f9db7748563e (8 revisions) (flutter/flutter#187135)
2026-05-27 burak.karahan@mail.ru Use local semantics tester in Material button tests (flutter/flutter#186667)
2026-05-27 rmolivares@renzo-olivares.dev Filter out `a: text input` from `team-framework` PR triage  (flutter/flutter#187129)
2026-05-27 bkonyi@google.com [Engine] Fix silent buffer mismatch bug in FML Win32 CommandLineFromPlatform (flutter/flutter#187120)
2026-05-27 srawlins@google.com examples: Remove unused parameters (flutter/flutter#185819)
2026-05-27 116356835+AbdeMohlbi@users.noreply.github.com Remove another `String.valueOf` (flutter/flutter#186628)
2026-05-27 alex.medinsh@gmail.com Print trace when skipping flavor-specific and platform-specific assets (flutter/flutter#187045)
2026-05-26 adilhanney@disroot.org Fix `InteractiveViewer` memory leak from undisposed `CurvedAnimation`s (flutter/flutter#185826)
2026-05-26 meylis@divine.video Fix AccessibilityBridge startup crash on vendor-modified Android (flutter/flutter#184630)
2026-05-26 keertip@users.noreply.github.com Update data driven fixes docs (flutter/flutter#186217)
2026-05-26 ahmedsameha1@gmail.com Add more 0x0 size tests part10 (flutter/flutter#186201)
2026-05-26 46920873+gabrimatic@users.noreply.github.com Disable spell check for obscured text (flutter/flutter#186329)
2026-05-26 chris@bracken.jp [iOS] Migrate VSyncClient and DisplayLinkManager to Swift (flutter/flutter#187001)
2026-05-26 bkonyi@google.com [flutter_tools, devicelab] Add safety filesystem guard to tests (flutter/flutter#186748)
2026-05-26 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from Itd2Jq_ZIABH2rW7B... to k9EizfEGJO4WwQN9-... (flutter/flutter#187115)
2026-05-26 engine-flutter-autoroll@skia.org Roll Dart SDK from 00e625453c43 to 7dcea971af6b (1 revision) (flutter/flutter#187117)
2026-05-26 rmacnak@google.com Remove use of deprecated copy_trees. (flutter/flutter#187091)
2026-05-26 15619084+vashworth@users.noreply.github.com Use resolved implementation plugins with SwiftPM (flutter/flutter#187097)
2026-05-26 engine-flutter-autoroll@skia.org Roll Skia from 27a819894f7c to a692cbf38952 (3 revisions) (flutter/flutter#187109)
2026-05-26 engine-flutter-autoroll@skia.org Roll Packages from 69cf959 to fc795e5 (4 revisions) (flutter/flutter#187114)
2026-05-26 mvincentong@gmail.com Handle simctl process exceptions during discovery (flutter/flutter#186501)
2026-05-26 mvincentong@gmail.com Clarify precache enabled platforms help (flutter/flutter#186878)
2026-05-26 bkonyi@google.com [tool] Refactor artifacts.dart to use enhanced enums and reduce duplication (flutter/flutter#187063)
2026-05-26 jason-simmons@users.noreply.github.com Build script updates for syncing engine sources and building artifacts on linux-arm64 (flutter/flutter#186917)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC boetger@google.com,stuartmorgan@google.com 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

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
via-guy pushed a commit to via-guy/flutter that referenced this pull request Jun 26, 2026
…cation (flutter#187063)

Refactors `Artifact` and `HostArtifact` to enhanced enums, encapsulating
filename mapping logic and introducing a `.directory()` constructor for
directory-representing values.

Also simplifies `getHostArtifact` implementations across different
`Artifacts` classes by delegating non-engine artifacts and consolidating
web SDK artifact resolution to a shared helper.
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-linux Building on or for Linux specifically platform-windows Building on or for Windows 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