Skip to content

feat(flutter_tool): update mac.dart to generate shorebird config #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2023
Merged
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
55 changes: 55 additions & 0 deletions packages/flutter_tools/lib/src/ios/mac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:async';

import 'package:meta/meta.dart';
import 'package:process/process.dart';
import 'package:yaml/yaml.dart';

import '../artifacts.dart';
import '../base/file_system.dart';
Expand Down Expand Up @@ -477,6 +478,14 @@ Future<XcodeBuildResult> buildXcodeProject({
globals.printError('Archive succeeded but the expected xcarchive at $outputDir not found');
}
}

try {
updateShorebirdYaml(buildInfo, app.archiveBundleOutputPath);
} on Exception catch (error) {
globals.printError('[shorebird] failed to generate shorebird configuration.\n$error');
return XcodeBuildResult(success: false);
}

return XcodeBuildResult(
success: true,
output: outputDir,
Expand All @@ -491,6 +500,52 @@ Future<XcodeBuildResult> buildXcodeProject({
}
}

void updateShorebirdYaml(BuildInfo buildInfo, String xcarchivePath) {
final File shorebirdYaml = globals.fs.file(
globals.fs.path.join(
xcarchivePath,
'Products',
'Applications',
'Runner.app',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't heard any reports of this yet, but I really wonder when we'll get our first error report caused by someone renaming "Runner"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will cause failures much earlier in the pipeline afaik because the flutter tooling expects the project name to be called “Runner” and doesn’t support renaming it.

'Frameworks',
'App.framework',
'flutter_assets',
'shorebird.yaml',
),
);
if (!shorebirdYaml.existsSync()) {
throw Exception('shorebird.yaml not found.');
}
final YamlDocument yaml = loadYamlDocument(shorebirdYaml.readAsStringSync());
final YamlMap yamlMap = yaml.contents as YamlMap;
final String? flavor = buildInfo.flavor;
String appId = '';
if (flavor == null) {
final String? defaultAppId = yamlMap['app_id'] as String?;
if (defaultAppId == null || defaultAppId.isEmpty) {
throw Exception('Cannot find "app_id" in shorebird.yaml');
}
appId = defaultAppId;
} else {
final YamlMap? yamlFlavors = yamlMap['flavors'] as YamlMap?;
if (yamlFlavors == null) {
throw Exception('Cannot find "flavors" in shorebird.yaml.');
}
final String? flavorAppId = yamlFlavors[flavor] as String?;
if (flavorAppId == null || flavorAppId.isEmpty) {
throw Exception('Cannot find "app_id" for $flavor in shorebird.yaml');
}
appId = flavorAppId;
}
final StringBuffer yamlContent = StringBuffer();
final String? baseUrl = yamlMap['base_url'] as String?;
yamlContent.writeln('app_id: $appId');
if (baseUrl != null) {
yamlContent.writeln('base_url: $baseUrl');
}
shorebirdYaml.writeAsStringSync(yamlContent.toString(), flush: true);
}

/// Extended attributes applied by Finder can cause code signing errors. Remove them.
/// https://developer.apple.com/library/archive/qa/qa1940/_index.html
@visibleForTesting
Expand Down