Unverified Commit 61236c87 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool] In 'attach' use platform dill and patched sdk dir from the Fuchsia SDK (#32071)

parent dd5d0d6c
...@@ -6,7 +6,9 @@ import 'dart:async'; ...@@ -6,7 +6,9 @@ import 'dart:async';
import 'package:multicast_dns/multicast_dns.dart'; import 'package:multicast_dns/multicast_dns.dart';
import '../artifacts.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/context.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart'; import '../base/io.dart';
import '../base/utils.dart'; import '../base/utils.dart';
...@@ -160,8 +162,6 @@ class AttachCommand extends FlutterCommand { ...@@ -160,8 +162,6 @@ class AttachCommand extends FlutterCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
final FlutterProject flutterProject = FlutterProject.current();
Cache.releaseLockEarly(); Cache.releaseLockEarly();
await _validateArguments(); await _validateArguments();
...@@ -169,6 +169,19 @@ class AttachCommand extends FlutterCommand { ...@@ -169,6 +169,19 @@ class AttachCommand extends FlutterCommand {
writePidFile(argResults['pid-file']); writePidFile(argResults['pid-file']);
final Device device = await findTargetDevice(); final Device device = await findTargetDevice();
final Artifacts artifacts = device.artifactOverrides ?? Artifacts.instance;
await context.run<void>(
body: () => _attachToDevice(device),
overrides: <Type, Generator>{
Artifacts: () => artifacts,
});
return null;
}
Future<void> _attachToDevice(Device device) async {
final FlutterProject flutterProject = FlutterProject.current();
Future<int> getDevicePort() async { Future<int> getDevicePort() async {
if (debugPort != null) { if (debugPort != null) {
return debugPort; return debugPort;
...@@ -310,7 +323,6 @@ class AttachCommand extends FlutterCommand { ...@@ -310,7 +323,6 @@ class AttachCommand extends FlutterCommand {
await device.portForwarder.unforward(port); await device.portForwarder.unforward(port);
} }
} }
return null;
} }
Future<void> _validateArguments() async { } Future<void> _validateArguments() async { }
......
...@@ -7,6 +7,7 @@ import 'dart:math' as math; ...@@ -7,6 +7,7 @@ import 'dart:math' as math;
import 'android/android_device.dart'; import 'android/android_device.dart';
import 'application_package.dart'; import 'application_package.dart';
import 'artifacts.dart';
import 'base/context.dart'; import 'base/context.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
import 'base/utils.dart'; import 'base/utils.dart';
...@@ -274,6 +275,9 @@ abstract class Device { ...@@ -274,6 +275,9 @@ abstract class Device {
/// Clear the device's logs. /// Clear the device's logs.
void clearLogs(); void clearLogs();
/// Optional device-specific artifact overrides.
OverrideArtifacts get artifactOverrides => null;
/// Start an app package on the current device. /// Start an app package on the current device.
/// ///
/// [platformArgs] allows callers to pass platform-specific arguments to the /// [platformArgs] allows callers to pass platform-specific arguments to the
......
...@@ -7,6 +7,7 @@ import 'dart:async'; ...@@ -7,6 +7,7 @@ import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import '../application_package.dart'; import '../application_package.dart';
import '../artifacts.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/io.dart'; import '../base/io.dart';
import '../base/logger.dart'; import '../base/logger.dart';
...@@ -223,6 +224,16 @@ class FuchsiaDevice extends Device { ...@@ -223,6 +224,16 @@ class FuchsiaDevice extends Device {
@override @override
void clearLogs() {} void clearLogs() {}
@override
OverrideArtifacts get artifactOverrides {
return _artifactOverrides ??= OverrideArtifacts(
parent: Artifacts.instance,
platformKernelDill: fuchsiaArtifacts.platformKernelDill,
flutterPatchedSdk: fuchsiaArtifacts.flutterPatchedSdk,
);
}
OverrideArtifacts _artifactOverrides;
@override @override
bool get supportsScreenshot => false; bool get supportsScreenshot => false;
......
...@@ -81,7 +81,12 @@ class FuchsiaSdk { ...@@ -81,7 +81,12 @@ class FuchsiaSdk {
/// Fuchsia-specific artifacts used to interact with a device. /// Fuchsia-specific artifacts used to interact with a device.
class FuchsiaArtifacts { class FuchsiaArtifacts {
/// Creates a new [FuchsiaArtifacts]. /// Creates a new [FuchsiaArtifacts].
FuchsiaArtifacts({this.sshConfig, this.devFinder}); FuchsiaArtifacts({
this.sshConfig,
this.devFinder,
this.platformKernelDill,
this.flutterPatchedSdk,
});
/// Creates a new [FuchsiaArtifacts] using the cached Fuchsia SDK. /// Creates a new [FuchsiaArtifacts] using the cached Fuchsia SDK.
/// ///
...@@ -92,6 +97,7 @@ class FuchsiaArtifacts { ...@@ -92,6 +97,7 @@ class FuchsiaArtifacts {
factory FuchsiaArtifacts.find() { factory FuchsiaArtifacts.find() {
final String fuchsia = Cache.instance.getArtifactDirectory('fuchsia').path; final String fuchsia = Cache.instance.getArtifactDirectory('fuchsia').path;
final String tools = fs.path.join(fuchsia, 'tools'); final String tools = fs.path.join(fuchsia, 'tools');
final String dartPrebuilts = fs.path.join(tools, 'dart_prebuilts');
// If FUCHSIA_BUILD_DIR is defined, then look for the ssh_config dir // If FUCHSIA_BUILD_DIR is defined, then look for the ssh_config dir
// relative to it. Next, if FUCHSIA_SSH_CONFIG is defined, then use it. // relative to it. Next, if FUCHSIA_SSH_CONFIG is defined, then use it.
...@@ -99,13 +105,17 @@ class FuchsiaArtifacts { ...@@ -99,13 +105,17 @@ class FuchsiaArtifacts {
File sshConfig; File sshConfig;
if (platform.environment.containsKey(_kFuchsiaBuildDir)) { if (platform.environment.containsKey(_kFuchsiaBuildDir)) {
sshConfig = fs.file(fs.path.join( sshConfig = fs.file(fs.path.join(
platform.environment[_kFuchsiaSshConfig], 'ssh-keys', 'ssh_config')); platform.environment[_kFuchsiaBuildDir], 'ssh-keys', 'ssh_config'));
} else if (platform.environment.containsKey(_kFuchsiaSshConfig)) { } else if (platform.environment.containsKey(_kFuchsiaSshConfig)) {
sshConfig = fs.file(platform.environment[_kFuchsiaSshConfig]); sshConfig = fs.file(platform.environment[_kFuchsiaSshConfig]);
} }
return FuchsiaArtifacts( return FuchsiaArtifacts(
sshConfig: sshConfig, sshConfig: sshConfig,
devFinder: fs.file(fs.path.join(tools, 'dev_finder')), devFinder: fs.file(fs.path.join(tools, 'dev_finder')),
platformKernelDill: fs.file(fs.path.join(
dartPrebuilts, 'flutter_runner', 'platform_strong.dill')),
flutterPatchedSdk: fs.file(fs.path.join(
dartPrebuilts, 'flutter_runner')),
); );
} }
...@@ -119,4 +129,10 @@ class FuchsiaArtifacts { ...@@ -119,4 +129,10 @@ class FuchsiaArtifacts {
/// The location of the dev finder tool used to locate connected /// The location of the dev finder tool used to locate connected
/// Fuchsia devices. /// Fuchsia devices.
final File devFinder; final File devFinder;
/// The location of the Fuchsia-specific platform dill.
final File platformKernelDill;
/// The directory containing [platformKernelDill].
final File flutterPatchedSdk;
} }
...@@ -10,7 +10,9 @@ import 'package:flutter_tools/src/vmservice.dart'; ...@@ -10,7 +10,9 @@ import 'package:flutter_tools/src/vmservice.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/time.dart'; import 'package:flutter_tools/src/base/time.dart';
...@@ -58,10 +60,74 @@ void main() { ...@@ -58,10 +60,74 @@ void main() {
}); });
}); });
group('Fuchsia device artifact overrides', () {
MockFile devFinder;
MockFile sshConfig;
MockFile platformDill;
MockFile patchedSdk;
setUp(() {
devFinder = MockFile();
sshConfig = MockFile();
platformDill = MockFile();
patchedSdk = MockFile();
when(devFinder.absolute).thenReturn(devFinder);
when(sshConfig.absolute).thenReturn(sshConfig);
when(platformDill.absolute).thenReturn(platformDill);
when(patchedSdk.absolute).thenReturn(patchedSdk);
});
testUsingContext('exist', () async {
final FuchsiaDevice device = FuchsiaDevice('fuchsia-device');
expect(device.artifactOverrides, isNotNull);
expect(device.artifactOverrides.platformKernelDill, equals(platformDill));
expect(device.artifactOverrides.flutterPatchedSdk, equals(patchedSdk));
}, overrides: <Type, Generator>{
FuchsiaArtifacts: () => FuchsiaArtifacts(
sshConfig: sshConfig,
devFinder: devFinder,
platformKernelDill: platformDill,
flutterPatchedSdk: patchedSdk,
),
});
testUsingContext('are used', () async {
final FuchsiaDevice device = FuchsiaDevice('fuchsia-device');
expect(device.artifactOverrides, isNotNull);
expect(device.artifactOverrides.platformKernelDill, equals(platformDill));
expect(device.artifactOverrides.flutterPatchedSdk, equals(patchedSdk));
await context.run<void>(
body: () {
expect(Artifacts.instance.getArtifactPath(Artifact.platformKernelDill),
equals(platformDill.path));
expect(Artifacts.instance.getArtifactPath(Artifact.flutterPatchedSdkPath),
equals(patchedSdk.path));
},
overrides: <Type, Generator>{
Artifacts: () => device.artifactOverrides,
},
);
}, overrides: <Type, Generator>{
FuchsiaArtifacts: () => FuchsiaArtifacts(
sshConfig: sshConfig,
devFinder: devFinder,
platformKernelDill: platformDill,
flutterPatchedSdk: patchedSdk,
),
});
});
group('displays friendly error when', () { group('displays friendly error when', () {
final MockProcessManager mockProcessManager = MockProcessManager(); MockProcessManager mockProcessManager;
final MockProcessResult mockProcessResult = MockProcessResult(); MockProcessResult mockProcessResult;
final MockFile mockFile = MockFile(); MockFile mockFile;
MockProcessManager emptyStdoutProcessManager;
MockProcessResult emptyStdoutProcessResult;
setUp(() {
mockProcessManager = MockProcessManager();
mockProcessResult = MockProcessResult();
mockFile = MockFile();
when(mockProcessManager.run( when(mockProcessManager.run(
any, any,
environment: anyNamed('environment'), environment: anyNamed('environment'),
...@@ -74,8 +140,8 @@ void main() { ...@@ -74,8 +140,8 @@ void main() {
when(mockFile.absolute).thenReturn(mockFile); when(mockFile.absolute).thenReturn(mockFile);
when(mockFile.path).thenReturn(''); when(mockFile.path).thenReturn('');
final MockProcessManager emptyStdoutProcessManager = MockProcessManager(); emptyStdoutProcessManager = MockProcessManager();
final MockProcessResult emptyStdoutProcessResult = MockProcessResult(); emptyStdoutProcessResult = MockProcessResult();
when(emptyStdoutProcessManager.run( when(emptyStdoutProcessManager.run(
any, any,
environment: anyNamed('environment'), environment: anyNamed('environment'),
...@@ -85,6 +151,7 @@ void main() { ...@@ -85,6 +151,7 @@ void main() {
when(emptyStdoutProcessResult.exitCode).thenReturn(0); when(emptyStdoutProcessResult.exitCode).thenReturn(0);
when<String>(emptyStdoutProcessResult.stdout).thenReturn(''); when<String>(emptyStdoutProcessResult.stdout).thenReturn('');
when<String>(emptyStdoutProcessResult.stderr).thenReturn(''); when<String>(emptyStdoutProcessResult.stderr).thenReturn('');
});
testUsingContext('No vmservices found', () async { testUsingContext('No vmservices found', () async {
final FuchsiaDevice device = FuchsiaDevice('id'); final FuchsiaDevice device = FuchsiaDevice('id');
...@@ -116,26 +183,29 @@ void main() { ...@@ -116,26 +183,29 @@ void main() {
[2018-11-09 01:30:12][52580][52983][log] INFO: example_app.cmx(flutter): Did thing this time [2018-11-09 01:30:12][52580][52983][log] INFO: example_app.cmx(flutter): Did thing this time
'''; ''';
final MockProcessManager mockProcessManager = MockProcessManager(); MockProcessManager mockProcessManager;
final MockProcess mockProcess = MockProcess(); MockProcess mockProcess;
Completer<int> exitCode; Completer<int> exitCode;
StreamController<List<int>> stdout; StreamController<List<int>> stdout;
StreamController<List<int>> stderr; StreamController<List<int>> stderr;
MockFile devFinder;
MockFile sshConfig;
setUp(() {
mockProcessManager = MockProcessManager();
mockProcess = MockProcess();
stdout = StreamController<List<int>>(sync: true);
stderr = StreamController<List<int>>(sync: true);
exitCode = Completer<int>();
when(mockProcessManager.start(any)) when(mockProcessManager.start(any))
.thenAnswer((Invocation _) => Future<Process>.value(mockProcess)); .thenAnswer((Invocation _) => Future<Process>.value(mockProcess));
when(mockProcess.exitCode).thenAnswer((Invocation _) => exitCode.future); when(mockProcess.exitCode).thenAnswer((Invocation _) => exitCode.future);
when(mockProcess.stdout).thenAnswer((Invocation _) => stdout.stream); when(mockProcess.stdout).thenAnswer((Invocation _) => stdout.stream);
when(mockProcess.stderr).thenAnswer((Invocation _) => stderr.stream); when(mockProcess.stderr).thenAnswer((Invocation _) => stderr.stream);
devFinder = MockFile();
final MockFile devFinder = MockFile(); sshConfig = MockFile();
final MockFile sshConfig = MockFile();
when(devFinder.absolute).thenReturn(devFinder); when(devFinder.absolute).thenReturn(devFinder);
when(sshConfig.absolute).thenReturn(sshConfig); when(sshConfig.absolute).thenReturn(sshConfig);
setUp(() {
stdout = StreamController<List<int>>(sync: true);
stderr = StreamController<List<int>>(sync: true);
exitCode = Completer<int>();
}); });
tearDown(() { tearDown(() {
......
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