@@ -6,6 +6,7 @@ import 'dart:async';
6
6
7
7
import 'package:meta/meta.dart' ;
8
8
import 'package:process/process.dart' ;
9
+ import 'package:yaml/yaml.dart' ;
9
10
10
11
import '../artifacts.dart' ;
11
12
import '../base/file_system.dart' ;
@@ -498,6 +499,14 @@ Future<XcodeBuildResult> buildXcodeProject({
498
499
globals.printError ('Archive succeeded but the expected xcarchive at $outputDir not found' );
499
500
}
500
501
}
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
+
501
510
return XcodeBuildResult (
502
511
success: true ,
503
512
output: outputDir,
@@ -512,6 +521,52 @@ Future<XcodeBuildResult> buildXcodeProject({
512
521
}
513
522
}
514
523
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
+
515
570
/// Extended attributes applied by Finder can cause code signing errors. Remove them.
516
571
/// https://developer.apple.com/library/archive/qa/qa1940/_index.html
517
572
Future <void > removeFinderExtendedAttributes (FileSystemEntity projectDirectory, ProcessUtils processUtils, Logger logger) async {
0 commit comments