Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/flutter_tools/lib/src/base/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<String> genSnapshotArgs = <String>[
// 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 =
Expand Down
33 changes: 33 additions & 0 deletions packages/flutter_tools/lib/src/build_system/targets/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,36 @@ abstract final class Lipo {
}
}
}

/// For managing the supplementary linking files for Shorebird.
abstract final class LinkSupplement {
static Future<void> 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');
}
}
20 changes: 5 additions & 15 deletions packages/flutter_tools/lib/src/build_system/targets/ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}

Expand Down
20 changes: 5 additions & 15 deletions packages/flutter_tools/lib/src/build_system/targets/macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down