Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 18 additions & 1 deletion packages/flutter_tools/lib/src/build_system/targets/macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import '../../base/file_system.dart';
import '../../base/io.dart';
import '../../base/process.dart';
import '../../build_info.dart';
import '../../globals.dart' as globals show xcode;
import '../../globals.dart' as globals show platform, xcode;
import '../../reporting/reporting.dart';
import '../../shorebird/shorebird_yaml.dart';
import '../build_system.dart';
import '../depfile.dart';
import '../exceptions.dart';
Expand Down Expand Up @@ -683,6 +684,22 @@ class ReleaseMacOSBundleFlutterAssets extends MacOSBundleFlutterAssets {
bool buildSuccess = true;
try {
await super.build(environment);
final ResolvedFiles resolvedOutputs = resolveOutputs(environment);
for (final File outputSource in resolvedOutputs.sources) {
if (outputSource.basename == 'shorebird.yaml') {
try {
updateShorebirdYaml(
environment.defines[kFlavor],
outputSource.path,
environment: globals.platform.environment,
);
} on Exception catch (error) {
throw Exception(
'Failed to generate shorebird configuration. Error: $error',
);
}
}
}
} catch (_) { // ignore: avoid_catches_without_on_clauses
buildSuccess = false;
rethrow;
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/ios/mac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ Future<XcodeBuildResult> buildXcodeProject({
}

try {
updateShorebirdYaml(buildInfo, app.shorebirdYamlPath, environment: globals.platform.environment);
updateShorebirdYaml(buildInfo.flavor, app.shorebirdYamlPath, environment: globals.platform.environment);
} on Exception catch (error) {
globals.printError('[shorebird] failed to generate shorebird configuration.\n$error');
return XcodeBuildResult(success: false);
Expand Down
27 changes: 0 additions & 27 deletions packages/flutter_tools/lib/src/macos/build_macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ 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 @@ -222,32 +221,6 @@ 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
5 changes: 2 additions & 3 deletions packages/flutter_tools/lib/src/shorebird/shorebird_yaml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import 'package:yaml/yaml.dart';
import 'package:yaml_edit/yaml_edit.dart';

import '../base/file_system.dart';
import '../build_info.dart';
import '../globals.dart' as globals;

void updateShorebirdYaml(BuildInfo buildInfo, String shorebirdYamlPath, {required Map<String, String> environment}) {
void updateShorebirdYaml(String? flavor, String shorebirdYamlPath, {required Map<String, String> environment}) {
final File shorebirdYaml = globals.fs.file(shorebirdYamlPath);
if (!shorebirdYaml.existsSync()) {
throw Exception('shorebird.yaml not found at $shorebirdYamlPath');
}
final YamlDocument input = loadYamlDocument(shorebirdYaml.readAsStringSync());
final YamlMap yamlMap = input.contents as YamlMap;
final Map<String, dynamic> compiled = compileShorebirdYaml(yamlMap, flavor: buildInfo.flavor, environment: environment);
final Map<String, dynamic> compiled = compileShorebirdYaml(yamlMap, flavor: flavor, environment: environment);
// Currently we write out over the same yaml file, we should fix this to
// write to a new .json file instead and avoid naming confusion between the
// input and compiled files.
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/windows/build_windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Future<void> buildWindows(

if (shorebirdYamlFile.existsSync()) {
try {
updateShorebirdYaml(buildInfo, shorebirdYamlFile.path, environment: globals.platform.environment);
updateShorebirdYaml(buildInfo.flavor, shorebirdYamlFile.path, 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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,43 @@ void main() {
ProcessManager: () => processManager,
});

testUsingContext('ReleaseMacOSBundleFlutterAssets updates shorebird.yaml if present', () async {
environment.defines[kBuildMode] = 'release';
environment.defines[kXcodeAction] = 'install';
environment.defines[kFlavor] = 'internal';

fileSystem.file('bin/cache/artifacts/engine/darwin-x64/vm_isolate_snapshot.bin')
.createSync(recursive: true);
fileSystem.file('bin/cache/artifacts/engine/darwin-x64/isolate_snapshot.bin')
.createSync(recursive: true);
fileSystem.file(fileSystem.path.join(environment.buildDir.path, 'App.framework', 'App'))
.createSync(recursive: true);
final String shorebirdYamlPath = fileSystem.path.join(
environment.buildDir.path,
'App.framework','Versions',
'A',
'Resources',
'flutter_assets',
'shorebird.yaml',
);
fileSystem.file(fileSystem.path.join(environment.buildDir.path, 'App.framework', 'App'))
..createSync(recursive: true)
..writeAsStringSync('''
# Some other text that should be removed
app_id: base-app-id
flavors:
internal: internal-app-id
stable: stable-app-id
''');

await const ReleaseMacOSBundleFlutterAssets().build(environment);

expect(fileSystem.file(shorebirdYamlPath).readAsStringSync(), 'app_id: internal-app-id');
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});

testUsingContext('DebugMacOSFramework creates expected binary with arm64 only arch', () async {
environment.defines[kDarwinArchs] = 'arm64';
processManager.addCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:io';

import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/shorebird/shorebird_yaml.dart';
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';
Expand Down Expand Up @@ -86,12 +85,7 @@ base_url: https://example.com
final File tempFile = File('${tempDir.path}/shorebird.yaml');
tempFile.writeAsStringSync(yamlContents);
updateShorebirdYaml(
const BuildInfo(
BuildMode.release,
'foo',
treeShakeIcons: false,
packageConfigPath: '',
),
'foo',
tempFile.path,
environment: <String, String>{'SHOREBIRD_PUBLIC_KEY': '4-a'},
);
Expand Down
Loading