Skip to content

Commit e9f9585

Browse files
authored
feat: add support for saving ft.link in the supplemental zip (#79)
Also cleaned up the code we use to create this zip file
1 parent 1c2e57f commit e9f9585

File tree

4 files changed

+47
-32
lines changed

4 files changed

+47
-32
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'package:process/process.dart';
77
import '../artifacts.dart';
88
import '../build_info.dart';
99
import '../macos/xcode.dart';
10-
1110
import 'file_system.dart';
1211
import 'logger.dart';
1312
import 'process.dart';
@@ -134,13 +133,16 @@ class AOTSnapshotter {
134133
// Shorebird dumps the class table information during snapshot compilation which is later used during linking.
135134
'--print_class_table_link_debug_info_to=${_fileSystem.path.join(outputDir.parent.path, 'App.class_table.json')}',
136135
'--print_class_table_link_info_to=${_fileSystem.path.join(outputDir.parent.path, 'App.ct.link')}',
136+
'--print_field_table_link_debug_info_to=${_fileSystem.path.join(outputDir.parent.path, 'App.field_table.json')}',
137+
'--print_field_table_link_info_to=${_fileSystem.path.join(outputDir.parent.path, 'App.ft.link')}',
137138
];
138139

139140
final List<String> genSnapshotArgs = <String>[
140141
// Shorebird uses --deterministic to improve snapshot stability and increase linking.
141142
'--deterministic',
142143
// Only use the default Shorebird gen_snapshot args on iOS.
143-
if (platform == TargetPlatform.ios || platform == TargetPlatform.darwin) ...dumpClassTableLinkInfoArgs,
144+
if (platform == TargetPlatform.ios || platform == TargetPlatform.darwin)
145+
...dumpClassTableLinkInfoArgs,
144146
];
145147

146148
final bool targetingApplePlatform =

packages/flutter_tools/lib/src/build_system/targets/common.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,36 @@ abstract final class Lipo {
457457
}
458458
}
459459
}
460+
461+
/// For managing the supplementary linking files for Shorebird.
462+
abstract final class LinkSupplement {
463+
static Future<void> create(
464+
Environment environment, {
465+
required String inputBuildDir,
466+
required String outputBuildDir,
467+
}) async {
468+
// If the shorebird directory exists, delete it first.
469+
final Directory shorebirdDir = environment.fileSystem.directory(
470+
environment.fileSystem.path.join(outputBuildDir, 'shorebird'),
471+
);
472+
if (shorebirdDir.existsSync()) {
473+
shorebirdDir.deleteSync(recursive: true);
474+
}
475+
476+
void maybeCopy(String name) {
477+
final File file = environment.fileSystem.file(
478+
environment.fileSystem.path.join(inputBuildDir, name),
479+
);
480+
if (file.existsSync()) {
481+
file.copySync(environment.fileSystem.path.join(shorebirdDir.path, name));
482+
}
483+
}
484+
485+
// Copy the link information (generated by gen_snapshot)
486+
// into the shorebird directory.
487+
maybeCopy('App.ct.link');
488+
maybeCopy('App.class_table.json');
489+
maybeCopy('App.ft.link');
490+
maybeCopy('App.field_table.json');
491+
}
492+
}

packages/flutter_tools/lib/src/build_system/targets/ios.dart

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,11 @@ abstract class AotAssemblyBase extends Target {
140140
skipMissingInputs: true,
141141
);
142142

143-
// If the shorebird directory exists, delete it first.
144-
final Directory shorebirdDir = environment.fileSystem.directory(environment.fileSystem.path.join(getIosBuildDirectory(), 'shorebird'));
145-
if (shorebirdDir.existsSync()) {
146-
shorebirdDir.deleteSync(recursive: true);
147-
}
148-
149-
// Copy the class table link information (generated by gen_snapshot) from the buildOutputPath to the iOS build directory.
150-
final File classTableLink = environment.fileSystem.file(environment.fileSystem.path.join(buildOutputPath, 'App.ct.link'));
151-
final File classTableLinkDebug = environment.fileSystem.file(environment.fileSystem.path.join(buildOutputPath, 'App.class_table.json'));
152-
if (classTableLink.existsSync()) {
153-
classTableLink.copySync(environment.fileSystem.path.join(shorebirdDir.path, 'App.ct.link'));
154-
}
155-
if (classTableLinkDebug.existsSync()) {
156-
classTableLinkDebug.copySync(environment.fileSystem.path.join(shorebirdDir.path, 'App.class_table.json'));
157-
}
143+
await LinkSupplement.create(
144+
environment,
145+
inputBuildDir: getIosBuildDirectory(),
146+
outputBuildDir: buildOutputPath,
147+
);
158148
}
159149
}
160150

packages/flutter_tools/lib/src/build_system/targets/macos.dart

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -403,21 +403,11 @@ class CompileMacOSFramework extends Target {
403403
skipMissingInputs: true,
404404
);
405405

406-
// If the shorebird directory exists, delete it first.
407-
final Directory shorebirdDir = environment.fileSystem.directory(environment.fileSystem.path.join(getMacOSBuildDirectory(), 'shorebird'));
408-
if (shorebirdDir.existsSync()) {
409-
shorebirdDir.deleteSync(recursive: true);
410-
}
411-
412-
// Copy the class table link information (generated by gen_snapshot) from the buildOutputPath to the macos build directory.
413-
final File classTableLink = environment.fileSystem.file(environment.fileSystem.path.join(buildOutputPath, 'App.ct.link'));
414-
final File classTableLinkDebug = environment.fileSystem.file(environment.fileSystem.path.join(buildOutputPath, 'App.class_table.json'));
415-
if (classTableLink.existsSync()) {
416-
classTableLink.copySync(environment.fileSystem.path.join(shorebirdDir.path, 'App.ct.link'));
417-
}
418-
if (classTableLinkDebug.existsSync()) {
419-
classTableLinkDebug.copySync(environment.fileSystem.path.join(shorebirdDir.path, 'App.class_table.json'));
420-
}
406+
await LinkSupplement.create(
407+
environment,
408+
inputBuildDir: getMacOSBuildDirectory(),
409+
outputBuildDir: buildOutputPath,
410+
);
421411
}
422412

423413
@override

0 commit comments

Comments
 (0)