Skip to content

[flutter_tools] Replace TargetPlatform.simpleName with cpuArch - #196264

Merged
auto-submit[bot] merged 17 commits into
flutter:masterfrom
bkonyi:ft-ext-target-platform-cpu-arch
Nov 13, 2026
Merged

auto-submit[bot] merged 17 commits into
flutter:masterfrom
bkonyi:ft-ext-target-platform-cpu-arch

Conversation

@bkonyi

@bkonyi bkonyi commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Replaces the ambiguously named TargetPlatform.simpleName getter with a strongly typed CpuArch get cpuArch getter on TargetPlatform (following up on review feedback from #195841). Updates getLinuxBuildDirectory, getWindowsBuildDirectory, and BuildLinuxCommand to resolve architectures through TargetPlatform.cpuArch and HostPlatform.cpuArch, and throws UnsupportedError on multi-architecture, architecture-independent, or non-native platforms (including removing the legacy TargetPlatform.darwin => 'x64' mapping).

Part of #190755

Pre-launch Checklist

bkonyi added 14 commits October 26, 2026 19:55
…vice to tool extensions

Adds `HostPlatform` and `ArtifactDependency` to `package:flutter_tools_core`, `ArtifactService` to `package:flutter_tools_extension`, and `LinuxArtifactService` to `package:flutter_tools_extension_linux_prototype` so tool extensions can declare custom artifact dependencies over the extension protocol.

Part of flutter#190755
Part of flutter#190754
…_test

Remove the redundant `package:flutter_tools/src/base/os.dart` import in `extension_device_test.dart` after merging `origin/master`, as `HostPlatform` is re-exported by `package:flutter_tools_core/flutter_tools_core.dart`.
…fact-service

# Conflicts:
#	packages/flutter_tools/test/general.shard/extension_protocol/extension_device_test.dart
Re-exports `HostPlatform` from `package:flutter_tools_core/flutter_tools_core.dart` in `packages/flutter_tools/lib/src/base/os.dart` instead of declaring a `typedef`, avoiding `ambiguous_import` conflicts when importing both `os.dart` and `flutter_tools_core.dart`.
…fact-service

Adds the `artifact` service to the Linux prototype's `config.yaml` and to the `extension_discovery_test.dart` fixture as required by the manifest services check from flutter#194590, and fixes the `'artifacts'` namespace in the `ExtensionPackageConfig` docs.
…tform by osName and cpuArch

Moves CpuArch to package:flutter_tools_core as an extensible @immutable final class (re-exported from build_info.dart) and updates HostPlatform to be defined by osName and cpuArch, exposing cpuArchName, cliName, and name getters while validating single-segment lowercase alphanumeric OS and architecture identifiers. Replaces CpuArch.fromHostPlatform call sites with HostPlatform.cpuArch.

Part of flutter#190755
Part of flutter#190754
…arch

# Conflicts:
#	packages/flutter_tools/lib/src/build_info.dart
#	packages/flutter_tools/lib/src/experimental/extension_manager.dart
#	packages/flutter_tools/packages/flutter_tools_core/lib/src/artifacts.dart
#	packages/flutter_tools/packages/flutter_tools_core/test/artifacts_test.dart
#	packages/flutter_tools/packages/flutter_tools_extension/lib/src/artifacts.dart
#	packages/flutter_tools/packages/flutter_tools_extension_linux_prototype/lib/src/artifact.dart
#	packages/flutter_tools/packages/flutter_tools_extension_linux_prototype/test/linux_artifact_test.dart
#	packages/flutter_tools/test/commands.shard/hermetic/tool_extensions_build_test.dart
#	packages/flutter_tools/test/general.shard/build_info_test.dart
#	packages/flutter_tools/test/general.shard/extension_protocol/artifact_service_test.dart
Replaces the ambiguously named `TargetPlatform.simpleName` getter with a strongly typed `CpuArch get cpuArch` getter on `TargetPlatform`.

Updates `getLinuxBuildDirectory`, `getWindowsBuildDirectory`, and `BuildLinuxCommand` to resolve architectures through `TargetPlatform.cpuArch` and `HostPlatform.cpuArch`. `TargetPlatform.cpuArch` covers all architecture-specific targets and throws `UnsupportedError` for multi-architecture, architecture-independent, or non-native platforms (removing the legacy `TargetPlatform.darwin` mapping to `'x64'`).

Part of flutter#190755
@bkonyi bkonyi added the CICD Run CI/CD label Nov 10, 2026
@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 Nov 10, 2026
Updates `CpuArchExtension` (`dartName`, `darwinArchName`, and `androidPlatformName`) to derive architecture and platform names from `CpuArch.name` and `TargetPlatform.getName()` rather than duplicating string literals.

Deduplicates `CpuArch` and `HostPlatform` single-segment identifier validation into a shared `_validIdentifierRegExp` in `artifacts.dart`.

Part of flutter#190755
Part of flutter#190754
@bkonyi
bkonyi marked this pull request as ready for review November 13, 2026 19:30
@bkonyi
bkonyi requested review from a team as code owners November 13, 2026 19:30
@bkonyi
bkonyi requested review from jesswrd and removed request for a team November 13, 2026 19:30
@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 team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-windows Owned by the Windows platform team labels Nov 13, 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 CpuArch from an enum to an immutable final class in flutter_tools_core to support custom CPU architectures, and updates HostPlatform to reference CpuArch directly. It also refactors related platform and architecture resolution logic across the codebase and expands test coverage. The review feedback suggests improving error messages in several files by interpolating cpuArch.name (or this.name) instead of the CpuArch object itself to avoid printing the class prefix.

I am having trouble creating individual review comments. Click here to see my feedback.

packages/flutter_tools/lib/src/android/android_device.dart (540)

medium

Using $cpuArch directly in the error message will invoke its toString() method, which produces 'CpuArch.unknown' or 'CpuArch.riscv64'. It is cleaner and more user-friendly to print cpuArch.name instead (e.g., 'unknown' or 'riscv64').

        _logger.printError('Unsupported Android CPU architecture: ${cpuArch.name}');

packages/flutter_tools/lib/src/isolated/native_assets/android/native_assets.dart (55)

medium

Using $cpuArch directly in the error message will invoke its toString() method, which produces 'CpuArch.unknown'. It is cleaner and more user-friendly to print cpuArch.name instead.

    _ => throwToolExit('Invalid Android arch: ${cpuArch.name}.'),

packages/flutter_tools/lib/src/isolated/native_assets/ios/native_assets.dart (31)

medium

Using $cpuArch directly in the error message will invoke its toString() method, which produces 'CpuArch.unknown'. It is cleaner and more user-friendly to print cpuArch.name instead.

    _ => throw Exception('Unknown iOS CPU arch: ${cpuArch.name}.'),

packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart (23)

medium

Using $cpuArch directly in the error message will invoke its toString() method, which produces 'CpuArch.unknown'. It is cleaner and more user-friendly to print cpuArch.name instead.

    _ => throw Exception('Unknown macOS CPU arch: ${cpuArch.name}.'),

packages/flutter_tools/lib/src/build_info.dart (593)

medium

Using $this directly in the error message will invoke its toString() method, which produces 'CpuArch.unknown'. It is cleaner and more user-friendly to print this.name instead.

    _ => throw UnsupportedError('Unexpected CPU arch ${this.name}'),

@bkonyi
bkonyi requested review from chingjun and loic-sharma and removed request for jesswrd November 13, 2026 19:33

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning this up! 💙

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 13, 2026
Merged via the queue into flutter:master with commit 0c6b0fd Nov 13, 2026
22 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 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-linux Owned by the Linux 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