66library ;
77
88import 'package:flutter_tools_core/flutter_tools_core.dart' as tools_core;
9+ import 'package:flutter_tools_core/flutter_tools_core.dart' show CpuArch;
910import 'package:meta/meta.dart' ;
1011
1112import 'package:package_config/package_config_types.dart' ;
@@ -20,6 +21,8 @@ import 'context/tool_context.dart';
2021import 'convert.dart' ;
2122import 'darwin/darwin.dart' ;
2223
24+ export 'package:flutter_tools_core/flutter_tools_core.dart' show CpuArch;
25+
2326/// Whether icon font subsetting is enabled by default.
2427const kIconTreeShakerEnabledDefault = true ;
2528
@@ -576,84 +579,48 @@ bool isEmulatorBuildMode(BuildMode mode) {
576579 return mode == BuildMode .debug;
577580}
578581
579- /// Platform-agnostic CPU architecture type.
580- enum CpuArch {
581- /// Unknown architecture. Used when the architecture is not relevant.
582- unknown,
583- armv7,
584- arm64,
585- x86,
586- x64,
587- riscv64;
588-
589- factory CpuArch .fromName (String name) {
590- return switch (name) {
591- 'unknown' => .unknown,
592- 'armv7' => .armv7,
593- 'arm64' => .arm64,
594- 'x86' => .x86,
595- 'x64' || 'x86_64' => .x64,
596- 'riscv64' => .riscv64,
597- _ => throw Exception ('Unsupported CPU arch name "$name "' ),
598- };
599- }
600-
601- /// The [CpuArch] of the given [hostPlatform] .
602- factory CpuArch .fromHostPlatform (HostPlatform hostPlatform) {
603- return switch (hostPlatform) {
604- .darwin_x64 || .linux_x64 || .windows_x64 => .x64,
605- .darwin_arm64 || .linux_arm64 || .windows_arm64 => .arm64,
606- .linux_riscv64 => .riscv64,
607- _ => CpuArch .fromName (hostPlatform.platformName),
608- };
609- }
610-
582+ /// Platform-specific naming helpers on [CpuArch] for built-in Flutter tool
583+ /// targets.
584+ extension CpuArchExtension on CpuArch {
611585 /// Returns the Dart SDK's name for the specified target architecture.
612586 ///
613587 /// When building for Darwin platforms, the tool invokes architecture-specific
614588 /// variants of `gen_snapshot` , one for each target architecture. The output
615589 /// instructions are then built into architecture-specific binaries, which are
616590 /// merged into a universal binary using the `lipo` tool.
617- String get dartName {
618- return switch (this ) {
619- armv7 => 'armv7' ,
620- arm64 => 'arm64' ,
621- x86 => 'x86' ,
622- x64 => 'x64' ,
623- riscv64 => 'riscv64' ,
624- unknown => throw UnsupportedError ('Unexpected CPU arch $this ' ),
625- };
626- }
591+ String get dartName => switch (this ) {
592+ .armv7 || .arm64 || .x86 || .x64 || .riscv64 => name,
593+ _ => throw UnsupportedError ('Unexpected CPU arch $this ' ),
594+ };
627595
628596 /// The Apple architecture name for this architecture.
629597 ///
630598 /// This is the name understood by the Darwin toolchain (e.g. `lipo` , `clang` ,
631599 /// and the `-arch` flag) and used for architecture-specific build output
632- /// directories on iOS and macOS. This differs from [dartName] for [x64] ,
633- /// which maps to `x86_64` here.
600+ /// directories on iOS and macOS. This differs from [dartName] for
601+ /// [CpuArch.x64] , which maps to `x86_64` here.
634602 String get darwinArchName => switch (this ) {
635- armv7 => 'armv7' ,
636- arm64 => 'arm64' ,
637- x64 => 'x86_64' ,
638- x86 || riscv64 || unknown => throw UnsupportedError ('Unexpected Darwin CPU arch $this ' ),
603+ .armv7 || .arm64 => name,
604+ .x64 => 'x86_64' ,
605+ _ => throw UnsupportedError ('Unexpected Darwin CPU arch $this ' ),
639606 };
640607
641608 /// The name of the Android ABI (as used in `jniLibs` directories) for this
642609 /// architecture.
643610 String get androidArchName => switch (this ) {
644- armv7 => 'armeabi-v7a' ,
645- arm64 => 'arm64-v8a' ,
646- x64 => 'x86_64' ,
647- x86 || riscv64 || unknown => throw UnsupportedError ('Unexpected Android CPU arch $this ' ),
611+ . armv7 => 'armeabi-v7a' ,
612+ . arm64 => 'arm64-v8a' ,
613+ . x64 => 'x86_64' ,
614+ _ => throw UnsupportedError ('Unexpected Android CPU arch $this ' ),
648615 };
649616
650617 /// The `TargetPlatform` name of the Android platform for this architecture.
651618 String get androidPlatformName => switch (this ) {
652- armv7 => 'android-arm' ,
653- arm64 => 'android-arm64' ,
654- x64 => 'android-x64' ,
655- x86 || riscv64 || unknown => throw UnsupportedError ('Unexpected Android CPU arch $this ' ),
656- };
619+ . armv7 => TargetPlatform .android_arm ,
620+ . arm64 => TargetPlatform .android_arm64 ,
621+ . x64 => TargetPlatform .android_x64 ,
622+ _ => throw UnsupportedError ('Unexpected Android CPU arch $this ' ),
623+ }. getName () ;
657624}
658625
659626/// The operating system (or runtime environment) that a [TargetPlatform]
@@ -958,7 +925,7 @@ String getLinuxBuildDirectory(
958925 null => getCurrentHostPlatform (
959926 operatingSystemUtils: operatingSystemUtils,
960927 platform: platform,
961- ).platformName ,
928+ ).cpuArchName ,
962929 };
963930 final String subDirs = fileSystem.path.joinAll (< String > [
964931 'linux' ,
0 commit comments