Skip to content

Commit c2bdd43

Browse files
felangeleseidel
authored andcommitted
feat(flutter_tool): update mac.dart to generate shorebird config (#15)
1 parent ce773e9 commit c2bdd43

File tree

1 file changed

+55
-0
lines changed
  • packages/flutter_tools/lib/src/ios

1 file changed

+55
-0
lines changed

packages/flutter_tools/lib/src/ios/mac.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:async';
66

77
import 'package:meta/meta.dart';
88
import 'package:process/process.dart';
9+
import 'package:yaml/yaml.dart';
910

1011
import '../artifacts.dart';
1112
import '../base/file_system.dart';
@@ -498,6 +499,14 @@ Future<XcodeBuildResult> buildXcodeProject({
498499
globals.printError('Archive succeeded but the expected xcarchive at $outputDir not found');
499500
}
500501
}
502+
503+
try {
504+
updateShorebirdYaml(buildInfo, app.archiveBundleOutputPath);
505+
} on Exception catch (error) {
506+
globals.printError('[shorebird] failed to generate shorebird configuration.\n$error');
507+
return XcodeBuildResult(success: false);
508+
}
509+
501510
return XcodeBuildResult(
502511
success: true,
503512
output: outputDir,
@@ -512,6 +521,52 @@ Future<XcodeBuildResult> buildXcodeProject({
512521
}
513522
}
514523

524+
void updateShorebirdYaml(BuildInfo buildInfo, String xcarchivePath) {
525+
final File shorebirdYaml = globals.fs.file(
526+
globals.fs.path.join(
527+
xcarchivePath,
528+
'Products',
529+
'Applications',
530+
'Runner.app',
531+
'Frameworks',
532+
'App.framework',
533+
'flutter_assets',
534+
'shorebird.yaml',
535+
),
536+
);
537+
if (!shorebirdYaml.existsSync()) {
538+
throw Exception('shorebird.yaml not found.');
539+
}
540+
final YamlDocument yaml = loadYamlDocument(shorebirdYaml.readAsStringSync());
541+
final YamlMap yamlMap = yaml.contents as YamlMap;
542+
final String? flavor = buildInfo.flavor;
543+
String appId = '';
544+
if (flavor == null) {
545+
final String? defaultAppId = yamlMap['app_id'] as String?;
546+
if (defaultAppId == null || defaultAppId.isEmpty) {
547+
throw Exception('Cannot find "app_id" in shorebird.yaml');
548+
}
549+
appId = defaultAppId;
550+
} else {
551+
final YamlMap? yamlFlavors = yamlMap['flavors'] as YamlMap?;
552+
if (yamlFlavors == null) {
553+
throw Exception('Cannot find "flavors" in shorebird.yaml.');
554+
}
555+
final String? flavorAppId = yamlFlavors[flavor] as String?;
556+
if (flavorAppId == null || flavorAppId.isEmpty) {
557+
throw Exception('Cannot find "app_id" for $flavor in shorebird.yaml');
558+
}
559+
appId = flavorAppId;
560+
}
561+
final StringBuffer yamlContent = StringBuffer();
562+
final String? baseUrl = yamlMap['base_url'] as String?;
563+
yamlContent.writeln('app_id: $appId');
564+
if (baseUrl != null) {
565+
yamlContent.writeln('base_url: $baseUrl');
566+
}
567+
shorebirdYaml.writeAsStringSync(yamlContent.toString(), flush: true);
568+
}
569+
515570
/// Extended attributes applied by Finder can cause code signing errors. Remove them.
516571
/// https://developer.apple.com/library/archive/qa/qa1940/_index.html
517572
Future<void> removeFinderExtendedAttributes(FileSystemEntity projectDirectory, ProcessUtils processUtils, Logger logger) async {

0 commit comments

Comments
 (0)