Skip to content

Commit c219bf7

Browse files
authored
[tools] Make SnapshotType.platform non-nullable (#146958)
When performing artifact lookups for `Artifact.genSnapshot` for macOS desktop builds, a `TargetPlatform` is used to determine the name of the tool, typically `gen_snapshot_$TARGET_ARCH`. Formerly, this tool was always named `gen_snapshot`. The astute reader may ask "but Chris, didn't we support TWO target architectures on iOS and therefore need TWO `gen_snapshot` binaries?" Yes, we did support both armv7 and arm64 target architectures on iOS. But no, we didn't initially have two `gen_snapshot` binaries. We did *build* two `gen_snapshots`: * A 32-bit x86 binary that emitted armv7 AOT code * A 64-bit x64 binary that emitted arm64 AOT code At the time, the bitness of the `gen_snapshot` tool needed to match the bitness of the target architecture, and to avoid having to do a lot of work plumbing through suffixed `gen_snapshot` names, the author of that work (who, as evidenced by this patch, is still paying for his code crimes) elected to "cleverly" lipo the two together into a single multi-architecture macOS binary still named `gen_snapshot`. See: flutter/engine#4948 This was later remediated over the course of several patches, including: * flutter/engine#10430 * flutter/engine#22818 * flutter/flutter#37445 However, there were still cases (notably `--local-engine` workflows in the tool) where we weren't computing the target platform and thus referenced the generic `gen_snapshot` tool. See: flutter/flutter#38933 Fixed in: flutter/engine#28345 The test removed in this PR, which ensured that null `SnapshotType.platform` was supported was introduced in flutter/flutter#11924 as a followup to flutter/flutter#11820 when the snapshotting logic was originally extracted to the `GenSnapshot` class, and most invocations still passed a null target platform. Since there are no longer any cases where `TargetPlatform` isn't passed when looking up `Artifact.genSnapshot`, we can safely make the platform non-nullable and remove the test. This is pre-factoring towards the removal of the generic `gen_snapshot` artifact from the macOS host binaries (which are currently unused since we never pass a null `TargetPlatform`), which is pre-factoring towards the goal of building `gen_snapshot` binaries with an arm64 host architecture, and eliminate the need to use Rosetta during iOS and macOS Flutter builds. Part of: flutter/flutter#101138 Umbrella issue: flutter/flutter#103386 Umbrella issue: flutter/flutter#69157 No new tests since the behaviour is enforced by the compiler.
1 parent b25f909 commit c219bf7

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

packages/flutter_tools/lib/src/artifacts.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class CachedArtifacts implements Artifacts {
578578
case TargetPlatform.linux_arm64:
579579
case TargetPlatform.windows_x64:
580580
case TargetPlatform.windows_arm64:
581-
return _getDesktopArtifactPath(artifact, platform, mode);
581+
return _getDesktopArtifactPath(artifact, platform!, mode);
582582
case TargetPlatform.fuchsia_arm64:
583583
case TargetPlatform.fuchsia_x64:
584584
return _getFuchsiaArtifactPath(artifact, platform!, mode!);
@@ -594,18 +594,18 @@ class CachedArtifacts implements Artifacts {
594594
return _fileSystem.path.basename(_getEngineArtifactsPath(platform, mode)!);
595595
}
596596

597-
String _getDesktopArtifactPath(Artifact artifact, TargetPlatform? platform, BuildMode? mode) {
597+
String _getDesktopArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode? mode) {
598598
// When platform is null, a generic host platform artifact is being requested
599599
// and not the gen_snapshot for darwin as a target platform.
600-
if (platform != null && artifact == Artifact.genSnapshot) {
600+
if (artifact == Artifact.genSnapshot) {
601601
final String engineDir = _getEngineArtifactsPath(platform, mode)!;
602602
return _fileSystem.path.join(engineDir, _artifactToFileName(artifact, _platform));
603603
}
604-
if (platform != null && artifact == Artifact.flutterMacOSFramework) {
604+
if (artifact == Artifact.flutterMacOSFramework) {
605605
final String engineDir = _getEngineArtifactsPath(platform, mode)!;
606606
return _getMacOSEngineArtifactPath(engineDir, _fileSystem, _platform);
607607
}
608-
return _getHostArtifactPath(artifact, platform ?? _currentHostPlatform(_platform, _operatingSystemUtils), mode);
608+
return _getHostArtifactPath(artifact, platform, mode);
609609
}
610610

611611
String _getAndroidArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {

packages/flutter_tools/lib/src/base/build.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'process.dart';
1616
class SnapshotType {
1717
SnapshotType(this.platform, this.mode);
1818

19-
final TargetPlatform? platform;
19+
final TargetPlatform platform;
2020
final BuildMode mode;
2121

2222
@override

packages/flutter_tools/test/general.shard/base/build_test.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ const List<String> kDefaultClang = <String>[
4949
];
5050

5151
void main() {
52-
group('SnapshotType', () {
53-
test('does not throw, if target platform is null', () {
54-
expect(() => SnapshotType(null, BuildMode.release), returnsNormally);
55-
});
56-
});
57-
5852
group('GenSnapshot', () {
5953
late GenSnapshot genSnapshot;
6054
late Artifacts artifacts;

0 commit comments

Comments
 (0)