Repository navigation
[flutter_tools] Replace TargetPlatform.simpleName with cpuArch - #196264
Conversation
…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
…n ArtifactDependency
…_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
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
There was a problem hiding this comment.
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)
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)
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)
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)
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)
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}'),
loic-sharma
left a comment
There was a problem hiding this comment.
Thanks for cleaning this up! 💙
Replaces the ambiguously named
TargetPlatform.simpleNamegetter with a strongly typedCpuArch get cpuArchgetter onTargetPlatform(following up on review feedback from #195841). UpdatesgetLinuxBuildDirectory,getWindowsBuildDirectory, andBuildLinuxCommandto resolve architectures throughTargetPlatform.cpuArchandHostPlatform.cpuArch, and throwsUnsupportedErroron multi-architecture, architecture-independent, or non-native platforms (including removing the legacyTargetPlatform.darwin => 'x64'mapping).Part of #190755
Pre-launch Checklist
///).