Commit ca8070f9 authored by John McCutchan's avatar John McCutchan Committed by GitHub

Fix flutter run --use-application-binary (#6106)

When using --use-application-binary:

- [x] Stop flutter run from checking for a pubspec.yaml in current directory
- [x] Stop flutter run from invoking pub get
- [x] Set 'shouldBuild' based on --use-application-binary
- [x] Stop requiring 'lib/main.dart' to be present before running.
- [x] Stop building an FLX when launching on Android
parent cf794f42
...@@ -274,12 +274,15 @@ class AndroidDevice extends Device { ...@@ -274,12 +274,15 @@ class AndroidDevice extends Device {
}) async { }) async {
printTrace('$this startBundle'); printTrace('$this startBundle');
if (!FileSystemEntity.isFileSync(bundlePath)) { if (bundlePath != null) {
printError('Cannot find $bundlePath'); if (!FileSystemEntity.isFileSync(bundlePath)) {
return new LaunchResult.failed(); printError('Cannot find $bundlePath');
} return new LaunchResult.failed();
}
runCheckedSync(adbCommandForDevice(<String>['push', bundlePath, _deviceBundlePath])); runCheckedSync(
adbCommandForDevice(<String>['push', bundlePath, _deviceBundlePath]));
}
ProtocolDiscovery observatoryDiscovery; ProtocolDiscovery observatoryDiscovery;
ProtocolDiscovery diagnosticDiscovery; ProtocolDiscovery diagnosticDiscovery;
...@@ -289,13 +292,26 @@ class AndroidDevice extends Device { ...@@ -289,13 +292,26 @@ class AndroidDevice extends Device {
diagnosticDiscovery = new ProtocolDiscovery(logReader, ProtocolDiscovery.kDiagnosticService); diagnosticDiscovery = new ProtocolDiscovery(logReader, ProtocolDiscovery.kDiagnosticService);
} }
List<String> cmd = adbCommandForDevice(<String>[ List<String> cmd;
'shell', 'am', 'start',
'-a', 'android.intent.action.RUN', if (bundlePath != null) {
'-d', _deviceBundlePath, // Specify in the RUN intent the path to the local bundle pushed.
'-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP cmd = adbCommandForDevice(<String>[
'--ez', 'enable-background-compilation', 'true', 'shell', 'am', 'start',
]); '-a', 'android.intent.action.RUN',
'-d', _deviceBundlePath,
'-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP
'--ez', 'enable-background-compilation', 'true',
]);
} else {
cmd = adbCommandForDevice(<String>[
'shell', 'am', 'start',
'-a', 'android.intent.action.RUN',
'-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP
'--ez', 'enable-background-compilation', 'true',
]);
}
if (traceStartup) if (traceStartup)
cmd.addAll(<String>['--ez', 'trace-startup', 'true']); cmd.addAll(<String>['--ez', 'trace-startup', 'true']);
if (route != null) if (route != null)
...@@ -372,19 +388,23 @@ class AndroidDevice extends Device { ...@@ -372,19 +388,23 @@ class AndroidDevice extends Device {
String mainPath, String mainPath,
String route, String route,
DebuggingOptions debuggingOptions, DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs Map<String, dynamic> platformArgs,
bool prebuiltApplication: false
}) async { }) async {
if (!_checkForSupportedAdbVersion() || !_checkForSupportedAndroidVersion()) if (!_checkForSupportedAdbVersion() || !_checkForSupportedAndroidVersion())
return new LaunchResult.failed(); return new LaunchResult.failed();
String localBundlePath = await flx.buildFlx( String localBundlePath;
mainPath: mainPath,
precompiledSnapshot: isAotBuildMode(debuggingOptions.buildMode),
includeRobotoFonts: false
);
if (localBundlePath == null) if (!prebuiltApplication) {
return new LaunchResult.failed(); localBundlePath = await flx.buildFlx(
mainPath: mainPath,
precompiledSnapshot: isAotBuildMode(debuggingOptions.buildMode),
includeRobotoFonts: false
);
if (localBundlePath == null)
return new LaunchResult.failed();
}
printTrace('Starting bundle for $this.'); printTrace('Starting bundle for $this.');
...@@ -430,10 +450,15 @@ class AndroidDevice extends Device { ...@@ -430,10 +450,15 @@ class AndroidDevice extends Device {
ApplicationPackage package, ApplicationPackage package,
LaunchResult result, { LaunchResult result, {
String mainPath, String mainPath,
VMService observatory VMService observatory,
bool prebuiltApplication: false
}) async { }) async {
Directory tempDir = await Directory.systemTemp.createTemp('flutter_tools'); Directory tempDir = await Directory.systemTemp.createTemp('flutter_tools');
if (prebuiltApplication) {
return false;
}
try { try {
String snapshotPath = path.join(tempDir.path, 'snapshot_blob.bin'); String snapshotPath = path.join(tempDir.path, 'snapshot_blob.bin');
int result = await flx.createSnapshot(mainPath: mainPath, snapshotPath: snapshotPath); int result = await flx.createSnapshot(mainPath: mainPath, snapshotPath: snapshotPath);
......
...@@ -81,6 +81,15 @@ class RunCommand extends RunCommandBase { ...@@ -81,6 +81,15 @@ class RunCommand extends RunCommandBase {
// results out to 'refresh_benchmark.json', and exit. This flag is intended // results out to 'refresh_benchmark.json', and exit. This flag is intended
// for use in generating automated flutter benchmarks. // for use in generating automated flutter benchmarks.
argParser.addFlag('benchmark', negatable: false, hide: !verboseHelp); argParser.addFlag('benchmark', negatable: false, hide: !verboseHelp);
commandValidator = () {
if (!runningWithPrebuiltApplication) {
return commonCommandValidator();
}
// When running with a prebuilt application, no command validation is
// necessary.
return true;
};
} }
Device device; Device device;
...@@ -108,10 +117,24 @@ class RunCommand extends RunCommandBase { ...@@ -108,10 +117,24 @@ class RunCommand extends RunCommandBase {
} }
} }
@override
bool get shouldRunPub {
// If we are running with a prebuilt application, do not run pub.
if (runningWithPrebuiltApplication)
return false;
return super.shouldRunPub;
}
bool shouldUseHotMode() { bool shouldUseHotMode() {
return argResults['hot'] && (getBuildMode() == BuildMode.debug); bool hotArg = argResults['hot'] ?? false;
final bool shouldUseHotMode = hotArg && !runningWithPrebuiltApplication;
return (getBuildMode() == BuildMode.debug) && shouldUseHotMode;
} }
bool get runningWithPrebuiltApplication =>
argResults['use-application-binary'] != null;
@override @override
Future<int> verifyThenRunCommand() async { Future<int> verifyThenRunCommand() async {
if (!commandValidator()) if (!commandValidator())
...@@ -191,7 +214,7 @@ class RunCommand extends RunCommandBase { ...@@ -191,7 +214,7 @@ class RunCommand extends RunCommandBase {
); );
} }
return runner.run(route: route, shouldBuild: argResults['build']); return runner.run(route: route, shouldBuild: !runningWithPrebuiltApplication && argResults['build']);
} }
} }
......
...@@ -182,7 +182,8 @@ abstract class Device { ...@@ -182,7 +182,8 @@ abstract class Device {
String mainPath, String mainPath,
String route, String route,
DebuggingOptions debuggingOptions, DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs Map<String, dynamic> platformArgs,
bool prebuiltApplication: false
}); });
/// Does this device implement support for hot reloading / restarting? /// Does this device implement support for hot reloading / restarting?
...@@ -205,7 +206,8 @@ abstract class Device { ...@@ -205,7 +206,8 @@ abstract class Device {
ApplicationPackage package, ApplicationPackage package,
LaunchResult result, { LaunchResult result, {
String mainPath, String mainPath,
VMService observatory VMService observatory,
bool prebuiltApplication: false
}) async { }) async {
throw 'unsupported'; throw 'unsupported';
} }
......
...@@ -181,7 +181,8 @@ class IOSDevice extends Device { ...@@ -181,7 +181,8 @@ class IOSDevice extends Device {
String mainPath, String mainPath,
String route, String route,
DebuggingOptions debuggingOptions, DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs Map<String, dynamic> platformArgs,
bool prebuiltApplication: false
}) async { }) async {
// TODO(chinmaygarde): Use checked, mainPath, route. // TODO(chinmaygarde): Use checked, mainPath, route.
// TODO(devoncarew): Handle startPaused, debugPort. // TODO(devoncarew): Handle startPaused, debugPort.
......
...@@ -412,7 +412,8 @@ class IOSSimulator extends Device { ...@@ -412,7 +412,8 @@ class IOSSimulator extends Device {
String mainPath, String mainPath,
String route, String route,
DebuggingOptions debuggingOptions, DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs Map<String, dynamic> platformArgs,
bool prebuiltApplication: false
}) async { }) async {
printTrace('Building ${app.name} for $id.'); printTrace('Building ${app.name} for $id.');
......
...@@ -38,6 +38,8 @@ class RunAndStayResident extends ResidentRunner { ...@@ -38,6 +38,8 @@ class RunAndStayResident extends ResidentRunner {
final bool benchmark; final bool benchmark;
final String applicationBinary; final String applicationBinary;
bool get prebuiltMode => applicationBinary != null;
@override @override
Future<int> run({ Future<int> run({
Completer<DebugConnectionInfo> connectionInfoCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
...@@ -46,6 +48,7 @@ class RunAndStayResident extends ResidentRunner { ...@@ -46,6 +48,7 @@ class RunAndStayResident extends ResidentRunner {
}) { }) {
// Don't let uncaught errors kill the process. // Don't let uncaught errors kill the process.
return runZoned(() { return runZoned(() {
assert(shouldBuild == !prebuiltMode);
return _run( return _run(
traceStartup: traceStartup, traceStartup: traceStartup,
benchmark: benchmark, benchmark: benchmark,
...@@ -78,7 +81,8 @@ class RunAndStayResident extends ResidentRunner { ...@@ -78,7 +81,8 @@ class RunAndStayResident extends ResidentRunner {
_package, _package,
_result, _result,
mainPath: _mainPath, mainPath: _mainPath,
observatory: vmService observatory: vmService,
prebuiltApplication: prebuiltMode
); );
status.stop(showElapsedTime: true); status.stop(showElapsedTime: true);
...@@ -99,13 +103,15 @@ class RunAndStayResident extends ResidentRunner { ...@@ -99,13 +103,15 @@ class RunAndStayResident extends ResidentRunner {
String route, String route,
bool shouldBuild: true bool shouldBuild: true
}) async { }) async {
_mainPath = findMainDartFile(target); if (!prebuiltMode) {
if (!FileSystemEntity.isFileSync(_mainPath)) { _mainPath = findMainDartFile(target);
String message = 'Tried to run $_mainPath, but that file does not exist.'; if (!FileSystemEntity.isFileSync(_mainPath)) {
if (target == null) String message = 'Tried to run $_mainPath, but that file does not exist.';
message += '\nConsider using the -t option to specify the Dart file to start.'; if (target == null)
printError(message); message += '\nConsider using the -t option to specify the Dart file to start.';
return 1; printError(message);
return 1;
}
} }
_package = getApplicationPackageForPlatform(device.platform, applicationBinary: applicationBinary); _package = getApplicationPackageForPlatform(device.platform, applicationBinary: applicationBinary);
...@@ -153,7 +159,12 @@ class RunAndStayResident extends ResidentRunner { ...@@ -153,7 +159,12 @@ class RunAndStayResident extends ResidentRunner {
platformArgs = <String, dynamic>{ 'trace-startup': traceStartup }; platformArgs = <String, dynamic>{ 'trace-startup': traceStartup };
await startEchoingDeviceLog(); await startEchoingDeviceLog();
printStatus('Running ${getDisplayPath(_mainPath)} on ${device.name}...'); if (_mainPath == null) {
assert(prebuiltMode);
printStatus('Running ${_package.displayName} on ${device.name}');
} else {
printStatus('Running ${getDisplayPath(_mainPath)} on ${device.name}...');
}
_result = await device.startApp( _result = await device.startApp(
_package, _package,
...@@ -161,7 +172,8 @@ class RunAndStayResident extends ResidentRunner { ...@@ -161,7 +172,8 @@ class RunAndStayResident extends ResidentRunner {
mainPath: _mainPath, mainPath: _mainPath,
debuggingOptions: debuggingOptions, debuggingOptions: debuggingOptions,
platformArgs: platformArgs, platformArgs: platformArgs,
route: route route: route,
prebuiltApplication: prebuiltMode
); );
if (!_result.started) { if (!_result.started) {
......
...@@ -22,7 +22,7 @@ typedef bool Validator(); ...@@ -22,7 +22,7 @@ typedef bool Validator();
abstract class FlutterCommand extends Command { abstract class FlutterCommand extends Command {
FlutterCommand() { FlutterCommand() {
commandValidator = _commandValidator; commandValidator = commonCommandValidator;
} }
@override @override
...@@ -206,7 +206,7 @@ abstract class FlutterCommand extends Command { ...@@ -206,7 +206,7 @@ abstract class FlutterCommand extends Command {
// This is a field so that you can modify the value for testing. // This is a field so that you can modify the value for testing.
Validator commandValidator; Validator commandValidator;
bool _commandValidator() { bool commonCommandValidator() {
if (!PackageMap.isUsingCustomPackagesPath) { if (!PackageMap.isUsingCustomPackagesPath) {
// Don't expect a pubspec.yaml file if the user passed in an explicit .packages file path. // Don't expect a pubspec.yaml file if the user passed in an explicit .packages file path.
if (!FileSystemEntity.isFileSync('pubspec.yaml')) { if (!FileSystemEntity.isFileSync('pubspec.yaml')) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment