Skip to content

Commit

Permalink
Merge branch 'main' into release_28
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel authored Mar 28, 2024
2 parents f51de1e + 2f2645b commit 915ef52
Show file tree
Hide file tree
Showing 32 changed files with 969 additions and 189 deletions.
2 changes: 1 addition & 1 deletion bin/internal/flutter.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6e1c9add71baf57b4178d4d315cea7ba52afe355
931d8d0d82f0c1a29731ca7601100804d09b3f33
14 changes: 6 additions & 8 deletions packages/shorebird_cli/lib/src/code_push_client_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ Please create a release using "shorebird release" and try again.
required int releaseId,
required ReleasePlatform platform,
required ReleaseStatus status,
UpdateReleaseMetadata? metadata,
}) async {
final updateStatusProgress = logger.progress('Updating release status');
try {
Expand All @@ -256,6 +257,7 @@ Please create a release using "shorebird release" and try again.
releaseId: releaseId,
platform: platform,
status: status,
metadata: metadata,
);
updateStatusProgress.complete();
} catch (error) {
Expand Down Expand Up @@ -642,16 +644,14 @@ aar artifact already exists, continuing...''',
Future<Patch> createPatch({
required String appId,
required int releaseId,
required bool hasAssetChanges,
required bool hasNativeChanges,
required CreatePatchMetadata metadata,
}) async {
final createPatchProgress = logger.progress('Creating patch');
try {
final patch = await codePushClient.createPatch(
appId: appId,
releaseId: releaseId,
hasAssetChanges: hasAssetChanges,
hasNativeChanges: hasNativeChanges,
metadata: metadata,
);
createPatchProgress.complete();
return patch;
Expand Down Expand Up @@ -709,17 +709,15 @@ aar artifact already exists, continuing...''',
Future<void> publishPatch({
required String appId,
required int releaseId,
required bool hasAssetChanges,
required bool hasNativeChanges,
required CreatePatchMetadata metadata,
required ReleasePlatform platform,
required DeploymentTrack track,
required Map<Arch, PatchArtifactBundle> patchArtifactBundles,
}) async {
final patch = await createPatch(
appId: appId,
releaseId: releaseId,
hasAssetChanges: hasAssetChanges,
hasNativeChanges: hasNativeChanges,
metadata: metadata,
);

await createPatchArtifacts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import 'package:shorebird_cli/src/deployment_track.dart';
import 'package:shorebird_cli/src/formatters/file_size_formatter.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/patch_diff_checker.dart';
import 'package:shorebird_cli/src/platform.dart';
import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_env.dart';
import 'package:shorebird_cli/src/shorebird_flutter.dart';
import 'package:shorebird_cli/src/shorebird_validator.dart';
import 'package:shorebird_cli/src/version.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

/// {@template patch_aar_command}
Expand Down Expand Up @@ -151,19 +153,19 @@ Please re-run the release command for this version or create a new release.''');
return ExitCode.software.code;
}

const platform = ReleasePlatform.android;
const releasePlatform = ReleasePlatform.android;
final releaseArtifacts = await codePushClientWrapper.getReleaseArtifacts(
appId: appId,
releaseId: release.id,
architectures: architectures,
platform: platform,
platform: releasePlatform,
);

final releaseAarArtifact = await codePushClientWrapper.getReleaseArtifact(
appId: appId,
releaseId: release.id,
arch: 'aar',
platform: platform,
platform: releasePlatform,
);

final Map<Arch, String> releaseArtifactPaths;
Expand Down Expand Up @@ -250,7 +252,7 @@ Please re-run the release command for this version or create a new release.''');
final summary = [
'''📱 App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.appId})')}''',
'📦 Release Version: ${lightCyan.wrap(releaseVersion)}',
'''🕹️ Platform: ${lightCyan.wrap(platform.name)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''',
'''🕹️ Platform: ${lightCyan.wrap(releasePlatform.name)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''',
'🟢 Track: ${lightCyan.wrap('Production')}',
];

Expand All @@ -276,11 +278,23 @@ ${summary.join('\n')}
await codePushClientWrapper.publishPatch(
appId: appId,
releaseId: release.id,
hasAssetChanges: diffStatus.hasAssetChanges,
hasNativeChanges: diffStatus.hasNativeChanges,
platform: platform,
platform: releasePlatform,
track: DeploymentTrack.production,
patchArtifactBundles: patchArtifactBundles,
metadata: CreatePatchMetadata(
releasePlatform: releasePlatform,
usedIgnoreAssetChangesFlag: allowAssetDiffs,
hasAssetChanges: diffStatus.hasAssetChanges,
usedIgnoreNativeChangesFlag: allowNativeDiffs,
hasNativeChanges: diffStatus.hasNativeChanges,
linkPercentage: null,
environment: BuildEnvironmentMetadata(
operatingSystem: platform.operatingSystem,
operatingSystemVersion: platform.operatingSystemVersion,
shorebirdVersion: packageVersion,
xcodeVersion: null,
),
),
);

return ExitCode.success.code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import 'package:shorebird_cli/src/extensions/arg_results.dart';
import 'package:shorebird_cli/src/formatters/formatters.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/patch_diff_checker.dart';
import 'package:shorebird_cli/src/platform.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_env.dart';
import 'package:shorebird_cli/src/shorebird_flutter.dart';
import 'package:shorebird_cli/src/shorebird_release_version_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validator.dart';
import 'package:shorebird_cli/src/version.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

/// {@template patch_android_command}
Expand Down Expand Up @@ -121,7 +123,7 @@ If this option is not provided, the version number will be determined from the p

await cache.updateAll();

const platform = ReleasePlatform.android;
const releasePlatform = ReleasePlatform.android;
final flavor = results.findOption('flavor', argParser: argParser);
final target = results.findOption('target', argParser: argParser);

Expand Down Expand Up @@ -252,15 +254,15 @@ Looked in:
appId: app.appId,
releaseId: release.id,
architectures: architectures,
platform: platform,
platform: releasePlatform,
);

final releaseAabArtifact =
await codePushClientWrapper.getReleaseArtifact(
appId: app.appId,
releaseId: release.id,
arch: 'aab',
platform: platform,
platform: releasePlatform,
);

final releaseArtifactPaths = <Arch, String>{};
Expand Down Expand Up @@ -350,7 +352,7 @@ Looked in:
'''📱 App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.appId})')}''',
if (flavor != null) '🍧 Flavor: ${lightCyan.wrap(flavor)}',
'📦 Release Version: ${lightCyan.wrap(releaseVersion)}',
'''🕹️ Platform: ${lightCyan.wrap(platform.name)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''',
'''🕹️ Platform: ${lightCyan.wrap(releasePlatform.name)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''',
if (isStaging)
'🟠 Track: ${lightCyan.wrap('Staging')}'
else
Expand Down Expand Up @@ -379,9 +381,21 @@ ${summary.join('\n')}
await codePushClientWrapper.publishPatch(
appId: appId,
releaseId: release.id,
hasAssetChanges: diffStatus.hasAssetChanges,
hasNativeChanges: diffStatus.hasNativeChanges,
platform: platform,
metadata: CreatePatchMetadata(
releasePlatform: releasePlatform,
usedIgnoreAssetChangesFlag: allowAssetDiffs,
hasAssetChanges: diffStatus.hasAssetChanges,
usedIgnoreNativeChangesFlag: allowNativeDiffs,
hasNativeChanges: diffStatus.hasNativeChanges,
linkPercentage: null,
environment: BuildEnvironmentMetadata(
operatingSystem: platform.operatingSystem,
operatingSystemVersion: platform.operatingSystemVersion,
shorebirdVersion: packageVersion,
xcodeVersion: null,
),
),
platform: releasePlatform,
track:
isStaging ? DeploymentTrack.staging : DeploymentTrack.production,
patchArtifactBundles: patchArtifactBundles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/config/config.dart';
import 'package:shorebird_cli/src/deployment_track.dart';
import 'package:shorebird_cli/src/doctor.dart';
import 'package:shorebird_cli/src/engine_config.dart';
import 'package:shorebird_cli/src/executables/executables.dart';
import 'package:shorebird_cli/src/extensions/arg_results.dart';
import 'package:shorebird_cli/src/formatters/file_size_formatter.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/patch_diff_checker.dart';
import 'package:shorebird_cli/src/platform.dart';
import 'package:shorebird_cli/src/platform/platform.dart';
import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart';
import 'package:shorebird_cli/src/shorebird_artifacts.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_env.dart';
import 'package:shorebird_cli/src/shorebird_flutter.dart';
import 'package:shorebird_cli/src/shorebird_validator.dart';
import 'package:shorebird_cli/src/version.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

/// {@template patch_ios_command}
Expand Down Expand Up @@ -109,6 +110,18 @@ If this option is not provided, the version number will be determined from the p
final HashFunction _hashFn;
final IosArchiveDiffer _archiveDiffer;

// Link percentage that is considered the minimum for acceptable perfromance.
// This was selected arbitrarily and may need to be adjusted.
static const double minLinkPercentage = 50;

static String lowLinkPercentageWarning(double linkPercentage) {
return '''
${lightCyan.wrap('shorebird patch')} was only able to share ${linkPercentage.toStringAsFixed(1)}% of Dart code with the released app.
This means the patched code may execute slower than expected.
https://docs.shorebird.dev/status#ios_link_percentage
''';
}

@override
Future<int> run() async {
try {
Expand All @@ -130,8 +143,6 @@ If this option is not provided, the version number will be determined from the p
return ExitCode.usage.code;
}

showiOSStatusWarning();

final allowAssetDiffs = results['allow-asset-diffs'] == true;
final allowNativeDiffs = results['allow-native-diffs'] == true;
final dryRun = results['dry-run'] == true;
Expand Down Expand Up @@ -306,16 +317,19 @@ Current Flutter Revision: $currentFlutterRevision
),
);

final useLinker = engineConfig.localEngine != null ||
!preLinkerFlutterRevisions.contains(release.flutterRevision);
double? percentLinked;
final useLinker = AotTools.usesLinker(release.flutterRevision);
if (useLinker) {
final exitCode = await _runLinker(
final (:exitCode, :linkPercentage) = await _runLinker(
releaseArtifact: releaseArtifactFile,
);

if (exitCode != ExitCode.success.code) {
return exitCode;
if (exitCode != ExitCode.success.code) return exitCode;

if (linkPercentage != null && linkPercentage < minLinkPercentage) {
logger.warn(lowLinkPercentageWarning(linkPercentage));
}
percentLinked = linkPercentage;
}

if (dryRun) {
Expand Down Expand Up @@ -370,6 +384,8 @@ Current Flutter Revision: $currentFlutterRevision
'🟠 Track: ${lightCyan.wrap('Staging')}'
else
'🟢 Track: ${lightCyan.wrap('Production')}',
if (percentLinked != null)
'''🔗 Running ${lightCyan.wrap('${percentLinked.toStringAsFixed(1)}%')} on CPU''',
];

logger.info(
Expand All @@ -394,8 +410,6 @@ ${summary.join('\n')}
await codePushClientWrapper.publishPatch(
appId: appId,
releaseId: release.id,
hasAssetChanges: diffStatus.hasAssetChanges,
hasNativeChanges: diffStatus.hasNativeChanges,
platform: releasePlatform,
track:
isStaging ? DeploymentTrack.staging : DeploymentTrack.production,
Expand All @@ -407,6 +421,20 @@ ${summary.join('\n')}
size: patchFileSize,
),
},
metadata: CreatePatchMetadata(
releasePlatform: releasePlatform,
usedIgnoreAssetChangesFlag: allowAssetDiffs,
hasAssetChanges: diffStatus.hasAssetChanges,
usedIgnoreNativeChangesFlag: allowNativeDiffs,
hasNativeChanges: diffStatus.hasNativeChanges,
linkPercentage: percentLinked,
environment: BuildEnvironmentMetadata(
operatingSystem: platform.operatingSystem,
operatingSystemVersion: platform.operatingSystemVersion,
shorebirdVersion: packageVersion,
xcodeVersion: await xcodeBuild.version(),
),
),
);

return ExitCode.success.code;
Expand Down Expand Up @@ -494,12 +522,12 @@ ${summary.join('\n')}
buildProgress.complete();
}

Future<int> _runLinker({required File releaseArtifact}) async {
Future<_LinkResult> _runLinker({required File releaseArtifact}) async {
final patch = File(_aotOutputPath);

if (!patch.existsSync()) {
logger.err('Unable to find patch AOT file at ${patch.path}');
return ExitCode.software.code;
return (exitCode: ExitCode.software.code, linkPercentage: null);
}

final analyzeSnapshot = File(
Expand All @@ -510,28 +538,36 @@ ${summary.join('\n')}

if (!analyzeSnapshot.existsSync()) {
logger.err('Unable to find analyze_snapshot at ${analyzeSnapshot.path}');
return ExitCode.software.code;
return (exitCode: ExitCode.software.code, linkPercentage: null);
}

final genSnapshot = shorebirdArtifacts.getArtifactPath(
artifact: ShorebirdArtifact.genSnapshot,
);

final linkProgress = logger.progress('Linking AOT files');
double? linkPercentage;
try {
await aotTools.link(
linkPercentage = await aotTools.link(
base: releaseArtifact.path,
patch: patch.path,
analyzeSnapshot: analyzeSnapshot.path,
genSnapshot: genSnapshot,
outputPath: _vmcodeOutputPath,
workingDirectory: _buildDirectory,
kernel: newestAppDill().path,
);
} catch (error) {
linkProgress.fail('Failed to link AOT files: $error');
return ExitCode.software.code;
return (exitCode: ExitCode.software.code, linkPercentage: null);
}

linkProgress.complete();
return ExitCode.success.code;
return (exitCode: ExitCode.success.code, linkPercentage: linkPercentage);
}
}

typedef _LinkResult = ({int exitCode, double? linkPercentage});

/// {@template _ReadVersionException}
/// Exception thrown when the release version cannot be determined.
/// {@endtemplate}
Expand Down
Loading

0 comments on commit 915ef52

Please sign in to comment.