Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/fuchsia_ctl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# CHANGELOG

## 0.0.23

- Added `emu` tool for spawning an emulator instance given a Fuchsia QEMU build,
the Fuchsia SDK, and an Android emulator executable.
- Fixed homepage link.

## 0.0.18 - 0.0.21
## 0.0.18 - 0.0.22

- Add retries to paving operations.
- Add timeouts to paving and ssh operations.
- Add arguments parameter to test command.



## 0.0.17

- Add "push-packages" option.
Expand Down
44 changes: 40 additions & 4 deletions packages/fuchsia_ctl/bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ import 'dart:io';
import 'package:args/args.dart';
import 'package:file/file.dart';
import 'package:file/local.dart';
import 'package:fuchsia_ctl/fuchsia_ctl.dart';
import 'package:fuchsia_ctl/src/amber_ctl.dart';
import 'package:fuchsia_ctl/src/operation_result.dart';
import 'package:fuchsia_ctl/src/tar.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as path;
import 'package:retry/retry.dart';
import 'package:uuid/uuid.dart';

import 'package:fuchsia_ctl/fuchsia_ctl.dart';

typedef AsyncResult = Future<OperationResult> Function(
String, DevFinder, ArgResults);

const Map<String, AsyncResult> commands = <String, AsyncResult>{
'emu': emulator,
'pave': pave,
'pm': pm,
'ssh': ssh,
Expand All @@ -42,6 +41,21 @@ Future<void> main(List<String> args) async {
defaultsTo: './dev_finder',
help: 'The path to the dev_finder executable.')
..addFlag('help', defaultsTo: false, help: 'Prints help.');

parser.addCommand('emu')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a blocking command? e.g it will remain running until calling ctrl+c?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's blocking. Should that be documented?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in the code. I couldn't find a way to configure it to show with ArgParser

..addOption('image', help: 'Fuchsia image to run')
..addOption('zbi', help: 'Bootloader image to sign and run')
..addOption('qemu-kernel', help: 'QEMU kernel to run')
..addOption('window-size', help: 'Emulator window size formatted "WxH"')
..addOption('aemu', help: 'AEMU executable path')
..addOption('sdk',
help: 'Location to Fuchsia SDK containing tools and images')
..addOption('public-key',
abbr: 'p',
defaultsTo: '.fuchsia/authorized_keys',
help: 'Path to the authorized_keys to sign zbi image with')
..addFlag('headless', help: 'Run FEMU without graphical window');

parser.addCommand('ssh')
..addFlag('interactive',
abbr: 'i',
Expand Down Expand Up @@ -129,6 +143,28 @@ Future<void> main(List<String> args) async {
}
}

@visibleForTesting
Future<OperationResult> emulator(
String deviceName,
DevFinder devFinder,
ArgResults args,
) async {
final Emulator emulator = Emulator(
aemuPath: args['aemu'],
fuchsiaImagePath: args['image'],
fuchsiaSdkPath: args['sdk'],
qemuKernelPath: args['qemu-kernel'],
authorizedKeysPath: args['public-key'],
zbiPath: args['zbi'],
);
await emulator.prepareEnvironment();

return emulator.start(
headless: args['headless'],
windowSize: args['window-size'],
);
}

@visibleForTesting
Future<OperationResult> ssh(
String deviceName,
Expand Down
3 changes: 3 additions & 0 deletions packages/fuchsia_ctl/lib/fuchsia_ctl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'src/amber_ctl.dart';
export 'src/dev_finder.dart';
export 'src/emulator.dart';
export 'src/image_paver.dart';
export 'src/operation_result.dart';
export 'src/package_server.dart';
export 'src/ssh_client.dart';
export 'src/tar.dart';
4 changes: 1 addition & 3 deletions packages/fuchsia_ctl/lib/src/amber_ctl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import 'dart:io';

import 'package:meta/meta.dart';
import 'package:fuchsia_ctl/fuchsia_ctl.dart';
import 'package:fuchsia_ctl/src/ssh_client.dart';
import 'package:uuid/uuid.dart';

import 'operation_result.dart';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't needed anymore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was clean up as it was already imported from the high level fuchsia_ctl since this imports the ssh class.

import 'package:fuchsia_ctl/fuchsia_ctl.dart';

const SshClient _kSsh = SshClient();

Expand Down
81 changes: 81 additions & 0 deletions packages/fuchsia_ctl/lib/src/command_line.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2020 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io';

import 'package:meta/meta.dart';
import 'package:process/process.dart';

/// Class for common actions with processes on the command line.
@immutable
class CommandLine {
/// Create a new instance of [CommandLine].
const CommandLine(
{this.processManager = const LocalProcessManager(),
@visibleForTesting this.stdoutValue,
@visibleForTesting this.stderrValue});

/// The underlying [ProcessManager] to use for running on the current shell.
final ProcessManager processManager;

/// Mock value for use in tests.
final Stdout stdoutValue;

/// Mock value for use in tests.
final Stdout stderrValue;

/// Current shells stdout to use.
Stdout get shellStdout => stdoutValue ?? stdout;

/// Current shells stderr to use.
Stdout get shellStderr => stderrValue ?? stderr;

/// Run [command] and handle its stdio. Once [command] is complete, it will
/// output its stdio to the console.
///
/// Use this for tasks where stdio does not need to be monitored.
///
/// Throw [CommandLineException] if [command] returns a non-0 exit code.
Future<void> run(List<String> command) async {
shellStdout.writeln(command.join(' '));
final ProcessResult process = await processManager.run(command);
shellStdout.writeln(process.stdout);
shellStderr.writeln(process.stderr);

if (process.exitCode != 0) {
throw CommandLineException('${command.first} did not return exit code 0');
}
}

/// Start [command] and handle its stdio by streaming it to the existing
/// stdio. While [command] is running, its stdio is streamed to the shell.
///
/// Use this for long running tasks where stdio should be monitored.
///
/// Throw [CommandLineException] if [command] returns a non-0 exit code.
Future<Process> start(List<String> command) async {
shellStdout.writeln(command.join(' '));
final Process process = await processManager.start(command);
shellStdout.addStream(process.stdout);
shellStderr.addStream(process.stderr);

if (await process.exitCode != 0) {
throw CommandLineException('${command.first} did not return exit code 0');
}

return process;
}
}

/// Wraps exceptions thrown by [CommandLine].
class CommandLineException implements Exception {
/// Creates a new [CommandLineException].
const CommandLineException(this.message);

/// The user-facing message to display.
final String message;

@override
String toString() => message;
}
11 changes: 8 additions & 3 deletions packages/fuchsia_ctl/lib/src/dev_finder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@ class DevFinder {
}
final List<String> command = <String>[
devFinderPath,
if (deviceName != null) 'resolve' else 'list',
if (deviceName != null)
'resolve'
else
'list',
'-device-limit', '1', //
if (local) '-local',
if (deviceName != null) deviceName,
if (local)
'-local',
if (deviceName != null)
deviceName,
];

for (int i = 0; i < numTries; i++) {
Expand Down
Loading