From 35decc3ef91ef001165bd9d91fab9c988c69d666 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 3 Dec 2024 17:14:33 -0600 Subject: [PATCH 01/17] fix(flutter_tool): only dump class_table link info on iOS --- .../flutter_tools/lib/src/base/build.dart | 148 +++++++++++------- 1 file changed, 89 insertions(+), 59 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index 8561c92bd6b1f..62b9af5c4b75b 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -29,15 +29,16 @@ class GenSnapshot { required Artifacts artifacts, required ProcessManager processManager, required Logger logger, - }) : _artifacts = artifacts, - _processUtils = ProcessUtils(logger: logger, processManager: processManager); + }) : _artifacts = artifacts, + _processUtils = + ProcessUtils(logger: logger, processManager: processManager); final Artifacts _artifacts; final ProcessUtils _processUtils; String getSnapshotterPath(SnapshotType snapshotType) { - return _artifacts.getArtifactPath( - Artifact.genSnapshot, platform: snapshotType.platform, mode: snapshotType.mode); + return _artifacts.getArtifactPath(Artifact.genSnapshot, + platform: snapshotType.platform, mode: snapshotType.mode); } /// Ignored warning messages from gen_snapshot. @@ -74,7 +75,8 @@ class GenSnapshot { return _processUtils.stream( [snapshotterPath, ...args], - mapFunction: (String line) => kIgnoredWarnings.contains(line) ? null : line, + mapFunction: (String line) => + kIgnoredWarnings.contains(line) ? null : line, ); } } @@ -87,14 +89,14 @@ class AOTSnapshotter { required Xcode xcode, required ProcessManager processManager, required Artifacts artifacts, - }) : _logger = logger, - _fileSystem = fileSystem, - _xcode = xcode, - _genSnapshot = GenSnapshot( - artifacts: artifacts, - processManager: processManager, - logger: logger, - ); + }) : _logger = logger, + _fileSystem = fileSystem, + _xcode = xcode, + _genSnapshot = GenSnapshot( + artifacts: artifacts, + processManager: processManager, + logger: logger, + ); final Logger _logger; final FileSystem _fileSystem; @@ -122,19 +124,29 @@ class AOTSnapshotter { assert(platform != TargetPlatform.ios || darwinArch != null); if (!_isValidAotPlatform(platform, buildMode)) { - _logger.printError('${getNameForTargetPlatform(platform)} does not support AOT compilation.'); + _logger.printError( + '${getNameForTargetPlatform(platform)} does not support AOT compilation.'); return 1; } final Directory outputDir = _fileSystem.directory(outputPath); outputDir.createSync(recursive: true); - final List genSnapshotArgs = [ + final Directory shorebirdOutputDir = _fileSystem + .directory(_fileSystem.path.join(outputDir.parent.path, 'shorebird')); + shorebirdOutputDir.createSync(recursive: true); + + final List shorebirdDefaultGenSnapshotArgs = [ // Shorebird uses --deterministic to improve snapshot stability and increase linking. '--deterministic', - // Shorebird dumps the class table information during snapshot compilation. - '--print_class_table_link_debug_info_to=${_fileSystem.path.join(outputDir.path, 'App.class_table.json')}', - '--print_class_table_link_info_to=${_fileSystem.path.join(outputDir.path, 'App.ct.link')}', + // 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(shorebirdOutputDir.path, 'App.class_table.json')}', + '--print_class_table_link_info_to=${_fileSystem.path.join(shorebirdOutputDir.path, 'App.ct.link')}', + ]; + + final List genSnapshotArgs = [ + // Only use the default Shorebird gen_snapshot args on iOS. + if (platform == TargetPlatform.ios) ...shorebirdDefaultGenSnapshotArgs, ]; final bool targetingApplePlatform = @@ -149,7 +161,8 @@ class AOTSnapshotter { // by supplying --no-strip in extraGenSnapshotOptions. bool shouldStrip = true; if (extraGenSnapshotOptions.isNotEmpty) { - _logger.printTrace('Extra gen_snapshot options: $extraGenSnapshotOptions'); + _logger + .printTrace('Extra gen_snapshot options: $extraGenSnapshotOptions'); for (final String option in extraGenSnapshotOptions) { if (option == '--no-strip') { shouldStrip = false; @@ -159,14 +172,16 @@ class AOTSnapshotter { } } - final String assembly = _fileSystem.path.join(outputDir.path, 'snapshot_assembly.S'); + final String assembly = + _fileSystem.path.join(outputDir.path, 'snapshot_assembly.S'); if (targetingApplePlatform) { genSnapshotArgs.addAll([ '--snapshot_kind=app-aot-assembly', '--assembly=$assembly', ]); } else { - final String aotSharedLibrary = _fileSystem.path.join(outputDir.path, 'app.so'); + final String aotSharedLibrary = + _fileSystem.path.join(outputDir.path, 'app.so'); genSnapshotArgs.addAll([ '--snapshot_kind=app-aot-elf', '--elf=$aotSharedLibrary', @@ -179,7 +194,8 @@ class AOTSnapshotter { if (targetingApplePlatform) { stripAfterBuild = shouldStrip; if (stripAfterBuild) { - _logger.printTrace('Will strip AOT snapshot manually after build and dSYM generation.'); + _logger.printTrace( + 'Will strip AOT snapshot manually after build and dSYM generation.'); } } else { stripAfterBuild = false; @@ -201,12 +217,12 @@ class AOTSnapshotter { // The name of the debug file must contain additional information about // the architecture, since a single build command may produce // multiple debug files. - final String archName = getNameForTargetPlatform(platform, darwinArch: darwinArch); + final String archName = + getNameForTargetPlatform(platform, darwinArch: darwinArch); final String debugFilename = 'app.$archName.symbols'; final bool shouldSplitDebugInfo = splitDebugInfo?.isNotEmpty ?? false; if (shouldSplitDebugInfo) { - _fileSystem.directory(splitDebugInfo) - .createSync(recursive: true); + _fileSystem.directory(splitDebugInfo).createSync(recursive: true); } // Debugging information. @@ -216,8 +232,7 @@ class AOTSnapshotter { '--resolve-dwarf-paths', '--save-debugging-info=${_fileSystem.path.join(splitDebugInfo!, debugFilename)}', ], - if (dartObfuscation) - '--obfuscate', + if (dartObfuscation) '--obfuscate', ]); genSnapshotArgs.add(mainPath); @@ -229,7 +244,8 @@ class AOTSnapshotter { darwinArch: darwinArch, ); if (genSnapshotExitCode != 0) { - _logger.printError('Dart snapshot generator failed with exit code $genSnapshotExitCode'); + _logger.printError( + 'Dart snapshot generator failed with exit code $genSnapshotExitCode'); return genSnapshotExitCode; } @@ -237,15 +253,14 @@ class AOTSnapshotter { // end-developer can link into their app. if (targetingApplePlatform) { return _buildFramework( - appleArch: darwinArch!, - isIOS: platform == TargetPlatform.ios, - sdkRoot: sdkRoot, - assemblyPath: assembly, - outputPath: outputDir.path, - quiet: quiet, - stripAfterBuild: stripAfterBuild, - extractAppleDebugSymbols: extractAppleDebugSymbols - ); + appleArch: darwinArch!, + isIOS: platform == TargetPlatform.ios, + sdkRoot: sdkRoot, + assemblyPath: assembly, + outputPath: outputDir.path, + quiet: quiet, + stripAfterBuild: stripAfterBuild, + extractAppleDebugSymbols: extractAppleDebugSymbols); } else { return 0; } @@ -253,16 +268,15 @@ class AOTSnapshotter { /// Builds an iOS or macOS framework at [outputPath]/App.framework from the assembly /// source at [assemblyPath]. - Future _buildFramework({ - required DarwinArch appleArch, - required bool isIOS, - String? sdkRoot, - required String assemblyPath, - required String outputPath, - required bool quiet, - required bool stripAfterBuild, - required bool extractAppleDebugSymbols - }) async { + Future _buildFramework( + {required DarwinArch appleArch, + required bool isIOS, + String? sdkRoot, + required String assemblyPath, + required String outputPath, + required bool quiet, + required bool stripAfterBuild, + required bool extractAppleDebugSymbols}) async { final String targetArch = appleArch.name; if (!quiet) { _logger.printStatus('Building App.framework for $targetArch...'); @@ -282,7 +296,8 @@ class AOTSnapshotter { ], ]; - final String assemblyO = _fileSystem.path.join(outputPath, 'snapshot_assembly.o'); + final String assemblyO = + _fileSystem.path.join(outputPath, 'snapshot_assembly.o'); final RunResult compileResult = await _xcode.cc([ ...commonBuildOptions, @@ -292,42 +307,57 @@ class AOTSnapshotter { assemblyO, ]); if (compileResult.exitCode != 0) { - _logger.printError('Failed to compile AOT snapshot. Compiler terminated with exit code ${compileResult.exitCode}'); + _logger.printError( + 'Failed to compile AOT snapshot. Compiler terminated with exit code ${compileResult.exitCode}'); return compileResult.exitCode; } - final String frameworkDir = _fileSystem.path.join(outputPath, 'App.framework'); + final String frameworkDir = + _fileSystem.path.join(outputPath, 'App.framework'); _fileSystem.directory(frameworkDir).createSync(recursive: true); final String appLib = _fileSystem.path.join(frameworkDir, 'App'); final List linkArgs = [ ...commonBuildOptions, '-dynamiclib', - '-Xlinker', '-rpath', '-Xlinker', '@executable_path/Frameworks', - '-Xlinker', '-rpath', '-Xlinker', '@loader_path/Frameworks', + '-Xlinker', + '-rpath', + '-Xlinker', + '@executable_path/Frameworks', + '-Xlinker', + '-rpath', + '-Xlinker', + '@loader_path/Frameworks', '-fapplication-extension', - '-install_name', '@rpath/App.framework/App', - '-o', appLib, + '-install_name', + '@rpath/App.framework/App', + '-o', + appLib, assemblyO, ]; final RunResult linkResult = await _xcode.clang(linkArgs); if (linkResult.exitCode != 0) { - _logger.printError('Failed to link AOT snapshot. Linker terminated with exit code ${linkResult.exitCode}'); + _logger.printError( + 'Failed to link AOT snapshot. Linker terminated with exit code ${linkResult.exitCode}'); return linkResult.exitCode; } if (extractAppleDebugSymbols) { - final RunResult dsymResult = await _xcode.dsymutil(['-o', '$frameworkDir.dSYM', appLib]); + final RunResult dsymResult = + await _xcode.dsymutil(['-o', '$frameworkDir.dSYM', appLib]); if (dsymResult.exitCode != 0) { - _logger.printError('Failed to generate dSYM - dsymutil terminated with exit code ${dsymResult.exitCode}'); + _logger.printError( + 'Failed to generate dSYM - dsymutil terminated with exit code ${dsymResult.exitCode}'); return dsymResult.exitCode; } if (stripAfterBuild) { // See https://www.unix.com/man-page/osx/1/strip/ for arguments - final RunResult stripResult = await _xcode.strip(['-x', appLib, '-o', appLib]); + final RunResult stripResult = + await _xcode.strip(['-x', appLib, '-o', appLib]); if (stripResult.exitCode != 0) { - _logger.printError('Failed to strip debugging symbols from the generated AOT snapshot - strip terminated with exit code ${stripResult.exitCode}'); + _logger.printError( + 'Failed to strip debugging symbols from the generated AOT snapshot - strip terminated with exit code ${stripResult.exitCode}'); return stripResult.exitCode; } } From 0366d5ab0c332dbd39aeb749c607496a0acb77e5 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 3 Dec 2024 17:16:09 -0600 Subject: [PATCH 02/17] revert format --- .../flutter_tools/lib/src/base/build.dart | 134 ++++++++---------- 1 file changed, 56 insertions(+), 78 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index 62b9af5c4b75b..f84042e5724dd 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -29,16 +29,15 @@ class GenSnapshot { required Artifacts artifacts, required ProcessManager processManager, required Logger logger, - }) : _artifacts = artifacts, - _processUtils = - ProcessUtils(logger: logger, processManager: processManager); + }) : _artifacts = artifacts, + _processUtils = ProcessUtils(logger: logger, processManager: processManager); final Artifacts _artifacts; final ProcessUtils _processUtils; String getSnapshotterPath(SnapshotType snapshotType) { - return _artifacts.getArtifactPath(Artifact.genSnapshot, - platform: snapshotType.platform, mode: snapshotType.mode); + return _artifacts.getArtifactPath( + Artifact.genSnapshot, platform: snapshotType.platform, mode: snapshotType.mode); } /// Ignored warning messages from gen_snapshot. @@ -75,8 +74,7 @@ class GenSnapshot { return _processUtils.stream( [snapshotterPath, ...args], - mapFunction: (String line) => - kIgnoredWarnings.contains(line) ? null : line, + mapFunction: (String line) => kIgnoredWarnings.contains(line) ? null : line, ); } } @@ -89,14 +87,14 @@ class AOTSnapshotter { required Xcode xcode, required ProcessManager processManager, required Artifacts artifacts, - }) : _logger = logger, - _fileSystem = fileSystem, - _xcode = xcode, - _genSnapshot = GenSnapshot( - artifacts: artifacts, - processManager: processManager, - logger: logger, - ); + }) : _logger = logger, + _fileSystem = fileSystem, + _xcode = xcode, + _genSnapshot = GenSnapshot( + artifacts: artifacts, + processManager: processManager, + logger: logger, + ); final Logger _logger; final FileSystem _fileSystem; @@ -124,16 +122,14 @@ class AOTSnapshotter { assert(platform != TargetPlatform.ios || darwinArch != null); if (!_isValidAotPlatform(platform, buildMode)) { - _logger.printError( - '${getNameForTargetPlatform(platform)} does not support AOT compilation.'); + _logger.printError('${getNameForTargetPlatform(platform)} does not support AOT compilation.'); return 1; } final Directory outputDir = _fileSystem.directory(outputPath); outputDir.createSync(recursive: true); - final Directory shorebirdOutputDir = _fileSystem - .directory(_fileSystem.path.join(outputDir.parent.path, 'shorebird')); + final Directory shorebirdOutputDir = _fileSystem.directory(_fileSystem.path.join(outputDir.parent.path, 'shorebird')); shorebirdOutputDir.createSync(recursive: true); final List shorebirdDefaultGenSnapshotArgs = [ @@ -161,8 +157,7 @@ class AOTSnapshotter { // by supplying --no-strip in extraGenSnapshotOptions. bool shouldStrip = true; if (extraGenSnapshotOptions.isNotEmpty) { - _logger - .printTrace('Extra gen_snapshot options: $extraGenSnapshotOptions'); + _logger.printTrace('Extra gen_snapshot options: $extraGenSnapshotOptions'); for (final String option in extraGenSnapshotOptions) { if (option == '--no-strip') { shouldStrip = false; @@ -172,16 +167,14 @@ class AOTSnapshotter { } } - final String assembly = - _fileSystem.path.join(outputDir.path, 'snapshot_assembly.S'); + final String assembly = _fileSystem.path.join(outputDir.path, 'snapshot_assembly.S'); if (targetingApplePlatform) { genSnapshotArgs.addAll([ '--snapshot_kind=app-aot-assembly', '--assembly=$assembly', ]); } else { - final String aotSharedLibrary = - _fileSystem.path.join(outputDir.path, 'app.so'); + final String aotSharedLibrary = _fileSystem.path.join(outputDir.path, 'app.so'); genSnapshotArgs.addAll([ '--snapshot_kind=app-aot-elf', '--elf=$aotSharedLibrary', @@ -194,8 +187,7 @@ class AOTSnapshotter { if (targetingApplePlatform) { stripAfterBuild = shouldStrip; if (stripAfterBuild) { - _logger.printTrace( - 'Will strip AOT snapshot manually after build and dSYM generation.'); + _logger.printTrace('Will strip AOT snapshot manually after build and dSYM generation.'); } } else { stripAfterBuild = false; @@ -217,12 +209,12 @@ class AOTSnapshotter { // The name of the debug file must contain additional information about // the architecture, since a single build command may produce // multiple debug files. - final String archName = - getNameForTargetPlatform(platform, darwinArch: darwinArch); + final String archName = getNameForTargetPlatform(platform, darwinArch: darwinArch); final String debugFilename = 'app.$archName.symbols'; final bool shouldSplitDebugInfo = splitDebugInfo?.isNotEmpty ?? false; if (shouldSplitDebugInfo) { - _fileSystem.directory(splitDebugInfo).createSync(recursive: true); + _fileSystem.directory(splitDebugInfo) + .createSync(recursive: true); } // Debugging information. @@ -232,7 +224,8 @@ class AOTSnapshotter { '--resolve-dwarf-paths', '--save-debugging-info=${_fileSystem.path.join(splitDebugInfo!, debugFilename)}', ], - if (dartObfuscation) '--obfuscate', + if (dartObfuscation) + '--obfuscate', ]); genSnapshotArgs.add(mainPath); @@ -244,8 +237,7 @@ class AOTSnapshotter { darwinArch: darwinArch, ); if (genSnapshotExitCode != 0) { - _logger.printError( - 'Dart snapshot generator failed with exit code $genSnapshotExitCode'); + _logger.printError('Dart snapshot generator failed with exit code $genSnapshotExitCode'); return genSnapshotExitCode; } @@ -253,14 +245,15 @@ class AOTSnapshotter { // end-developer can link into their app. if (targetingApplePlatform) { return _buildFramework( - appleArch: darwinArch!, - isIOS: platform == TargetPlatform.ios, - sdkRoot: sdkRoot, - assemblyPath: assembly, - outputPath: outputDir.path, - quiet: quiet, - stripAfterBuild: stripAfterBuild, - extractAppleDebugSymbols: extractAppleDebugSymbols); + appleArch: darwinArch!, + isIOS: platform == TargetPlatform.ios, + sdkRoot: sdkRoot, + assemblyPath: assembly, + outputPath: outputDir.path, + quiet: quiet, + stripAfterBuild: stripAfterBuild, + extractAppleDebugSymbols: extractAppleDebugSymbols + ); } else { return 0; } @@ -268,15 +261,16 @@ class AOTSnapshotter { /// Builds an iOS or macOS framework at [outputPath]/App.framework from the assembly /// source at [assemblyPath]. - Future _buildFramework( - {required DarwinArch appleArch, - required bool isIOS, - String? sdkRoot, - required String assemblyPath, - required String outputPath, - required bool quiet, - required bool stripAfterBuild, - required bool extractAppleDebugSymbols}) async { + Future _buildFramework({ + required DarwinArch appleArch, + required bool isIOS, + String? sdkRoot, + required String assemblyPath, + required String outputPath, + required bool quiet, + required bool stripAfterBuild, + required bool extractAppleDebugSymbols + }) async { final String targetArch = appleArch.name; if (!quiet) { _logger.printStatus('Building App.framework for $targetArch...'); @@ -296,8 +290,7 @@ class AOTSnapshotter { ], ]; - final String assemblyO = - _fileSystem.path.join(outputPath, 'snapshot_assembly.o'); + final String assemblyO = _fileSystem.path.join(outputPath, 'snapshot_assembly.o'); final RunResult compileResult = await _xcode.cc([ ...commonBuildOptions, @@ -307,57 +300,42 @@ class AOTSnapshotter { assemblyO, ]); if (compileResult.exitCode != 0) { - _logger.printError( - 'Failed to compile AOT snapshot. Compiler terminated with exit code ${compileResult.exitCode}'); + _logger.printError('Failed to compile AOT snapshot. Compiler terminated with exit code ${compileResult.exitCode}'); return compileResult.exitCode; } - final String frameworkDir = - _fileSystem.path.join(outputPath, 'App.framework'); + final String frameworkDir = _fileSystem.path.join(outputPath, 'App.framework'); _fileSystem.directory(frameworkDir).createSync(recursive: true); final String appLib = _fileSystem.path.join(frameworkDir, 'App'); final List linkArgs = [ ...commonBuildOptions, '-dynamiclib', - '-Xlinker', - '-rpath', - '-Xlinker', - '@executable_path/Frameworks', - '-Xlinker', - '-rpath', - '-Xlinker', - '@loader_path/Frameworks', + '-Xlinker', '-rpath', '-Xlinker', '@executable_path/Frameworks', + '-Xlinker', '-rpath', '-Xlinker', '@loader_path/Frameworks', '-fapplication-extension', - '-install_name', - '@rpath/App.framework/App', - '-o', - appLib, + '-install_name', '@rpath/App.framework/App', + '-o', appLib, assemblyO, ]; final RunResult linkResult = await _xcode.clang(linkArgs); if (linkResult.exitCode != 0) { - _logger.printError( - 'Failed to link AOT snapshot. Linker terminated with exit code ${linkResult.exitCode}'); + _logger.printError('Failed to link AOT snapshot. Linker terminated with exit code ${linkResult.exitCode}'); return linkResult.exitCode; } if (extractAppleDebugSymbols) { - final RunResult dsymResult = - await _xcode.dsymutil(['-o', '$frameworkDir.dSYM', appLib]); + final RunResult dsymResult = await _xcode.dsymutil(['-o', '$frameworkDir.dSYM', appLib]); if (dsymResult.exitCode != 0) { - _logger.printError( - 'Failed to generate dSYM - dsymutil terminated with exit code ${dsymResult.exitCode}'); + _logger.printError('Failed to generate dSYM - dsymutil terminated with exit code ${dsymResult.exitCode}'); return dsymResult.exitCode; } if (stripAfterBuild) { // See https://www.unix.com/man-page/osx/1/strip/ for arguments - final RunResult stripResult = - await _xcode.strip(['-x', appLib, '-o', appLib]); + final RunResult stripResult = await _xcode.strip(['-x', appLib, '-o', appLib]); if (stripResult.exitCode != 0) { - _logger.printError( - 'Failed to strip debugging symbols from the generated AOT snapshot - strip terminated with exit code ${stripResult.exitCode}'); + _logger.printError('Failed to strip debugging symbols from the generated AOT snapshot - strip terminated with exit code ${stripResult.exitCode}'); return stripResult.exitCode; } } From d231404f3567a6253301b2ded50b3f502909cbad Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 3 Dec 2024 17:18:54 -0600 Subject: [PATCH 03/17] tweak shorebird dir --- packages/flutter_tools/lib/src/base/build.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index f84042e5724dd..163fe5b6cff05 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -129,7 +129,7 @@ class AOTSnapshotter { final Directory outputDir = _fileSystem.directory(outputPath); outputDir.createSync(recursive: true); - final Directory shorebirdOutputDir = _fileSystem.directory(_fileSystem.path.join(outputDir.parent.path, 'shorebird')); + final Directory shorebirdOutputDir = _fileSystem.directory(_fileSystem.path.join(outputDir.parent.parent.path, 'shorebird')); shorebirdOutputDir.createSync(recursive: true); final List shorebirdDefaultGenSnapshotArgs = [ From 39a8bbc9db6ec35431ca041ee326d3a1fd4afc60 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 3 Dec 2024 17:21:36 -0600 Subject: [PATCH 04/17] re-add `--deterministic` for android --- packages/flutter_tools/lib/src/base/build.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index 163fe5b6cff05..7f57312ff9df9 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -132,17 +132,17 @@ class AOTSnapshotter { final Directory shorebirdOutputDir = _fileSystem.directory(_fileSystem.path.join(outputDir.parent.parent.path, 'shorebird')); shorebirdOutputDir.createSync(recursive: true); - final List shorebirdDefaultGenSnapshotArgs = [ - // Shorebird uses --deterministic to improve snapshot stability and increase linking. - '--deterministic', + final List defaultIosGenSnapshotArgs = [ // 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(shorebirdOutputDir.path, 'App.class_table.json')}', '--print_class_table_link_info_to=${_fileSystem.path.join(shorebirdOutputDir.path, 'App.ct.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) ...shorebirdDefaultGenSnapshotArgs, + if (platform == TargetPlatform.ios) ...defaultIosGenSnapshotArgs, ]; final bool targetingApplePlatform = From 0fd2af58a259b4eef6d0d5d7193afe5609466d54 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 3 Dec 2024 17:30:19 -0600 Subject: [PATCH 05/17] tweak --- packages/flutter_tools/lib/src/base/build.dart | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index 7f57312ff9df9..c1fed048dbadb 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -129,20 +129,17 @@ class AOTSnapshotter { final Directory outputDir = _fileSystem.directory(outputPath); outputDir.createSync(recursive: true); - final Directory shorebirdOutputDir = _fileSystem.directory(_fileSystem.path.join(outputDir.parent.parent.path, 'shorebird')); - shorebirdOutputDir.createSync(recursive: true); - - final List defaultIosGenSnapshotArgs = [ + final List iosGenSnapshotArgs = [ // 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(shorebirdOutputDir.path, 'App.class_table.json')}', - '--print_class_table_link_info_to=${_fileSystem.path.join(shorebirdOutputDir.path, 'App.ct.link')}', + '--print_class_table_link_debug_info_to=${_fileSystem.path.join(outputDir.path, 'App.class_table.json')}', + '--print_class_table_link_info_to=${_fileSystem.path.join(outputDir.path, 'App.ct.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) ...defaultIosGenSnapshotArgs, + if (platform == TargetPlatform.ios) ...iosGenSnapshotArgs, ]; final bool targetingApplePlatform = From acb2f9e66103814dbd56dcc1eba2d659b26dbcb5 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 3 Dec 2024 17:33:55 -0600 Subject: [PATCH 06/17] copy link info to build dir --- packages/flutter_tools/lib/src/base/build.dart | 4 ++-- packages/flutter_tools/lib/src/build_system/targets/ios.dart | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index c1fed048dbadb..fe8d3a01185ae 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -131,8 +131,8 @@ class AOTSnapshotter { final List iosGenSnapshotArgs = [ // 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.path, 'App.class_table.json')}', - '--print_class_table_link_info_to=${_fileSystem.path.join(outputDir.path, 'App.ct.link')}', + '--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')}', ]; final List genSnapshotArgs = [ 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 19bd6fe110734..502f10ffcf403 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -159,6 +159,7 @@ class AotAssemblyRelease extends AotAssemblyBase { @override List get outputs => const [ Source.pattern('{OUTPUT_DIR}/App.framework/App'), + Source.pattern('{OUTPUT_DIR}/App.ct.link') // Shorebird class table link information. ]; @override From f85682f4cacd3bdbc193b59ea40c59009d6d7ac3 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 4 Dec 2024 11:07:44 -0600 Subject: [PATCH 07/17] tweak --- .../lib/src/build_system/targets/ios.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 502f10ffcf403..61b61d08ea6e2 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -628,6 +628,18 @@ class ReleaseIosApplicationBundle extends _IosAssetBundleWithDSYM { AotAssemblyRelease(), ]; + @override + List get inputs => [ + ...super.inputs, + const Source.pattern('{BUILD_DIR}/App.ct.link'), + ]; + + @override + List get outputs => [ + ...super.outputs, + const Source.pattern('{OUTPUT_DIR}/App.ct.link'), + ]; + @override Future build(Environment environment) async { bool buildSuccess = true; From 7347ac7729a63b606dc88d6da80dcc056d9bc84b Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 4 Dec 2024 11:50:05 -0600 Subject: [PATCH 08/17] tweak --- .../lib/src/build_system/targets/ios.dart | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) 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 61b61d08ea6e2..e806f12629e04 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -131,6 +131,13 @@ abstract class AotAssemblyBase extends Target { // Don't fail if the dSYM wasn't created (i.e. during a debug build). skipMissingInputs: true, ); + + // // Copy the class table link information to the output directory. + // globals.fs.directory(buildOutputPath).childFile('App.ct.link').copySync( + // globals.fs + // .directory(environment.outputDir.path) + // .childFile('App.ct.link') + // .path); } } @@ -145,6 +152,7 @@ class AotAssemblyRelease extends AotAssemblyBase { List get inputs => const [ Source.pattern('{FLUTTER_ROOT}/packages/flutter_tools/lib/src/build_system/targets/ios.dart'), Source.pattern('{BUILD_DIR}/app.dill'), + Source.pattern('{BUILD_DIR}/App.ct.link'), Source.artifact(Artifact.engineDartBinary), Source.artifact(Artifact.skyEnginePath), // TODO(zanderso): cannot reference gen_snapshot with artifacts since @@ -628,18 +636,6 @@ class ReleaseIosApplicationBundle extends _IosAssetBundleWithDSYM { AotAssemblyRelease(), ]; - @override - List get inputs => [ - ...super.inputs, - const Source.pattern('{BUILD_DIR}/App.ct.link'), - ]; - - @override - List get outputs => [ - ...super.outputs, - const Source.pattern('{OUTPUT_DIR}/App.ct.link'), - ]; - @override Future build(Environment environment) async { bool buildSuccess = true; From d97e92847908f23e6e89d64f17b1f394c4c3bccf Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 4 Dec 2024 11:56:51 -0600 Subject: [PATCH 09/17] tweak --- .../lib/src/build_system/targets/ios.dart | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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 e806f12629e04..eb675af650869 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -132,12 +132,12 @@ abstract class AotAssemblyBase extends Target { skipMissingInputs: true, ); - // // Copy the class table link information to the output directory. - // globals.fs.directory(buildOutputPath).childFile('App.ct.link').copySync( - // globals.fs - // .directory(environment.outputDir.path) - // .childFile('App.ct.link') - // .path); + // Copy the class table link information to the output directory. + globals.fs.directory(buildOutputPath).childFile('App.ct.link').copySync( + globals.fs + .directory(environment.outputDir.path) + .childFile('App.ct.link') + .path); } } @@ -152,7 +152,6 @@ class AotAssemblyRelease extends AotAssemblyBase { List get inputs => const [ Source.pattern('{FLUTTER_ROOT}/packages/flutter_tools/lib/src/build_system/targets/ios.dart'), Source.pattern('{BUILD_DIR}/app.dill'), - Source.pattern('{BUILD_DIR}/App.ct.link'), Source.artifact(Artifact.engineDartBinary), Source.artifact(Artifact.skyEnginePath), // TODO(zanderso): cannot reference gen_snapshot with artifacts since @@ -167,7 +166,6 @@ class AotAssemblyRelease extends AotAssemblyBase { @override List get outputs => const [ Source.pattern('{OUTPUT_DIR}/App.framework/App'), - Source.pattern('{OUTPUT_DIR}/App.ct.link') // Shorebird class table link information. ]; @override From ab0c95e7a7b995308d5028c9b1349ff4758d297b Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 4 Dec 2024 12:12:04 -0600 Subject: [PATCH 10/17] tweak --- .../lib/src/build_system/targets/ios.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 eb675af650869..e7efe7f7f1d2f 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -132,12 +132,11 @@ abstract class AotAssemblyBase extends Target { skipMissingInputs: true, ); - // Copy the class table link information to the output directory. - globals.fs.directory(buildOutputPath).childFile('App.ct.link').copySync( - globals.fs - .directory(environment.outputDir.path) - .childFile('App.ct.link') - .path); + // Copy the class table link information from the buildOutputPath to the iOS build directory. + final File classTableLink = environment.fileSystem.file(environment.fileSystem.path.join(buildOutputPath, 'App.ct.link')); + if (classTableLink.existsSync()) { + classTableLink.copySync(environment.fileSystem.path.join(getIosBuildDirectory(), 'App.ct.link')); + } } } From 171da17a42a7e547d08eb2eb2efc1ed9c6dbe63b Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 4 Dec 2024 12:16:26 -0600 Subject: [PATCH 11/17] tweak --- packages/flutter_tools/lib/src/build_system/targets/ios.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 e7efe7f7f1d2f..baf1cc109cebc 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -132,10 +132,10 @@ abstract class AotAssemblyBase extends Target { skipMissingInputs: true, ); - // Copy the class table link information from the buildOutputPath to the iOS build directory. + // 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')); if (classTableLink.existsSync()) { - classTableLink.copySync(environment.fileSystem.path.join(getIosBuildDirectory(), 'App.ct.link')); + classTableLink.copySync(environment.fileSystem.path.join(getIosBuildDirectory(), 'shorebird', 'App.ct.link')); } } } From 71009777f23dd347192bc50341f33cf5c05f7c61 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 4 Dec 2024 12:19:41 -0600 Subject: [PATCH 12/17] tweak --- packages/flutter_tools/lib/src/build_system/targets/ios.dart | 4 ++++ 1 file changed, 4 insertions(+) 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 baf1cc109cebc..bb00faab0333b 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -134,9 +134,13 @@ abstract class AotAssemblyBase extends Target { // 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(getIosBuildDirectory(), 'shorebird', 'App.ct.link')); } + if (classTableLinkDebug.existsSync()) { + classTableLinkDebug.copySync(environment.fileSystem.path.join(getIosBuildDirectory(), 'shorebird', 'App.class_table.json')); + } } } From ea71e86cf5e642087dddd94fdad505a2e920e192 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 4 Dec 2024 12:58:20 -0600 Subject: [PATCH 13/17] tweak --- packages/flutter_tools/lib/src/ios/mac.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index 46db1f2752a9f..42597d70c4c8d 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -545,6 +545,15 @@ Future buildXcodeProject({ } } + final File classTableLinkInfo = globals.fs.file(globals.fs.path.join(getIosBuildDirectory(), 'shorebird', 'App.ct.link')); + if (classTableLinkInfo.existsSync()) { + final Directory outputShorebirdDirectory = globals.fs.directory(globals.fs.path.join(outputDir!, 'shorebird')); + if (outputShorebirdDirectory.existsSync()) { + outputShorebirdDirectory.deleteSync(recursive: true); + } + classTableLinkInfo.copySync(outputShorebirdDirectory.path); + } + try { updateShorebirdYaml(buildInfo, app.shorebirdYamlPath, environment: globals.platform.environment); } on Exception catch (error) { From 2536c9c037079534e50c5bd44f72bafdac74f220 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 4 Dec 2024 13:04:13 -0600 Subject: [PATCH 14/17] tweak --- packages/flutter_tools/lib/src/ios/mac.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index 42597d70c4c8d..55dac5fd1a66c 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -545,13 +545,14 @@ Future buildXcodeProject({ } } + // Copy shorebird class table link information into the generated xcarchive. final File classTableLinkInfo = globals.fs.file(globals.fs.path.join(getIosBuildDirectory(), 'shorebird', 'App.ct.link')); if (classTableLinkInfo.existsSync()) { final Directory outputShorebirdDirectory = globals.fs.directory(globals.fs.path.join(outputDir!, 'shorebird')); if (outputShorebirdDirectory.existsSync()) { outputShorebirdDirectory.deleteSync(recursive: true); } - classTableLinkInfo.copySync(outputShorebirdDirectory.path); + classTableLinkInfo.copySync(globals.fs.path.join(outputShorebirdDirectory.path, 'App.ct.link')); } try { From bcce65f8cd6f81685c89303c8f3237d3787b7d94 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 4 Dec 2024 13:09:00 -0600 Subject: [PATCH 15/17] tweak --- packages/flutter_tools/lib/src/ios/mac.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index 55dac5fd1a66c..48eeb11a75e49 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -545,10 +545,10 @@ Future buildXcodeProject({ } } - // Copy shorebird class table link information into the generated xcarchive. + // Copy shorebird class table link information into the generated xcarchive if it was generated by gen_snapshot. final File classTableLinkInfo = globals.fs.file(globals.fs.path.join(getIosBuildDirectory(), 'shorebird', 'App.ct.link')); if (classTableLinkInfo.existsSync()) { - final Directory outputShorebirdDirectory = globals.fs.directory(globals.fs.path.join(outputDir!, 'shorebird')); + final Directory outputShorebirdDirectory = globals.fs.directory(globals.fs.path.join(outputDir!, 'Shorebird')); if (outputShorebirdDirectory.existsSync()) { outputShorebirdDirectory.deleteSync(recursive: true); } From 07b72b2d03f002139d3a3632955de69a75fecb32 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 4 Dec 2024 14:31:41 -0600 Subject: [PATCH 16/17] revert --- packages/flutter_tools/lib/src/ios/mac.dart | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index 48eeb11a75e49..7f3b88a74d436 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -545,15 +545,6 @@ Future buildXcodeProject({ } } - // Copy shorebird class table link information into the generated xcarchive if it was generated by gen_snapshot. - final File classTableLinkInfo = globals.fs.file(globals.fs.path.join(getIosBuildDirectory(), 'shorebird', 'App.ct.link')); - if (classTableLinkInfo.existsSync()) { - final Directory outputShorebirdDirectory = globals.fs.directory(globals.fs.path.join(outputDir!, 'Shorebird')); - if (outputShorebirdDirectory.existsSync()) { - outputShorebirdDirectory.deleteSync(recursive: true); - } - classTableLinkInfo.copySync(globals.fs.path.join(outputShorebirdDirectory.path, 'App.ct.link')); - } try { updateShorebirdYaml(buildInfo, app.shorebirdYamlPath, environment: globals.platform.environment); From 9ac8ca59d11cc2fa984fd95c18c15a6def24a2f1 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 4 Dec 2024 16:00:35 -0600 Subject: [PATCH 17/17] revert --- packages/flutter_tools/lib/src/ios/mac.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index 7f3b88a74d436..46db1f2752a9f 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -545,7 +545,6 @@ Future buildXcodeProject({ } } - try { updateShorebirdYaml(buildInfo, app.shorebirdYamlPath, environment: globals.platform.environment); } on Exception catch (error) {