[macos] add flavor options to commands in the flutter_tool (#118421)
* Add new macos target configured for flavors * Rename Free App copy-Info.plist to Free App Info.plist * Remove bogus entitlements * Remove Generated.xcconfig * Audit project.pbxproj * Remove unused configs * share one info.plist * Modify scheme so that paid app works * Codesign automatic * Pipe flavor as scheme into xcodebuild * Ignore incoming flavor string * pipe flavor for flutter run to work * Add devicelab tests * Error if host and target device are same for flutter install desktop * Avoid bang (!) by promoting a local. Co-authored-by: Jenn Magder <magder@google.com> * Add supportsInstall property * Override in test classes * Add install test on macOS * Refactor application_package and add tests for package directory Co-authored-by: a-wallen <stephenwallen@google.com> Co-authored-by: Jenn Magder <magder@google.com>
This commit is contained in:
@@ -50,6 +50,11 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts
|
||||
if (device == null) {
|
||||
throwToolExit('No target device found');
|
||||
}
|
||||
|
||||
if (!device!.supportsInstall) {
|
||||
throwToolExit('Host and target are the same. Nothing to install.');
|
||||
}
|
||||
|
||||
if (userIdentifier != null && device is! AndroidDevice) {
|
||||
throwToolExit('--${FlutterOptions.kDeviceUser} is only supported for Android');
|
||||
}
|
||||
|
||||
@@ -104,6 +104,9 @@ abstract class DesktopDevice extends Device {
|
||||
@override
|
||||
void clearLogs() {}
|
||||
|
||||
@override
|
||||
bool get supportsInstall => false;
|
||||
|
||||
@override
|
||||
Future<LaunchResult> startApp(
|
||||
ApplicationPackage package, {
|
||||
@@ -123,9 +126,9 @@ abstract class DesktopDevice extends Device {
|
||||
}
|
||||
|
||||
// Ensure that the executable is locatable.
|
||||
final BuildMode buildMode = debuggingOptions.buildInfo.mode;
|
||||
final BuildInfo buildInfo = debuggingOptions.buildInfo;
|
||||
final bool traceStartup = platformArgs['trace-startup'] as bool? ?? false;
|
||||
final String? executable = executablePathForDevice(package, buildMode);
|
||||
final String? executable = executablePathForDevice(package, buildInfo);
|
||||
if (executable == null) {
|
||||
_logger.printError('Unable to find executable to run');
|
||||
return LaunchResult.failed();
|
||||
@@ -161,7 +164,7 @@ abstract class DesktopDevice extends Device {
|
||||
try {
|
||||
final Uri? observatoryUri = await observatoryDiscovery.uri;
|
||||
if (observatoryUri != null) {
|
||||
onAttached(package, buildMode, process);
|
||||
onAttached(package, buildInfo, process);
|
||||
return LaunchResult.succeeded(observatoryUri: observatoryUri);
|
||||
}
|
||||
_logger.printError(
|
||||
@@ -203,11 +206,11 @@ abstract class DesktopDevice extends Device {
|
||||
|
||||
/// Returns the path to the executable to run for [package] on this device for
|
||||
/// the given [buildMode].
|
||||
String? executablePathForDevice(ApplicationPackage package, BuildMode buildMode);
|
||||
String? executablePathForDevice(ApplicationPackage package, BuildInfo buildInfo);
|
||||
|
||||
/// Called after a process is attached, allowing any device-specific extra
|
||||
/// steps to be run.
|
||||
void onAttached(ApplicationPackage package, BuildMode buildMode, Process process) {}
|
||||
void onAttached(ApplicationPackage package, BuildInfo buildInfo, Process process) {}
|
||||
|
||||
/// Computes a set of environment variables used to pass debugging information
|
||||
/// to the engine without interfering with application level command line
|
||||
|
||||
@@ -579,6 +579,10 @@ abstract class Device {
|
||||
/// Whether the device supports the '--fast-start' development mode.
|
||||
bool get supportsFastStart => false;
|
||||
|
||||
/// Whether this device supports the installation of a flutter app via
|
||||
/// `flutter install`.
|
||||
bool get supportsInstall => true;
|
||||
|
||||
/// Stop an app package on the current device.
|
||||
///
|
||||
/// Specify [userIdentifier] to stop app installed to a profile (Android only).
|
||||
|
||||
@@ -70,8 +70,8 @@ class LinuxDevice extends DesktopDevice {
|
||||
}
|
||||
|
||||
@override
|
||||
String executablePathForDevice(covariant LinuxApp package, BuildMode buildMode) {
|
||||
return package.executable(buildMode);
|
||||
String executablePathForDevice(covariant LinuxApp package, BuildInfo buildInfo) {
|
||||
return package.executable(buildInfo.mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,9 +106,9 @@ abstract class MacOSApp extends ApplicationPackage {
|
||||
@override
|
||||
String get displayName => id;
|
||||
|
||||
String? applicationBundle(BuildMode buildMode);
|
||||
String? applicationBundle(BuildInfo buildInfo);
|
||||
|
||||
String? executable(BuildMode buildMode);
|
||||
String? executable(BuildInfo buildInfo);
|
||||
}
|
||||
|
||||
class PrebuiltMacOSApp extends MacOSApp implements PrebuiltApplicationPackage {
|
||||
@@ -135,10 +135,10 @@ class PrebuiltMacOSApp extends MacOSApp implements PrebuiltApplicationPackage {
|
||||
String get name => bundleName;
|
||||
|
||||
@override
|
||||
String? applicationBundle(BuildMode buildMode) => uncompressedBundle.path;
|
||||
String? applicationBundle(BuildInfo buildInfo) => uncompressedBundle.path;
|
||||
|
||||
@override
|
||||
String? executable(BuildMode buildMode) => _executable;
|
||||
String? executable(BuildInfo buildInfo) => _executable;
|
||||
|
||||
/// A [File] or [Directory] pointing to the application bundle.
|
||||
///
|
||||
@@ -156,23 +156,30 @@ class BuildableMacOSApp extends MacOSApp {
|
||||
String get name => 'macOS';
|
||||
|
||||
@override
|
||||
String? applicationBundle(BuildMode buildMode) {
|
||||
String? applicationBundle(BuildInfo buildInfo) {
|
||||
final File appBundleNameFile = project.nameFile;
|
||||
if (!appBundleNameFile.existsSync()) {
|
||||
globals.printError('Unable to find app name. ${appBundleNameFile.path} does not exist');
|
||||
return null;
|
||||
}
|
||||
|
||||
return globals.fs.path.join(
|
||||
getMacOSBuildDirectory(),
|
||||
'Build',
|
||||
'Products',
|
||||
sentenceCase(getNameForBuildMode(buildMode)),
|
||||
bundleDirectory(buildInfo),
|
||||
appBundleNameFile.readAsStringSync().trim());
|
||||
}
|
||||
|
||||
String bundleDirectory(BuildInfo buildInfo) {
|
||||
return sentenceCase(buildInfo.mode.name) + (buildInfo.flavor != null
|
||||
? ' ${sentenceCase(buildInfo.flavor!)}'
|
||||
: '');
|
||||
}
|
||||
|
||||
@override
|
||||
String? executable(BuildMode buildMode) {
|
||||
final String? directory = applicationBundle(buildMode);
|
||||
String? executable(BuildInfo buildInfo) {
|
||||
final String? directory = applicationBundle(buildInfo);
|
||||
if (directory == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ Future<void> buildMacOS({
|
||||
'xcodebuild',
|
||||
'-workspace', xcodeWorkspace.path,
|
||||
'-configuration', configuration,
|
||||
'-scheme', 'Runner',
|
||||
'-scheme', scheme,
|
||||
'-derivedDataPath', flutterBuildDir.absolute.path,
|
||||
'-destination', 'platform=macOS',
|
||||
'OBJROOT=${globals.fs.path.join(flutterBuildDir.absolute.path, 'Build', 'Intermediates.noindex')}',
|
||||
|
||||
@@ -78,17 +78,17 @@ class MacOSDevice extends DesktopDevice {
|
||||
}
|
||||
|
||||
@override
|
||||
String? executablePathForDevice(covariant MacOSApp package, BuildMode buildMode) {
|
||||
return package.executable(buildMode);
|
||||
String? executablePathForDevice(covariant MacOSApp package, BuildInfo buildInfo) {
|
||||
return package.executable(buildInfo);
|
||||
}
|
||||
|
||||
@override
|
||||
void onAttached(covariant MacOSApp package, BuildMode buildMode, Process process) {
|
||||
void onAttached(covariant MacOSApp package, BuildInfo buildInfo, Process process) {
|
||||
// Bring app to foreground. Ideally this would be done post-launch rather
|
||||
// than post-attach, since this won't run for release builds, but there's
|
||||
// no general-purpose way of knowing when a process is far enough along in
|
||||
// the launch process for 'open' to foreground it.
|
||||
final String? applicationBundle = package.applicationBundle(buildMode);
|
||||
final String? applicationBundle = package.applicationBundle(buildInfo);
|
||||
if (applicationBundle == null) {
|
||||
_logger.printError('Failed to foreground app; application bundle not found');
|
||||
return;
|
||||
|
||||
@@ -54,7 +54,7 @@ class MacOSDesignedForIPadDevice extends DesktopDevice {
|
||||
}
|
||||
|
||||
@override
|
||||
String? executablePathForDevice(ApplicationPackage package, BuildMode buildMode) => null;
|
||||
String? executablePathForDevice(ApplicationPackage package, BuildInfo buildInfo) => null;
|
||||
|
||||
@override
|
||||
Future<LaunchResult> startApp(
|
||||
|
||||
@@ -61,8 +61,8 @@ class WindowsDevice extends DesktopDevice {
|
||||
}
|
||||
|
||||
@override
|
||||
String executablePathForDevice(covariant WindowsApp package, BuildMode buildMode) {
|
||||
return package.executable(buildMode);
|
||||
String executablePathForDevice(covariant WindowsApp package, BuildInfo buildInfo) {
|
||||
return package.executable(buildInfo.mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user