-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for releasing, previewing, and patching linux apps (#…
- Loading branch information
1 parent
307ebb5
commit 34ebc6e
Showing
32 changed files
with
2,123 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
5c1dcc19ebcee3565c65262dd95970186e4d81cc | ||
3d75b30b181d1d4ce66c426c64aca2498529f2e0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/shorebird_cli/lib/src/archive_analysis/archive_analysis.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export 'android_archive_differ.dart'; | ||
export 'apple_archive_differ.dart'; | ||
export 'file_set_diff.dart'; | ||
export 'linux_bundle_differ.dart'; | ||
export 'plist.dart'; | ||
export 'windows_archive_differ.dart'; |
28 changes: 28 additions & 0 deletions
28
packages/shorebird_cli/lib/src/archive_analysis/linux_bundle_differ.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'package:path/path.dart' as p; | ||
import 'package:shorebird_cli/src/archive_analysis/archive_differ.dart'; | ||
|
||
/// {@template linux_bundle_differ} | ||
/// Finds differences between two Linux bundles. | ||
/// {@endtemplate} | ||
class LinuxBundleDiffer extends ArchiveDiffer { | ||
/// {@macro linux_bundle_differ} | ||
const LinuxBundleDiffer(); | ||
|
||
bool _isDirectoryPath(String path) { | ||
return path.endsWith('/'); | ||
} | ||
|
||
@override | ||
bool isAssetFilePath(String filePath) => | ||
!_isDirectoryPath(filePath) && | ||
p.split(filePath).any((s) => s == 'flutter_assets'); | ||
|
||
@override | ||
bool isDartFilePath(String filePath) => p.basename(filePath) == 'libapp.so'; | ||
|
||
@override | ||
bool isNativeFilePath(String filePath) { | ||
// TODO: implement isNativeFilePath | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
packages/shorebird_cli/lib/src/commands/patch/linux_patcher.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:crypto/crypto.dart'; | ||
import 'package:mason_logger/mason_logger.dart'; | ||
import 'package:path/path.dart' as p; | ||
import 'package:shorebird_cli/src/archive/archive.dart'; | ||
import 'package:shorebird_cli/src/archive_analysis/linux_bundle_differ.dart'; | ||
import 'package:shorebird_cli/src/artifact_builder.dart'; | ||
import 'package:shorebird_cli/src/artifact_manager.dart'; | ||
import 'package:shorebird_cli/src/code_push_client_wrapper.dart'; | ||
import 'package:shorebird_cli/src/code_signer.dart'; | ||
import 'package:shorebird_cli/src/commands/commands.dart'; | ||
import 'package:shorebird_cli/src/common_arguments.dart'; | ||
import 'package:shorebird_cli/src/extensions/arg_results.dart'; | ||
import 'package:shorebird_cli/src/logging/logging.dart'; | ||
import 'package:shorebird_cli/src/patch_diff_checker.dart'; | ||
import 'package:shorebird_cli/src/platform/platform.dart'; | ||
import 'package:shorebird_cli/src/release_type.dart'; | ||
import 'package:shorebird_cli/src/shorebird_flutter.dart'; | ||
import 'package:shorebird_cli/src/third_party/flutter_tools/lib/src/base/process.dart'; | ||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; | ||
|
||
/// {@template linux_patcher} | ||
/// Functions to create a linux patch. | ||
/// {@endtemplate} | ||
class LinuxPatcher extends Patcher { | ||
/// {@macro linux_patcher} | ||
LinuxPatcher({ | ||
required super.argParser, | ||
required super.argResults, | ||
required super.flavor, | ||
required super.target, | ||
}); | ||
|
||
@override | ||
Future<void> assertPreconditions() async {} | ||
|
||
@override | ||
Future<DiffStatus> assertUnpatchableDiffs({ | ||
required ReleaseArtifact releaseArtifact, | ||
required File releaseArchive, | ||
required File patchArchive, | ||
}) async { | ||
return patchDiffChecker.confirmUnpatchableDiffsIfNecessary( | ||
localArchive: patchArchive, | ||
releaseArchive: releaseArchive, | ||
archiveDiffer: const LinuxBundleDiffer(), | ||
allowAssetChanges: allowAssetDiffs, | ||
allowNativeChanges: allowNativeDiffs, | ||
); | ||
} | ||
|
||
@override | ||
Future<File> buildPatchArtifact({String? releaseVersion}) async { | ||
final flutterVersionString = await shorebirdFlutter.getVersionAndRevision(); | ||
|
||
final buildAppBundleProgress = logger.detailProgress( | ||
'Building Linux app with Flutter $flutterVersionString', | ||
); | ||
|
||
try { | ||
await artifactBuilder.buildLinuxApp( | ||
base64PublicKey: argResults.encodedPublicKey, | ||
); | ||
buildAppBundleProgress.complete(); | ||
} on Exception catch (e) { | ||
buildAppBundleProgress.fail(e.toString()); | ||
throw ProcessExit(ExitCode.software.code); | ||
} | ||
|
||
return artifactManager.linuxBundleDirectory.zipToTempFile(); | ||
} | ||
|
||
@override | ||
Future<Map<Arch, PatchArtifactBundle>> createPatchArtifacts({ | ||
required String appId, | ||
required int releaseId, | ||
required File releaseArtifact, | ||
File? supplementArtifact, | ||
}) async { | ||
final createDiffProgress = logger.progress('Creating patch artifacts'); | ||
final patchArtifactPath = p.join( | ||
artifactManager.linuxBundleDirectory.path, | ||
'lib', | ||
'libapp.so', | ||
); | ||
final patchArtifact = File(patchArtifactPath); | ||
final hash = sha256.convert(await patchArtifact.readAsBytes()).toString(); | ||
|
||
final tempDir = Directory.systemTemp.createTempSync(); | ||
final zipPath = p.join(tempDir.path, 'patch.zip'); | ||
final zipFile = releaseArtifact.copySync(zipPath); | ||
await artifactManager.extractZip( | ||
zipFile: zipFile, | ||
outputDirectory: tempDir, | ||
); | ||
|
||
// The release artifact is the zipped directory at | ||
// build/linux/x64/release/bundle | ||
final appSoPath = p.join(tempDir.path, 'lib', 'libapp.so'); | ||
|
||
final privateKeyFile = argResults.file( | ||
CommonArguments.privateKeyArg.name, | ||
); | ||
final hashSignature = privateKeyFile != null | ||
? codeSigner.sign( | ||
message: hash, | ||
privateKeyPemFile: privateKeyFile, | ||
) | ||
: null; | ||
|
||
final String diffPath; | ||
try { | ||
diffPath = await artifactManager.createDiff( | ||
releaseArtifactPath: appSoPath, | ||
patchArtifactPath: patchArtifactPath, | ||
); | ||
} on Exception catch (error) { | ||
createDiffProgress.fail('$error'); | ||
throw ProcessExit(ExitCode.software.code); | ||
} | ||
|
||
createDiffProgress.complete(); | ||
|
||
return { | ||
Arch.x86_64: PatchArtifactBundle( | ||
arch: Arch.x86_64.arch, | ||
path: diffPath, | ||
hash: hash, | ||
size: File(diffPath).lengthSync(), | ||
hashSignature: hashSignature, | ||
), | ||
}; | ||
} | ||
|
||
@override | ||
Future<String> extractReleaseVersionFromArtifact(File artifact) async { | ||
final outputDirectory = Directory.systemTemp.createTempSync(); | ||
await artifactManager.extractZip( | ||
zipFile: artifact, | ||
outputDirectory: outputDirectory, | ||
); | ||
return linux.versionFromLinuxBundle(bundleRoot: outputDirectory); | ||
} | ||
|
||
@override | ||
String get primaryReleaseArtifactArch => 'bundle'; | ||
|
||
@override | ||
ReleaseType get releaseType => ReleaseType.linux; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.