@@ -197,35 +197,16 @@ enum HostArtifact {
197197
198198// TODO(knopp): Remove once darwin artifacts are universal and moved out of darwin-x64
199199String _enginePlatformDirectoryName (TargetPlatform platform) {
200- if (platform == TargetPlatform .darwin ) {
200+ if (platform.type == .macos ) {
201201 return 'darwin-x64' ;
202202 }
203- return platform.getName ();
204- }
205-
206- // Remove android target platform type.
207- TargetPlatform ? _mapTargetPlatform (TargetPlatform ? targetPlatform) {
208- switch (targetPlatform) {
209- case TargetPlatform .android:
210- return TargetPlatform .android_arm64;
211- case TargetPlatform .ios:
212- case TargetPlatform .darwin:
213- case TargetPlatform .linux_x64:
214- case TargetPlatform .linux_arm64:
215- case TargetPlatform .linux_riscv64:
216- case TargetPlatform .windows_x64:
217- case TargetPlatform .windows_arm64:
218- case TargetPlatform .fuchsia_arm64:
219- case TargetPlatform .fuchsia_x64:
220- case TargetPlatform .tester:
221- case TargetPlatform .web_javascript:
222- case TargetPlatform .android_arm:
223- case TargetPlatform .android_arm64:
224- case TargetPlatform .android_x64:
225- case TargetPlatform .unsupported:
226- case null :
227- return targetPlatform;
203+ // iOS engine artifacts live in a single `ios` directory regardless of the
204+ // target architecture, so the arch-qualified name from [getName] is not used
205+ // here.
206+ if (platform.type == .ios) {
207+ return 'ios' ;
228208 }
209+ return platform.getName ();
229210}
230211
231212class EngineBuildPaths {
@@ -421,35 +402,34 @@ class CachedArtifacts implements Artifacts {
421402 BuildMode ? mode,
422403 EnvironmentType ? environmentType,
423404 }) {
424- platform = _mapTargetPlatform (platform);
425- switch (platform) {
426- case TargetPlatform .android:
427- case TargetPlatform .android_arm:
428- case TargetPlatform .android_arm64:
429- case TargetPlatform .android_x64:
430- assert (platform != TargetPlatform .android);
431- return _getAndroidArtifactPath (artifact, platform! , mode! );
432- case TargetPlatform .ios:
405+ switch (platform? .type) {
406+ case .android:
407+ // A generic Android target has an unknown CPU architecture (e.g. the
408+ // architecture-independent patched SDK requested when compiling the
409+ // app's Dart kernel). Default to arm64 in that case, matching the
410+ // historical behavior of the removed `_mapTargetPlatform` helper.
411+ final TargetPlatform androidPlatform = platform! .cpuArch == .unknown
412+ ? const TargetPlatform (.android, .arm64)
413+ : platform;
414+ return _getAndroidArtifactPath (artifact, androidPlatform, mode! );
415+ case .ios:
433416 return _getIosArtifactPath (artifact, platform! , mode, environmentType);
434- case TargetPlatform .darwin:
435- case TargetPlatform .linux_x64:
436- case TargetPlatform .linux_arm64:
437- case TargetPlatform .linux_riscv64:
438- case TargetPlatform .windows_x64:
439- case TargetPlatform .windows_arm64:
417+ case .macos:
418+ case .linux:
419+ case .windows:
440420 return _getDesktopArtifactPath (artifact, platform! , mode);
441- case TargetPlatform .fuchsia_arm64:
442- case TargetPlatform .fuchsia_x64:
421+ case .fuchsia:
443422 return _getFuchsiaArtifactPath (artifact, platform! , mode! );
444- case TargetPlatform .tester:
445- case TargetPlatform .web_javascript:
423+ case .tester:
424+ case .web:
425+ case .custom:
446426 case null :
447427 return _getHostArtifactPath (
448428 artifact,
449429 platform ?? _currentHostPlatform (_platform, _operatingSystemUtils),
450430 mode,
451431 );
452- case TargetPlatform .unsupported:
432+ case .unsupported:
453433 TargetPlatform .throwUnsupportedTarget ();
454434 }
455435 }
@@ -677,7 +657,11 @@ class CachedArtifacts implements Artifacts {
677657 case Artifact .genSnapshotX64:
678658 // For script snapshots any gen_snapshot binary will do. Returning gen_snapshot for
679659 // android_arm in profile mode because it is available on all supported host platforms.
680- return _getAndroidArtifactPath (artifact, TargetPlatform .android_arm, BuildMode .profile);
660+ return _getAndroidArtifactPath (
661+ artifact,
662+ const TargetPlatform (.android, .armv7),
663+ BuildMode .profile,
664+ );
681665 case Artifact .frontendServerSnapshotForEngineDartSdk:
682666 return _fileSystem.path.join (
683667 _dartSdkPath (_cache),
@@ -785,13 +769,10 @@ class CachedArtifacts implements Artifacts {
785769 String ? _getEngineArtifactsPath (TargetPlatform platform, [BuildMode ? mode]) {
786770 final String engineDir = _cache.getArtifactDirectory ('engine' ).path;
787771 final String platformName = _enginePlatformDirectoryName (platform);
788- switch (platform) {
789- case TargetPlatform .linux_x64:
790- case TargetPlatform .linux_arm64:
791- case TargetPlatform .linux_riscv64:
792- case TargetPlatform .darwin:
793- case TargetPlatform .windows_x64:
794- case TargetPlatform .windows_arm64:
772+ switch (platform.type) {
773+ case .linux:
774+ case .macos:
775+ case .windows:
795776 // TODO(zanderso): remove once debug desktop artifacts are uploaded
796777 // under a separate directory from the host artifacts.
797778 // https://github.com/flutter/flutter/issues/38935
@@ -800,23 +781,25 @@ class CachedArtifacts implements Artifacts {
800781 }
801782 final suffix = mode != BuildMode .debug ? '-${kebabCase (mode .cliName )}' : '' ;
802783 return _fileSystem.path.join (engineDir, platformName + suffix);
803- case TargetPlatform .fuchsia_arm64:
804- case TargetPlatform .fuchsia_x64:
805- case TargetPlatform .tester:
806- case TargetPlatform .web_javascript:
784+ case .fuchsia:
785+ case .tester:
786+ case .web:
807787 assert (mode == null , 'Platform $platform does not support different build modes.' );
808788 return _fileSystem.path.join (engineDir, platformName);
809- case TargetPlatform .ios:
810- case TargetPlatform .android_arm:
811- case TargetPlatform .android_arm64:
812- case TargetPlatform .android_x64:
789+ case .ios:
790+ assert (mode != null , 'Need to specify a build mode for platform $platform .' );
791+ final suffix = mode != BuildMode .debug ? '-${kebabCase (mode !.cliName )}' : '' ;
792+ return _fileSystem.path.join (engineDir, platformName + suffix);
793+ case .android:
794+ assert (
795+ platform.cpuArch != .unknown,
796+ 'cannot use a generic Android platform to look up artifacts' ,
797+ );
813798 assert (mode != null , 'Need to specify a build mode for platform $platform .' );
814799 final suffix = mode != BuildMode .debug ? '-${kebabCase (mode !.cliName )}' : '' ;
815800 return _fileSystem.path.join (engineDir, platformName + suffix);
816- case TargetPlatform .android:
817- assert (false , 'cannot use TargetPlatform.android to look up artifacts' );
818- return null ;
819- case TargetPlatform .unsupported:
801+ case .custom:
802+ case .unsupported:
820803 TargetPlatform .throwUnsupportedTarget ();
821804 }
822805 }
@@ -826,20 +809,15 @@ class CachedArtifacts implements Artifacts {
826809}
827810
828811TargetPlatform _currentHostPlatform (Platform platform, OperatingSystemUtils operatingSystemUtils) {
812+ final cpuArch = CpuArch .fromHostPlatform (operatingSystemUtils.hostPlatform);
829813 if (platform.isMacOS) {
830- return TargetPlatform .darwin ;
814+ return TargetPlatform (.macos, cpuArch) ;
831815 }
832816 if (platform.isLinux) {
833- return switch (operatingSystemUtils.hostPlatform) {
834- HostPlatform .linux_x64 => TargetPlatform .linux_x64,
835- HostPlatform .linux_riscv64 => TargetPlatform .linux_riscv64,
836- _ => TargetPlatform .linux_arm64,
837- };
817+ return TargetPlatform (.linux, cpuArch);
838818 }
839819 if (platform.isWindows) {
840- return operatingSystemUtils.hostPlatform == HostPlatform .windows_arm64
841- ? TargetPlatform .windows_arm64
842- : TargetPlatform .windows_x64;
820+ return TargetPlatform (.windows, cpuArch);
843821 }
844822 throw UnimplementedError ('Host OS not supported.' );
845823}
@@ -1061,7 +1039,6 @@ class CachedLocalEngineArtifacts implements Artifacts {
10611039 EnvironmentType ? environmentType,
10621040 }) {
10631041 platform ?? = _currentHostPlatform (_platform, _operatingSystemUtils);
1064- platform = _mapTargetPlatform (platform);
10651042 final isDirectoryArtifact = artifact == Artifact .flutterPatchedSdkPath;
10661043 final String ? artifactFileName = isDirectoryArtifact
10671044 ? null
@@ -1073,7 +1050,7 @@ class CachedLocalEngineArtifacts implements Artifacts {
10731050 case Artifact .genSnapshotX64:
10741051 return _genSnapshotPath (artifact);
10751052 case Artifact .flutterTester:
1076- return _flutterTesterPath (platform! );
1053+ return _flutterTesterPath (platform);
10771054 case Artifact .isolateSnapshotData:
10781055 case Artifact .vmSnapshotData:
10791056 return _fileSystem.path.join (
@@ -1089,7 +1066,7 @@ class CachedLocalEngineArtifacts implements Artifacts {
10891066 case Artifact .flutterMacOSXcframework:
10901067 return _fileSystem.path.join (localEngineInfo.targetOutPath, artifactFileName);
10911068 case Artifact .platformKernelDill:
1092- if (platform == TargetPlatform .fuchsia_x64 || platform == TargetPlatform .fuchsia_arm64 ) {
1069+ if (platform.type == .fuchsia ) {
10931070 return _fileSystem.path.join (
10941071 localEngineInfo.targetOutPath,
10951072 'flutter_runner_patched_sdk' ,
@@ -1122,7 +1099,7 @@ class CachedLocalEngineArtifacts implements Artifacts {
11221099 // what was specified in [mode] argument because local engine will
11231100 // have only one flutter_patched_sdk in standard location, that
11241101 // is happen to be what debug(non-release) mode is using.
1125- if (platform == TargetPlatform .fuchsia_x64 || platform == TargetPlatform .fuchsia_arm64 ) {
1102+ if (platform.type == .fuchsia ) {
11261103 return _fileSystem.path.join (localEngineInfo.targetOutPath, 'flutter_runner_patched_sdk' );
11271104 }
11281105 return _getFlutterPatchedSdkPath (BuildMode .debug);
@@ -1260,7 +1237,7 @@ class CachedLocalWebSdkArtifacts implements Artifacts {
12601237 BuildMode ? mode,
12611238 EnvironmentType ? environmentType,
12621239 }) {
1263- if (platform == TargetPlatform .web_javascript ) {
1240+ if (platform? .type == .web ) {
12641241 switch (artifact) {
12651242 case Artifact .engineDartSdkPath:
12661243 return _getDartSdkPath ();
@@ -1467,7 +1444,7 @@ class _TestArtifacts implements Artifacts {
14671444 final buffer = StringBuffer ();
14681445 buffer.write (artifact);
14691446 if (platform != null ) {
1470- buffer.write ('.$platform ' );
1447+ buffer.write ('.${ _enginePlatformDirectoryName ( platform )} ' );
14711448 }
14721449 if (mode != null ) {
14731450 buffer.write ('.$mode ' );
@@ -1576,30 +1553,25 @@ String _getFlutterPrebuiltsPath(String baseOutPath, FileSystem fileSystem) {
15761553
15771554String _getPrebuiltTarget (Platform platform, OperatingSystemUtils operatingSystemUtils) {
15781555 final TargetPlatform hostPlatform = _currentHostPlatform (platform, operatingSystemUtils);
1579- switch (hostPlatform) {
1580- case TargetPlatform .darwin :
1556+ switch (hostPlatform.type ) {
1557+ case .macos :
15811558 return 'macos-x64' ;
1582- case TargetPlatform .linux_riscv64:
1583- return 'linux-riscv64' ;
1584- case TargetPlatform .linux_arm64:
1585- return 'linux-arm64' ;
1586- case TargetPlatform .linux_x64:
1587- return 'linux-x64' ;
1588- case TargetPlatform .windows_x64:
1589- return 'windows-x64' ;
1590- case TargetPlatform .windows_arm64:
1591- return 'windows-arm64' ;
1592- case TargetPlatform .ios:
1593- case TargetPlatform .android:
1594- case TargetPlatform .android_arm:
1595- case TargetPlatform .android_arm64:
1596- case TargetPlatform .android_x64:
1597- case TargetPlatform .fuchsia_arm64:
1598- case TargetPlatform .fuchsia_x64:
1599- case TargetPlatform .web_javascript:
1600- case TargetPlatform .tester:
1559+ case .linux:
1560+ return switch (hostPlatform.cpuArch) {
1561+ .riscv64 => 'linux-riscv64' ,
1562+ .arm64 => 'linux-arm64' ,
1563+ _ => 'linux-x64' ,
1564+ };
1565+ case .windows:
1566+ return hostPlatform.cpuArch == .arm64 ? 'windows-arm64' : 'windows-x64' ;
1567+ case .ios:
1568+ case .android:
1569+ case .fuchsia:
1570+ case .web:
1571+ case .tester:
1572+ case .custom:
16011573 throwToolExit ('Unsupported host platform: $hostPlatform ' );
1602- case TargetPlatform .unsupported:
1574+ case .unsupported:
16031575 TargetPlatform .throwUnsupportedTarget ();
16041576 }
16051577}
0 commit comments