@@ -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' ;
@@ -496,6 +497,14 @@ Future<XcodeBuildResult> buildXcodeProject({
496
497
globals.printError ('Archive succeeded but the expected xcarchive at $outputDir not found' );
497
498
}
498
499
}
500
+
501
+ try {
502
+ updateShorebirdYaml (buildInfo, app.archiveBundleOutputPath);
503
+ } on Exception catch (error) {
504
+ globals.printError ('[shorebird] failed to generate shorebird configuration.\n $error ' );
505
+ return XcodeBuildResult (success: false );
506
+ }
507
+
499
508
return XcodeBuildResult (
500
509
success: true ,
501
510
output: outputDir,
@@ -510,6 +519,52 @@ Future<XcodeBuildResult> buildXcodeProject({
510
519
}
511
520
}
512
521
522
+ void updateShorebirdYaml (BuildInfo buildInfo, String xcarchivePath) {
523
+ final File shorebirdYaml = globals.fs.file (
524
+ globals.fs.path.join (
525
+ xcarchivePath,
526
+ 'Products' ,
527
+ 'Applications' ,
528
+ 'Runner.app' ,
529
+ 'Frameworks' ,
530
+ 'App.framework' ,
531
+ 'flutter_assets' ,
532
+ 'shorebird.yaml' ,
533
+ ),
534
+ );
535
+ if (! shorebirdYaml.existsSync ()) {
536
+ throw Exception ('shorebird.yaml not found.' );
537
+ }
538
+ final YamlDocument yaml = loadYamlDocument (shorebirdYaml.readAsStringSync ());
539
+ final YamlMap yamlMap = yaml.contents as YamlMap ;
540
+ final String ? flavor = buildInfo.flavor;
541
+ String appId = '' ;
542
+ if (flavor == null ) {
543
+ final String ? defaultAppId = yamlMap['app_id' ] as String ? ;
544
+ if (defaultAppId == null || defaultAppId.isEmpty) {
545
+ throw Exception ('Cannot find "app_id" in shorebird.yaml' );
546
+ }
547
+ appId = defaultAppId;
548
+ } else {
549
+ final YamlMap ? yamlFlavors = yamlMap['flavors' ] as YamlMap ? ;
550
+ if (yamlFlavors == null ) {
551
+ throw Exception ('Cannot find "flavors" in shorebird.yaml.' );
552
+ }
553
+ final String ? flavorAppId = yamlFlavors[flavor] as String ? ;
554
+ if (flavorAppId == null || flavorAppId.isEmpty) {
555
+ throw Exception ('Cannot find "app_id" for $flavor in shorebird.yaml' );
556
+ }
557
+ appId = flavorAppId;
558
+ }
559
+ final StringBuffer yamlContent = StringBuffer ();
560
+ final String ? baseUrl = yamlMap['base_url' ] as String ? ;
561
+ yamlContent.writeln ('app_id: $appId ' );
562
+ if (baseUrl != null ) {
563
+ yamlContent.writeln ('base_url: $baseUrl ' );
564
+ }
565
+ shorebirdYaml.writeAsStringSync (yamlContent.toString (), flush: true );
566
+ }
567
+
513
568
/// Extended attributes applied by Finder can cause code signing errors. Remove them.
514
569
/// https://developer.apple.com/library/archive/qa/qa1940/_index.html
515
570
Future <void > removeFinderExtendedAttributes (FileSystemEntity projectDirectory, ProcessUtils processUtils, Logger logger) async {
0 commit comments