diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index 9755fa792d2fa..ccb9e1dcfc724 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -7,7 +7,6 @@ import 'package:process/process.dart'; import '../artifacts.dart'; import '../build_info.dart'; import '../macos/xcode.dart'; - import 'file_system.dart'; import 'logger.dart'; import 'process.dart'; @@ -134,13 +133,16 @@ class AOTSnapshotter { // Shorebird dumps the class table information during snapshot compilation which is later used during linking. '--print_class_table_link_debug_info_to=${_fileSystem.path.join(outputDir.parent.path, 'App.class_table.json')}', '--print_class_table_link_info_to=${_fileSystem.path.join(outputDir.parent.path, 'App.ct.link')}', + '--print_field_table_link_debug_info_to=${_fileSystem.path.join(outputDir.parent.path, 'App.field_table.json')}', + '--print_field_table_link_info_to=${_fileSystem.path.join(outputDir.parent.path, 'App.ft.link')}', ]; final List genSnapshotArgs = [ // Shorebird uses --deterministic to improve snapshot stability and increase linking. '--deterministic', // Only use the default Shorebird gen_snapshot args on iOS. - if (platform == TargetPlatform.ios || platform == TargetPlatform.darwin) ...dumpClassTableLinkInfoArgs, + if (platform == TargetPlatform.ios || platform == TargetPlatform.darwin) + ...dumpClassTableLinkInfoArgs, ]; final bool targetingApplePlatform = diff --git a/packages/flutter_tools/lib/src/build_system/targets/common.dart b/packages/flutter_tools/lib/src/build_system/targets/common.dart index af46950557b22..fa75bff9bc4b7 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/common.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/common.dart @@ -457,3 +457,36 @@ abstract final class Lipo { } } } + +/// For managing the supplementary linking files for Shorebird. +abstract final class LinkSupplement { + static Future create( + Environment environment, { + required String inputBuildDir, + required String outputBuildDir, + }) async { + // If the shorebird directory exists, delete it first. + final Directory shorebirdDir = environment.fileSystem.directory( + environment.fileSystem.path.join(outputBuildDir, 'shorebird'), + ); + if (shorebirdDir.existsSync()) { + shorebirdDir.deleteSync(recursive: true); + } + + void maybeCopy(String name) { + final File file = environment.fileSystem.file( + environment.fileSystem.path.join(inputBuildDir, name), + ); + if (file.existsSync()) { + file.copySync(environment.fileSystem.path.join(shorebirdDir.path, name)); + } + } + + // Copy the link information (generated by gen_snapshot) + // into the shorebird directory. + maybeCopy('App.ct.link'); + maybeCopy('App.class_table.json'); + maybeCopy('App.ft.link'); + maybeCopy('App.field_table.json'); + } +} diff --git a/packages/flutter_tools/lib/src/build_system/targets/ios.dart b/packages/flutter_tools/lib/src/build_system/targets/ios.dart index e1c4ed534add1..f9b8e6a7737c3 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -140,21 +140,11 @@ abstract class AotAssemblyBase extends Target { skipMissingInputs: true, ); - // If the shorebird directory exists, delete it first. - final Directory shorebirdDir = environment.fileSystem.directory(environment.fileSystem.path.join(getIosBuildDirectory(), 'shorebird')); - if (shorebirdDir.existsSync()) { - shorebirdDir.deleteSync(recursive: true); - } - - // Copy the class table link information (generated by gen_snapshot) from the buildOutputPath to the iOS build directory. - final File classTableLink = environment.fileSystem.file(environment.fileSystem.path.join(buildOutputPath, 'App.ct.link')); - final File classTableLinkDebug = environment.fileSystem.file(environment.fileSystem.path.join(buildOutputPath, 'App.class_table.json')); - if (classTableLink.existsSync()) { - classTableLink.copySync(environment.fileSystem.path.join(shorebirdDir.path, 'App.ct.link')); - } - if (classTableLinkDebug.existsSync()) { - classTableLinkDebug.copySync(environment.fileSystem.path.join(shorebirdDir.path, 'App.class_table.json')); - } + await LinkSupplement.create( + environment, + inputBuildDir: getIosBuildDirectory(), + outputBuildDir: buildOutputPath, + ); } } diff --git a/packages/flutter_tools/lib/src/build_system/targets/macos.dart b/packages/flutter_tools/lib/src/build_system/targets/macos.dart index 61408b8ecb609..1c15a6bd5228d 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/macos.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/macos.dart @@ -403,21 +403,11 @@ class CompileMacOSFramework extends Target { skipMissingInputs: true, ); - // If the shorebird directory exists, delete it first. - final Directory shorebirdDir = environment.fileSystem.directory(environment.fileSystem.path.join(getMacOSBuildDirectory(), 'shorebird')); - if (shorebirdDir.existsSync()) { - shorebirdDir.deleteSync(recursive: true); - } - - // Copy the class table link information (generated by gen_snapshot) from the buildOutputPath to the macos build directory. - final File classTableLink = environment.fileSystem.file(environment.fileSystem.path.join(buildOutputPath, 'App.ct.link')); - final File classTableLinkDebug = environment.fileSystem.file(environment.fileSystem.path.join(buildOutputPath, 'App.class_table.json')); - if (classTableLink.existsSync()) { - classTableLink.copySync(environment.fileSystem.path.join(shorebirdDir.path, 'App.ct.link')); - } - if (classTableLinkDebug.existsSync()) { - classTableLinkDebug.copySync(environment.fileSystem.path.join(shorebirdDir.path, 'App.class_table.json')); - } + await LinkSupplement.create( + environment, + inputBuildDir: getMacOSBuildDirectory(), + outputBuildDir: buildOutputPath, + ); } @override