Add a new PrebuiltFlutterApplicationPackage interface. (#95290)
* Add a new PrebuiltFlutterApplicationPackage interface. * Review feedback * Rename bundleDir to uncompressedBundle
This commit is contained in:
@@ -362,7 +362,7 @@ class AndroidDevice extends Device {
|
||||
}
|
||||
|
||||
String _getSourceSha1(AndroidApk apk) {
|
||||
final File shaFile = _fileSystem.file('${apk.file.path}.sha1');
|
||||
final File shaFile = _fileSystem.file('${apk.applicationPackage.path}.sha1');
|
||||
return shaFile.existsSync() ? shaFile.readAsStringSync() : '';
|
||||
}
|
||||
|
||||
@@ -435,13 +435,13 @@ class AndroidDevice extends Device {
|
||||
AndroidApk app, {
|
||||
String? userIdentifier,
|
||||
}) async {
|
||||
if (!app.file.existsSync()) {
|
||||
_logger.printError('"${_fileSystem.path.relative(app.file.path)}" does not exist.');
|
||||
if (!app.applicationPackage.existsSync()) {
|
||||
_logger.printError('"${_fileSystem.path.relative(app.applicationPackage.path)}" does not exist.');
|
||||
return false;
|
||||
}
|
||||
|
||||
final Status status = _logger.startProgress(
|
||||
'Installing ${_fileSystem.path.relative(app.file.path)}...',
|
||||
'Installing ${_fileSystem.path.relative(app.applicationPackage.path)}...',
|
||||
);
|
||||
final RunResult installResult = await _processUtils.run(
|
||||
adbCommandForDevice(<String>[
|
||||
@@ -450,7 +450,7 @@ class AndroidDevice extends Device {
|
||||
'-r',
|
||||
if (userIdentifier != null)
|
||||
...<String>['--user', userIdentifier],
|
||||
app.file.path
|
||||
app.applicationPackage.path
|
||||
]));
|
||||
status.stop();
|
||||
// Some versions of adb exit with exit code 0 even on failure :(
|
||||
|
||||
@@ -21,13 +21,13 @@ import 'android_sdk.dart';
|
||||
import 'gradle.dart';
|
||||
|
||||
/// An application package created from an already built Android APK.
|
||||
class AndroidApk extends ApplicationPackage {
|
||||
class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackage {
|
||||
AndroidApk({
|
||||
required String id,
|
||||
required this.file,
|
||||
required this.applicationPackage,
|
||||
required this.versionCode,
|
||||
required this.launchActivity,
|
||||
}) : assert(file != null),
|
||||
}) : assert(applicationPackage != null),
|
||||
assert(launchActivity != null),
|
||||
super(id: id);
|
||||
|
||||
@@ -80,14 +80,14 @@ class AndroidApk extends ApplicationPackage {
|
||||
|
||||
return AndroidApk(
|
||||
id: packageName,
|
||||
file: apk,
|
||||
applicationPackage: apk,
|
||||
versionCode: data.versionCode == null ? null : int.tryParse(data.versionCode!),
|
||||
launchActivity: '${data.packageName}/${data.launchableActivityName}',
|
||||
);
|
||||
}
|
||||
|
||||
/// Path to the actual apk file.
|
||||
final File file;
|
||||
@override
|
||||
final FileSystemEntity applicationPackage;
|
||||
|
||||
/// The path to the activity that should be launched.
|
||||
final String launchActivity;
|
||||
@@ -197,14 +197,14 @@ class AndroidApk extends ApplicationPackage {
|
||||
|
||||
return AndroidApk(
|
||||
id: packageId,
|
||||
file: apkFile,
|
||||
applicationPackage: apkFile,
|
||||
versionCode: null,
|
||||
launchActivity: launchActivity,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String get name => file.basename;
|
||||
String get name => applicationPackage.basename;
|
||||
}
|
||||
|
||||
abstract class _Entry {
|
||||
|
||||
@@ -31,3 +31,12 @@ abstract class ApplicationPackage {
|
||||
@override
|
||||
String toString() => displayName ?? id;
|
||||
}
|
||||
|
||||
/// An interface for application package that is created from prebuilt binary.
|
||||
abstract class PrebuiltApplicationPackage implements ApplicationPackage {
|
||||
/// The application bundle of the prebuilt application.
|
||||
///
|
||||
/// The same ApplicationPackage should be able to be recreated by passing
|
||||
/// the file to [FlutterApplicationPackageFactory.getPackageForPlatform].
|
||||
FileSystemEntity get applicationPackage;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ abstract class FuchsiaApp extends ApplicationPackage {
|
||||
return null;
|
||||
}
|
||||
return PrebuiltFuchsiaApp(
|
||||
farArchive: applicationBinary.path,
|
||||
applicationPackage: applicationBinary,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -44,20 +44,20 @@ abstract class FuchsiaApp extends ApplicationPackage {
|
||||
File farArchive(BuildMode buildMode);
|
||||
}
|
||||
|
||||
class PrebuiltFuchsiaApp extends FuchsiaApp {
|
||||
class PrebuiltFuchsiaApp extends FuchsiaApp implements PrebuiltApplicationPackage {
|
||||
PrebuiltFuchsiaApp({
|
||||
required String farArchive,
|
||||
}) : _farArchive = farArchive,
|
||||
// TODO(zanderso): Extract the archive and extract the id from meta/package.
|
||||
super(projectBundleId: farArchive);
|
||||
|
||||
final String _farArchive;
|
||||
required this.applicationPackage,
|
||||
}) : // TODO(zanderso): Extract the archive and extract the id from meta/package.
|
||||
super(projectBundleId: applicationPackage.path);
|
||||
|
||||
@override
|
||||
File farArchive(BuildMode buildMode) => globals.fs.file(_farArchive);
|
||||
File farArchive(BuildMode buildMode) => globals.fs.file(applicationPackage);
|
||||
|
||||
@override
|
||||
String get name => _farArchive;
|
||||
String get name => applicationPackage.path;
|
||||
|
||||
@override
|
||||
final FileSystemEntity applicationPackage;
|
||||
}
|
||||
|
||||
class BuildableFuchsiaApp extends FuchsiaApp {
|
||||
|
||||
@@ -23,14 +23,14 @@ abstract class IOSApp extends ApplicationPackage {
|
||||
'File "${applicationBinary.path}" does not exist. Use an app bundle or an ipa.');
|
||||
return null;
|
||||
}
|
||||
Directory bundleDir;
|
||||
Directory uncompressedBundle;
|
||||
if (entityType == FileSystemEntityType.directory) {
|
||||
final Directory directory = globals.fs.directory(applicationBinary);
|
||||
if (!_isBundleDirectory(directory)) {
|
||||
globals.printError('Folder "${applicationBinary.path}" is not an app bundle.');
|
||||
return null;
|
||||
}
|
||||
bundleDir = globals.fs.directory(applicationBinary);
|
||||
uncompressedBundle = globals.fs.directory(applicationBinary);
|
||||
} else {
|
||||
// Try to unpack as an ipa.
|
||||
final Directory tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_app.');
|
||||
@@ -44,14 +44,14 @@ abstract class IOSApp extends ApplicationPackage {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
bundleDir = payloadDir.listSync().whereType<Directory>().singleWhere(_isBundleDirectory);
|
||||
uncompressedBundle = payloadDir.listSync().whereType<Directory>().singleWhere(_isBundleDirectory);
|
||||
} on StateError {
|
||||
globals.printError(
|
||||
'Invalid prebuilt iOS ipa. Does not contain a single app bundle.');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
final String plistPath = globals.fs.path.join(bundleDir.path, 'Info.plist');
|
||||
final String plistPath = globals.fs.path.join(uncompressedBundle.path, 'Info.plist');
|
||||
if (!globals.fs.file(plistPath).existsSync()) {
|
||||
globals.printError('Invalid prebuilt iOS app. Does not contain Info.plist.');
|
||||
return null;
|
||||
@@ -66,9 +66,10 @@ abstract class IOSApp extends ApplicationPackage {
|
||||
}
|
||||
|
||||
return PrebuiltIOSApp(
|
||||
bundleDir: bundleDir,
|
||||
bundleName: globals.fs.path.basename(bundleDir.path),
|
||||
uncompressedBundle: uncompressedBundle,
|
||||
bundleName: globals.fs.path.basename(uncompressedBundle.path),
|
||||
projectBundleId: id,
|
||||
applicationPackage: applicationBinary,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -152,14 +153,19 @@ class BuildableIOSApp extends IOSApp {
|
||||
}
|
||||
}
|
||||
|
||||
class PrebuiltIOSApp extends IOSApp {
|
||||
class PrebuiltIOSApp extends IOSApp implements PrebuiltApplicationPackage {
|
||||
PrebuiltIOSApp({
|
||||
required this.bundleDir,
|
||||
required this.uncompressedBundle,
|
||||
this.bundleName,
|
||||
required String projectBundleId,
|
||||
required this.applicationPackage,
|
||||
}) : super(projectBundleId: projectBundleId);
|
||||
|
||||
final Directory bundleDir;
|
||||
/// The uncompressed bundle of the application.
|
||||
///
|
||||
/// [IOSApp.fromPrebuiltApp] will uncompress the application into a temporary
|
||||
/// directory even when an `.ipa` file was used to create the [IOSApp] instance.
|
||||
final Directory uncompressedBundle;
|
||||
final String? bundleName;
|
||||
|
||||
@override
|
||||
@@ -174,5 +180,11 @@ class PrebuiltIOSApp extends IOSApp {
|
||||
@override
|
||||
String get deviceBundlePath => _bundlePath;
|
||||
|
||||
String get _bundlePath => bundleDir.path;
|
||||
String get _bundlePath => uncompressedBundle.path;
|
||||
|
||||
/// A [File] or [Directory] pointing to the application bundle.
|
||||
///
|
||||
/// This can be either an `.ipa` file or an uncompressed `.app` directory.
|
||||
@override
|
||||
final FileSystemEntity applicationPackage;
|
||||
}
|
||||
|
||||
@@ -38,10 +38,11 @@ abstract class MacOSApp extends ApplicationPackage {
|
||||
}
|
||||
|
||||
return PrebuiltMacOSApp(
|
||||
bundleDir: bundleInfo.bundle,
|
||||
bundleName: bundleInfo.bundle.path,
|
||||
uncompressedBundle: bundleInfo.uncompressedBundle,
|
||||
bundleName: bundleInfo.uncompressedBundle.path,
|
||||
projectBundleId: bundleInfo.id,
|
||||
executable: bundleInfo.executable,
|
||||
applicationPackage: applicationBinary,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,14 +53,14 @@ abstract class MacOSApp extends ApplicationPackage {
|
||||
globals.printError('File "${applicationBundle.path}" does not exist.');
|
||||
return null;
|
||||
}
|
||||
Directory bundleDir;
|
||||
Directory uncompressedBundle;
|
||||
if (entityType == FileSystemEntityType.directory) {
|
||||
final Directory directory = globals.fs.directory(applicationBundle);
|
||||
if (!_isBundleDirectory(directory)) {
|
||||
globals.printError('Folder "${applicationBundle.path}" is not an app bundle.');
|
||||
return null;
|
||||
}
|
||||
bundleDir = globals.fs.directory(applicationBundle);
|
||||
uncompressedBundle = globals.fs.directory(applicationBundle);
|
||||
} else {
|
||||
// Try to unpack as a zip.
|
||||
final Directory tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_app.');
|
||||
@@ -70,7 +71,7 @@ abstract class MacOSApp extends ApplicationPackage {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
bundleDir = tempDir
|
||||
uncompressedBundle = tempDir
|
||||
.listSync()
|
||||
.whereType<Directory>()
|
||||
.singleWhere(_isBundleDirectory);
|
||||
@@ -79,7 +80,7 @@ abstract class MacOSApp extends ApplicationPackage {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
final String plistPath = globals.fs.path.join(bundleDir.path, 'Contents', 'Info.plist');
|
||||
final String plistPath = globals.fs.path.join(uncompressedBundle.path, 'Contents', 'Info.plist');
|
||||
if (!globals.fs.file(plistPath).existsSync()) {
|
||||
globals.printError('Invalid prebuilt macOS app. Does not contain Info.plist.');
|
||||
return null;
|
||||
@@ -95,11 +96,11 @@ abstract class MacOSApp extends ApplicationPackage {
|
||||
globals.printError('Invalid prebuilt macOS app. Info.plist does not contain bundle executable');
|
||||
return null;
|
||||
}
|
||||
final String executable = globals.fs.path.join(bundleDir.path, 'Contents', 'MacOS', executableName);
|
||||
final String executable = globals.fs.path.join(uncompressedBundle.path, 'Contents', 'MacOS', executableName);
|
||||
if (!globals.fs.file(executable).existsSync()) {
|
||||
globals.printError('Could not find macOS binary at $executable');
|
||||
}
|
||||
return _BundleInfo(executable, id, bundleDir);
|
||||
return _BundleInfo(executable, id, uncompressedBundle);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -110,16 +111,21 @@ abstract class MacOSApp extends ApplicationPackage {
|
||||
String? executable(BuildMode buildMode);
|
||||
}
|
||||
|
||||
class PrebuiltMacOSApp extends MacOSApp {
|
||||
class PrebuiltMacOSApp extends MacOSApp implements PrebuiltApplicationPackage {
|
||||
PrebuiltMacOSApp({
|
||||
required this.bundleDir,
|
||||
required this.uncompressedBundle,
|
||||
required this.bundleName,
|
||||
required this.projectBundleId,
|
||||
required String executable,
|
||||
required this.applicationPackage,
|
||||
}) : _executable = executable,
|
||||
super(projectBundleId: projectBundleId);
|
||||
|
||||
final Directory bundleDir;
|
||||
/// The uncompressed bundle of the application.
|
||||
///
|
||||
/// [MacOSApp.fromPrebuiltApp] will uncompress the application into a temporary
|
||||
/// directory even when an `.zip` file was used to create the [MacOSApp] instance.
|
||||
final Directory uncompressedBundle;
|
||||
final String bundleName;
|
||||
final String projectBundleId;
|
||||
|
||||
@@ -129,10 +135,16 @@ class PrebuiltMacOSApp extends MacOSApp {
|
||||
String get name => bundleName;
|
||||
|
||||
@override
|
||||
String? applicationBundle(BuildMode buildMode) => bundleDir.path;
|
||||
String? applicationBundle(BuildMode buildMode) => uncompressedBundle.path;
|
||||
|
||||
@override
|
||||
String? executable(BuildMode buildMode) => _executable;
|
||||
|
||||
/// A [File] or [Directory] pointing to the application bundle.
|
||||
///
|
||||
/// This can be either a `.zip` file or an uncompressed `.app` directory.
|
||||
@override
|
||||
final FileSystemEntity applicationPackage;
|
||||
}
|
||||
|
||||
class BuildableMacOSApp extends MacOSApp {
|
||||
@@ -170,9 +182,9 @@ class BuildableMacOSApp extends MacOSApp {
|
||||
}
|
||||
|
||||
class _BundleInfo {
|
||||
_BundleInfo(this.executable, this.id, this.bundle);
|
||||
_BundleInfo(this.executable, this.id, this.uncompressedBundle);
|
||||
|
||||
final Directory bundle;
|
||||
final Directory uncompressedBundle;
|
||||
final String executable;
|
||||
final String id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user