diff --git a/packages/flutter_tools/lib/src/macos/build_macos.dart b/packages/flutter_tools/lib/src/macos/build_macos.dart index 5b8b186a238a7..69dcc06e2dafe 100644 --- a/packages/flutter_tools/lib/src/macos/build_macos.dart +++ b/packages/flutter_tools/lib/src/macos/build_macos.dart @@ -22,6 +22,7 @@ import '../migrations/xcode_project_object_version_migration.dart'; import '../migrations/xcode_script_build_phase_migration.dart'; import '../migrations/xcode_thin_binary_build_phase_input_paths_migration.dart'; import '../project.dart'; +import '../shorebird/shorebird_yaml.dart'; import 'application_package.dart'; import 'cocoapod_utils.dart'; import 'migrations/flutter_application_migration.dart'; @@ -221,6 +222,32 @@ Future buildMacOS({ } final String? applicationBundle = MacOSApp.fromMacOSProject(flutterProject.macos).applicationBundle(buildInfo); if (applicationBundle != null) { + final String shorebirdYamlPath = globals.fs.path.join( + applicationBundle, + 'Contents', + 'Frameworks', + 'App.framework', + 'Resources', + 'flutter_assets', + 'shorebird.yaml', + ); + if (globals.fs.isFileSync(shorebirdYamlPath)) { + try { + updateShorebirdYaml( + buildInfo, + shorebirdYamlPath, + environment: globals.platform.environment, + ); + } on Exception catch (error) { + globals.printError( + '[shorebird] failed to generate shorebird configuration.\n$error', + ); + throw Exception( + 'Failed to generate shorebird configuration. Error: $error', + ); + } + } + final Directory outputDirectory = globals.fs.directory(applicationBundle); // This output directory is the .app folder itself. final int? directorySize = globals.os.getDirectorySize(outputDirectory); diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart index c7e9cdce5f874..c9aa5e696baab 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart @@ -57,6 +57,15 @@ final FakePlatform macosPlatformCustomEnv = FakePlatform( } ); +final Platform macosPlatformWithShorebirdPublicKey = FakePlatform( + operatingSystem: 'macos', + environment: { + 'FLUTTER_ROOT': '/', + 'HOME': '/', + 'SHOREBIRD_PUBLIC_KEY': 'my_public_key', + } +); + final Platform notMacosPlatform = FakePlatform( environment: { 'FLUTTER_ROOT': '/', @@ -838,4 +847,37 @@ STDERR STUFF ), FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true), }); + + testUsingContext('macOS build outputs path and size when successful', + () async { + final BuildCommand command = BuildCommand( + artifacts: artifacts, + androidSdk: FakeAndroidSdk(), + buildSystem: TestBuildSystem.all(BuildResult(success: true)), + fileSystem: MemoryFileSystem.test(), + processUtils: processUtils, + logger: BufferLogger.test(), + osUtils: FakeOperatingSystemUtils(), + ); + createMinimalMockProjectFiles(); + final File shorebirdYamlFile = fileSystem.file( + 'build/macos/Build/Products/Release/example.app/Contents/Frameworks/App.framework/Resources/flutter_assets/shorebird.yaml', + ) + ..createSync(recursive: true) + ..writeAsStringSync('app_id: my-app-id'); + + await createTestCommandRunner(command) + .run(const ['build', 'macos', '--no-pub']); + + final String updatedYaml = shorebirdYamlFile.readAsStringSync(); + expect(updatedYaml, contains('app_id: my-app-id')); + expect(updatedYaml, contains('patch_public_key: my_public_key')); + }, overrides: { + FileSystem: () => fileSystem, + ProcessManager: () => FakeProcessManager.list([ + setUpFakeXcodeBuildHandler('Release'), + ]), + Platform: () => macosPlatformWithShorebirdPublicKey, + FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true), + }); }