From 2f2645b99c6e8857dd6149ba45ee098c0074a4a3 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Thu, 28 Mar 2024 16:36:50 -0500 Subject: [PATCH] feat(shorebird_cli): include link percentage in patch metadata (#1837) --- .../src/commands/patch/patch_aar_command.dart | 1 + .../commands/patch/patch_android_command.dart | 1 + .../src/commands/patch/patch_ios_command.dart | 1 + .../patch/patch_ios_framework_command.dart | 1 + .../commands/patch/patch_aar_command_test.dart | 1 + .../patch/patch_android_command_test.dart | 1 + .../commands/patch/patch_ios_command_test.dart | 16 ++++++++++++++++ .../patch/patch_ios_framework_command_test.dart | 1 + .../lib/src/models/create_patch_metadata.dart | 10 ++++++++++ .../lib/src/models/create_patch_metadata.g.dart | 6 +++++- .../create_patch/create_patch_request_test.dart | 1 + .../src/models/create_patch_metadata_test.dart | 5 +++++ 12 files changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_aar_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_aar_command.dart index b3342c6da..29a3b732e 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_aar_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_aar_command.dart @@ -287,6 +287,7 @@ ${summary.join('\n')} hasAssetChanges: diffStatus.hasAssetChanges, usedIgnoreNativeChangesFlag: allowNativeDiffs, hasNativeChanges: diffStatus.hasNativeChanges, + linkPercentage: null, environment: BuildEnvironmentMetadata( operatingSystem: platform.operatingSystem, operatingSystemVersion: platform.operatingSystemVersion, diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart index d64bd578e..10cf12fc3 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart @@ -387,6 +387,7 @@ ${summary.join('\n')} hasAssetChanges: diffStatus.hasAssetChanges, usedIgnoreNativeChangesFlag: allowNativeDiffs, hasNativeChanges: diffStatus.hasNativeChanges, + linkPercentage: null, environment: BuildEnvironmentMetadata( operatingSystem: platform.operatingSystem, operatingSystemVersion: platform.operatingSystemVersion, diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart index 69e77b60e..5f4090d5f 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart @@ -427,6 +427,7 @@ ${summary.join('\n')} hasAssetChanges: diffStatus.hasAssetChanges, usedIgnoreNativeChangesFlag: allowNativeDiffs, hasNativeChanges: diffStatus.hasNativeChanges, + linkPercentage: percentLinked, environment: BuildEnvironmentMetadata( operatingSystem: platform.operatingSystem, operatingSystemVersion: platform.operatingSystemVersion, diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart index 6348292a8..54cf2d798 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart @@ -345,6 +345,7 @@ ${summary.join('\n')} hasAssetChanges: diffStatus.hasAssetChanges, usedIgnoreNativeChangesFlag: allowNativeDiffs, hasNativeChanges: diffStatus.hasNativeChanges, + linkPercentage: null, environment: BuildEnvironmentMetadata( operatingSystem: platform.operatingSystem, operatingSystemVersion: platform.operatingSystemVersion, diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart index 267398d9c..74e7a039b 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart @@ -900,6 +900,7 @@ Please re-run the release command for this version or create a new release.'''), hasAssetChanges: false, usedIgnoreNativeChangesFlag: false, hasNativeChanges: false, + linkPercentage: null, environment: BuildEnvironmentMetadata( shorebirdVersion: packageVersion, operatingSystem: operatingSystem, diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart index f1d353ef7..794b0801c 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart @@ -983,6 +983,7 @@ Please re-run the release command for this version or create a new release.'''), hasAssetChanges: false, usedIgnoreNativeChangesFlag: false, hasNativeChanges: false, + linkPercentage: null, environment: BuildEnvironmentMetadata( shorebirdVersion: packageVersion, operatingSystem: operatingSystem, diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart index e726a57d7..397af45f0 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart @@ -1344,6 +1344,20 @@ Please re-run the release command for this version or create a new release.'''), }); test('generates diff base and publishes the appropriate patch', () async { + const linkPercentage = 99.9; + when( + () => aotTools.link( + base: any(named: 'base'), + patch: any(named: 'patch'), + analyzeSnapshot: any(named: 'analyzeSnapshot'), + genSnapshot: any(named: 'genSnapshot'), + kernel: any(named: 'kernel'), + workingDirectory: any(named: 'workingDirectory'), + outputPath: any(named: 'outputPath'), + ), + ).thenAnswer( + (_) async => linkPercentage, + ); await runWithOverrides(command.run); verify( () => codePushClientWrapper.publishPatch( @@ -1362,6 +1376,7 @@ Please re-run the release command for this version or create a new release.'''), hasAssetChanges: false, usedIgnoreNativeChangesFlag: false, hasNativeChanges: false, + linkPercentage: linkPercentage, environment: BuildEnvironmentMetadata( shorebirdVersion: packageVersion, operatingSystem: operatingSystem, @@ -1651,6 +1666,7 @@ flavors: hasAssetChanges: false, usedIgnoreNativeChangesFlag: false, hasNativeChanges: false, + linkPercentage: null, environment: BuildEnvironmentMetadata( shorebirdVersion: packageVersion, operatingSystem: operatingSystem, diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart index 425fa33e4..5dd3ae701 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart @@ -980,6 +980,7 @@ Please re-run the release command for this version or create a new release.'''), hasAssetChanges: false, usedIgnoreNativeChangesFlag: false, hasNativeChanges: false, + linkPercentage: null, environment: BuildEnvironmentMetadata( shorebirdVersion: packageVersion, operatingSystem: operatingSystem, diff --git a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart index adbe5d10e..e09bad986 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart @@ -23,6 +23,7 @@ class CreatePatchMetadata extends Equatable { required this.hasAssetChanges, required this.usedIgnoreNativeChangesFlag, required this.hasNativeChanges, + required this.linkPercentage, required this.environment, }); @@ -35,6 +36,7 @@ class CreatePatchMetadata extends Equatable { bool hasAssetChanges = false, bool usedIgnoreNativeChangesFlag = false, bool hasNativeChanges = false, + double? linkPercentage, BuildEnvironmentMetadata? environment, }) => CreatePatchMetadata( @@ -43,6 +45,7 @@ class CreatePatchMetadata extends Equatable { hasAssetChanges: hasAssetChanges, usedIgnoreNativeChangesFlag: usedIgnoreNativeChangesFlag, hasNativeChanges: hasNativeChanges, + linkPercentage: linkPercentage, environment: environment ?? BuildEnvironmentMetadata.forTest(), ); // coverage:ignore-end @@ -83,6 +86,12 @@ class CreatePatchMetadata extends Equatable { /// behavior in a patch. final bool hasNativeChanges; + /// The percentage of code that was linked in the patch. + /// Generally, the higher the percentage, the better the patch performance + /// since more code will be run on the CPU as opposed to the simulator. + /// Note: link percentage is currently only available for iOS patches. + final double? linkPercentage; + /// Properties about the environment in which the patch was created. /// /// Reason: see [BuildEnvironmentMetadata]. @@ -95,6 +104,7 @@ class CreatePatchMetadata extends Equatable { hasAssetChanges, usedIgnoreNativeChangesFlag, hasNativeChanges, + linkPercentage, environment, ]; } diff --git a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.g.dart index e9e00d87f..e30c8f4e3 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.g.dart @@ -24,6 +24,8 @@ CreatePatchMetadata _$CreatePatchMetadataFromJson(Map json) => 'used_ignore_native_changes_flag', (v) => v as bool), hasNativeChanges: $checkedConvert('has_native_changes', (v) => v as bool), + linkPercentage: $checkedConvert( + 'link_percentage', (v) => (v as num?)?.toDouble()), environment: $checkedConvert( 'environment', (v) => @@ -36,7 +38,8 @@ CreatePatchMetadata _$CreatePatchMetadataFromJson(Map json) => 'usedIgnoreAssetChangesFlag': 'used_ignore_asset_changes_flag', 'hasAssetChanges': 'has_asset_changes', 'usedIgnoreNativeChangesFlag': 'used_ignore_native_changes_flag', - 'hasNativeChanges': 'has_native_changes' + 'hasNativeChanges': 'has_native_changes', + 'linkPercentage': 'link_percentage' }, ); @@ -48,6 +51,7 @@ Map _$CreatePatchMetadataToJson( 'has_asset_changes': instance.hasAssetChanges, 'used_ignore_native_changes_flag': instance.usedIgnoreNativeChangesFlag, 'has_native_changes': instance.hasNativeChanges, + 'link_percentage': instance.linkPercentage, 'environment': instance.environment.toJson(), }; diff --git a/packages/shorebird_code_push_protocol/test/src/messages/create_patch/create_patch_request_test.dart b/packages/shorebird_code_push_protocol/test/src/messages/create_patch/create_patch_request_test.dart index e2f3ba1c8..46e6cee19 100644 --- a/packages/shorebird_code_push_protocol/test/src/messages/create_patch/create_patch_request_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/messages/create_patch/create_patch_request_test.dart @@ -15,6 +15,7 @@ void main() { usedIgnoreNativeChangesFlag: false, hasAssetChanges: true, hasNativeChanges: false, + linkPercentage: 99.9, environment: BuildEnvironmentMetadata( operatingSystem: 'linux', operatingSystemVersion: '1.0.0', diff --git a/packages/shorebird_code_push_protocol/test/src/models/create_patch_metadata_test.dart b/packages/shorebird_code_push_protocol/test/src/models/create_patch_metadata_test.dart index 2732c9b48..6b5125640 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/create_patch_metadata_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/create_patch_metadata_test.dart @@ -10,6 +10,7 @@ void main() { hasAssetChanges: false, usedIgnoreNativeChangesFlag: false, hasNativeChanges: false, + linkPercentage: 99.9, environment: BuildEnvironmentMetadata( operatingSystem: 'macos', operatingSystemVersion: '1.2.3', @@ -31,6 +32,7 @@ void main() { hasAssetChanges: false, usedIgnoreNativeChangesFlag: false, hasNativeChanges: false, + linkPercentage: 99.9, environment: BuildEnvironmentMetadata( operatingSystem: 'macos', operatingSystemVersion: '1.2.3', @@ -44,6 +46,7 @@ void main() { hasAssetChanges: false, usedIgnoreNativeChangesFlag: false, hasNativeChanges: false, + linkPercentage: 99.9, environment: BuildEnvironmentMetadata( operatingSystem: 'macos', operatingSystemVersion: '1.2.3', @@ -61,6 +64,7 @@ void main() { hasAssetChanges: false, usedIgnoreNativeChangesFlag: false, hasNativeChanges: false, + linkPercentage: null, environment: BuildEnvironmentMetadata( operatingSystem: 'macos', operatingSystemVersion: '1.2.3', @@ -74,6 +78,7 @@ void main() { hasAssetChanges: false, usedIgnoreNativeChangesFlag: false, hasNativeChanges: false, + linkPercentage: null, environment: BuildEnvironmentMetadata( operatingSystem: 'macos', operatingSystemVersion: '1.2.3',