mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
Change flutter tool to not require Fuchsia build args (#22382)
* Change flutter tool to not require Fuchsia build args * Restore code that was commented out. * Fix style nits.
This commit is contained in:
parent
54c10f44b2
commit
c496751ae8
|
@ -23,10 +23,20 @@ import '../runner/flutter_command.dart';
|
|||
import '../vmservice.dart';
|
||||
|
||||
// Usage:
|
||||
// With e.g. flutter_gallery already running, a HotRunner can be attached to it
|
||||
// with:
|
||||
// $ flutter fuchsia_reload -f ~/fuchsia -a 192.168.1.39 \
|
||||
// -g //lib/flutter/examples/flutter_gallery:flutter_gallery
|
||||
// With e.g. hello_mod already running, a HotRunner can be attached to it.
|
||||
//
|
||||
// From a Fuchsia in-tree build:
|
||||
// $ flutter fuchsia_reload --address 192.168.1.39 \
|
||||
// --build-dir ~/fuchsia/out/x64 \
|
||||
// --gn-target //topaz/examples/ui/hello_mod:hello_mod
|
||||
//
|
||||
// From out of tree:
|
||||
// $ flutter fuchsia_reload --address 192.168.1.39 \
|
||||
// --mod_name hello_mod \
|
||||
// --path /path/to/hello_mod
|
||||
// --dot-packages /path/to/hello_mod_out/app.packages \
|
||||
// --ssh-config /path/to/ssh_config \
|
||||
// --target /path/to/hello_mod/lib/main.dart
|
||||
|
||||
final String ipv4Loopback = InternetAddress.loopbackIPv4.address;
|
||||
|
||||
|
@ -40,6 +50,11 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
|||
abbr: 'b',
|
||||
defaultsTo: null,
|
||||
help: 'Fuchsia build directory, e.g. out/release-x86-64.');
|
||||
argParser.addOption('dot-packages',
|
||||
abbr: 'd',
|
||||
defaultsTo: null,
|
||||
help: 'Path to the mod\'s .packages file. Required if no'
|
||||
'GN target specified.');
|
||||
argParser.addOption('gn-target',
|
||||
abbr: 'g',
|
||||
help: 'GN target of the application, e.g //path/to/app:app.');
|
||||
|
@ -51,14 +66,23 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
|||
abbr: 'l',
|
||||
defaultsTo: false,
|
||||
help: 'Lists the running modules. ');
|
||||
argParser.addOption('name-override',
|
||||
abbr: 'n',
|
||||
help: 'On-device name of the application binary.');
|
||||
argParser.addOption('mod-name',
|
||||
abbr: 'm',
|
||||
help: 'Name of the flutter mod. If used with -g, overrides the name '
|
||||
'inferred from the GN target.');
|
||||
argParser.addOption('path',
|
||||
abbr: 'p',
|
||||
defaultsTo: null,
|
||||
help: 'Path to the flutter mod project.');
|
||||
argParser.addOption('ssh-config',
|
||||
abbr: 's',
|
||||
defaultsTo: null,
|
||||
help: 'Path to the Fuchsia target\'s ssh config file.');
|
||||
argParser.addOption('target',
|
||||
abbr: 't',
|
||||
defaultsTo: bundle.defaultMainPath,
|
||||
help: 'Target app path / main entry-point file. '
|
||||
'Relative to --gn-target path, e.g. lib/main.dart.');
|
||||
'Relative to --path or --gn-target path, e.g. lib/main.dart.');
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -67,15 +91,13 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
|||
@override
|
||||
final String description = 'Hot reload on Fuchsia.';
|
||||
|
||||
String _buildDir;
|
||||
String _projectRoot;
|
||||
String _projectName;
|
||||
String _binaryName;
|
||||
String _modName;
|
||||
String _isolateNumber;
|
||||
String _fuchsiaProjectPath;
|
||||
String _target;
|
||||
String _address;
|
||||
String _dotPackagesPath;
|
||||
String _sshConfig;
|
||||
|
||||
bool _list;
|
||||
|
||||
|
@ -113,13 +135,13 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
|||
|
||||
// Check that there are running VM services on the returned
|
||||
// ports, and find the Isolates that are running the target app.
|
||||
final String isolateName = '$_binaryName\$main$_isolateNumber';
|
||||
final String isolateName = '$_modName\$main$_isolateNumber';
|
||||
final List<int> targetPorts = await _filterPorts(
|
||||
servicePorts, isolateName);
|
||||
if (targetPorts.isEmpty)
|
||||
throwToolExit('No VMs found running $_binaryName.');
|
||||
throwToolExit('No VMs found running $_modName.');
|
||||
for (int port in targetPorts)
|
||||
printTrace('Found $_binaryName at $port');
|
||||
printTrace('Found $_modName at $port');
|
||||
|
||||
// Set up a device and hot runner and attach the hot runner to the first
|
||||
// vm service we found.
|
||||
|
@ -143,7 +165,7 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
|||
projectRootPath: _fuchsiaProjectPath,
|
||||
packagesFilePath: _dotPackagesPath
|
||||
);
|
||||
printStatus('Connecting to $_binaryName');
|
||||
printStatus('Connecting to $_modName');
|
||||
await hotRunner.attach(viewFilter: isolateName);
|
||||
} finally {
|
||||
await Future.wait(forwardedPorts.map((_PortForwarder pf) => pf.stop()));
|
||||
|
@ -274,19 +296,28 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
|||
}
|
||||
|
||||
Future<Null> _validateArguments() async {
|
||||
_buildDir = argResults['build-dir'];
|
||||
if (_buildDir == null) {
|
||||
final ProcessResult result = await processManager.run(<String>['fx', 'get-build-dir']);
|
||||
if (result.exitCode == 0)
|
||||
_buildDir = result.stdout.trim();
|
||||
else
|
||||
printStatus('get-build-dir failed:\nstdout: ${result.stdout}\nstderr: ${result.stderr}');
|
||||
final String fuchsiaBuildDir = argResults['build-dir'];
|
||||
final String gnTarget = argResults['gn-target'];
|
||||
|
||||
if (fuchsiaBuildDir != null) {
|
||||
if (gnTarget == null)
|
||||
throwToolExit('Must provide --gn-target when specifying --build-dir.');
|
||||
|
||||
if (!_directoryExists(fuchsiaBuildDir))
|
||||
throwToolExit('Specified --build-dir "$fuchsiaBuildDir" does not exist.');
|
||||
|
||||
_sshConfig = '$fuchsiaBuildDir/ssh-keys/ssh_config';
|
||||
}
|
||||
if (!_directoryExists(_buildDir))
|
||||
throwToolExit('Specified --build-dir "$_buildDir" does not exist.');
|
||||
|
||||
// If sshConfig path not available from the fuchsiaBuildDir, get from command line.
|
||||
_sshConfig ??= argResults['ssh-config'];
|
||||
if (_sshConfig == null)
|
||||
throwToolExit('Provide the path to the ssh config file with --ssh-config.');
|
||||
if (!_fileExists(_sshConfig))
|
||||
throwToolExit('Couldn\'t find ssh config file at $_sshConfig.');
|
||||
|
||||
_address = argResults['address'];
|
||||
if (_address == null) {
|
||||
if (_address == null && fuchsiaBuildDir != null) {
|
||||
final ProcessResult result = await processManager.run(<String>['fx', 'netaddr', '--fuchsia']);
|
||||
if (result.exitCode == 0)
|
||||
_address = result.stdout.trim();
|
||||
|
@ -298,21 +329,27 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
|||
|
||||
_list = argResults['list'];
|
||||
if (_list) {
|
||||
// For --list, we only need the device address and the Fuchsia tree root.
|
||||
// For --list, we only need the ssh config and device address.
|
||||
return;
|
||||
}
|
||||
|
||||
final String gnTarget = argResults['gn-target'];
|
||||
if (gnTarget == null)
|
||||
throwToolExit('Give the GN target with --gn-target(-g).');
|
||||
final List<String> targetInfo = _extractPathAndName(gnTarget);
|
||||
_projectRoot = targetInfo[0];
|
||||
printTrace('_projectRoot is $_projectRoot');
|
||||
_projectName = targetInfo[1];
|
||||
_fuchsiaProjectPath = '$_buildDir/../../$_projectRoot';
|
||||
printTrace('_fuchsiaProjectPath is $_fuchsiaProjectPath');
|
||||
String projectRoot;
|
||||
if (gnTarget != null) {
|
||||
if (fuchsiaBuildDir == null)
|
||||
throwToolExit('Must provide --build-dir when specifying --gn-target.');
|
||||
|
||||
final List<String> targetInfo = _extractPathAndName(gnTarget);
|
||||
projectRoot = targetInfo[0];
|
||||
_modName = targetInfo[1];
|
||||
_fuchsiaProjectPath = '$fuchsiaBuildDir/../../$projectRoot';
|
||||
} else if (argResults['path'] != null) {
|
||||
_fuchsiaProjectPath = argResults['path'];
|
||||
}
|
||||
|
||||
if (_fuchsiaProjectPath == null)
|
||||
throwToolExit('Provide the mod project path with --path.');
|
||||
if (!_directoryExists(_fuchsiaProjectPath))
|
||||
throwToolExit('Target does not exist in the Fuchsia tree: $_fuchsiaProjectPath.');
|
||||
throwToolExit('Cannot locate project at $_fuchsiaProjectPath.');
|
||||
|
||||
final String relativeTarget = argResults['target'];
|
||||
if (relativeTarget == null)
|
||||
|
@ -321,18 +358,19 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
|||
if (!_fileExists(_target))
|
||||
throwToolExit('Couldn\'t find application entry point at $_target.');
|
||||
|
||||
final String nameOverride = argResults['name-override'];
|
||||
if (nameOverride == null) {
|
||||
_binaryName = _projectName;
|
||||
} else {
|
||||
_binaryName = nameOverride;
|
||||
}
|
||||
if (argResults['mod-name'] != null)
|
||||
_modName = argResults['mod-name'];
|
||||
if (_modName == null)
|
||||
throwToolExit('Provide the mod name with --mod-name.');
|
||||
|
||||
// When there's an override of the on-device binary name, use that name
|
||||
// to locate the .packages file.
|
||||
final String packagesFileName = '${_binaryName}_dart_library.packages';
|
||||
_dotPackagesPath = '$_buildDir/dartlang/gen/$_projectRoot/$packagesFileName';
|
||||
printTrace('_dotPackagesPath is $_dotPackagesPath');
|
||||
if (argResults['dot-packages'] != null) {
|
||||
_dotPackagesPath = argResults['dot-packages'];
|
||||
} else if (fuchsiaBuildDir != null) {
|
||||
final String packagesFileName = '${_modName}_dart_library.packages';
|
||||
_dotPackagesPath = '$fuchsiaBuildDir/dartlang/gen/$projectRoot/$packagesFileName';
|
||||
}
|
||||
if (_dotPackagesPath == null)
|
||||
throwToolExit('Provide the .packages path with --dot-packages.');
|
||||
if (!_fileExists(_dotPackagesPath))
|
||||
throwToolExit('Couldn\'t find .packages file at $_dotPackagesPath.');
|
||||
|
||||
|
@ -361,11 +399,10 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
|||
}
|
||||
|
||||
Future<List<_PortForwarder>> _forwardPorts(List<int> remotePorts) async {
|
||||
final String config = '$_buildDir/ssh-keys/ssh_config';
|
||||
final List<_PortForwarder> forwarders = <_PortForwarder>[];
|
||||
for (int port in remotePorts) {
|
||||
final _PortForwarder f =
|
||||
await _PortForwarder.start(config, _address, port);
|
||||
await _PortForwarder.start(_sshConfig, _address, port);
|
||||
forwarders.add(f);
|
||||
}
|
||||
return forwarders;
|
||||
|
@ -373,7 +410,7 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
|||
|
||||
Future<List<int>> _getServicePorts() async {
|
||||
final FuchsiaDeviceCommandRunner runner =
|
||||
FuchsiaDeviceCommandRunner(_address, _buildDir);
|
||||
FuchsiaDeviceCommandRunner(_address, _sshConfig);
|
||||
final List<String> lsOutput = await runner.run('ls /tmp/dart.services');
|
||||
final List<int> ports = <int>[];
|
||||
if (lsOutput != null) {
|
||||
|
@ -483,13 +520,12 @@ class _PortForwarder {
|
|||
|
||||
class FuchsiaDeviceCommandRunner {
|
||||
final String _address;
|
||||
final String _buildDir;
|
||||
final String _sshConfig;
|
||||
|
||||
FuchsiaDeviceCommandRunner(this._address, this._buildDir);
|
||||
FuchsiaDeviceCommandRunner(this._address, this._sshConfig);
|
||||
|
||||
Future<List<String>> run(String command) async {
|
||||
final String config = '$_buildDir/ssh-keys/ssh_config';
|
||||
final List<String> args = <String>['ssh', '-F', config, _address, command];
|
||||
final List<String> args = <String>['ssh', '-F', _sshConfig, _address, command];
|
||||
printTrace(args.join(' '));
|
||||
final ProcessResult result = await processManager.run(args);
|
||||
if (result.exitCode != 0) {
|
||||
|
|
Loading…
Reference in a new issue