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
27 changes: 27 additions & 0 deletions packages/flutter_tools/lib/src/macos/build_macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -221,6 +222,32 @@ Future<void> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ final FakePlatform macosPlatformCustomEnv = FakePlatform(
}
);

final Platform macosPlatformWithShorebirdPublicKey = FakePlatform(
operatingSystem: 'macos',
environment: <String, String>{
'FLUTTER_ROOT': '/',
'HOME': '/',
'SHOREBIRD_PUBLIC_KEY': 'my_public_key',
}
);

final Platform notMacosPlatform = FakePlatform(
environment: <String, String>{
'FLUTTER_ROOT': '/',
Expand Down Expand Up @@ -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 <String>['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: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
setUpFakeXcodeBuildHandler('Release'),
]),
Platform: () => macosPlatformWithShorebirdPublicKey,
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
});
}
Loading