Add flutter run support for linux and windows (#31229)
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
// Copyright 2019 The Chromium 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 'package:meta/meta.dart';
|
||||
|
||||
import '../application_package.dart';
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../build_info.dart';
|
||||
import '../project.dart';
|
||||
|
||||
abstract class LinuxApp extends ApplicationPackage {
|
||||
LinuxApp({@required String projectBundleId}) : super(id: projectBundleId);
|
||||
|
||||
/// Creates a new [LinuxApp] from a linux sub project.
|
||||
factory LinuxApp.fromLinuxProject(LinuxProject project) {
|
||||
return BuildableLinuxApp(
|
||||
project: project,
|
||||
);
|
||||
}
|
||||
|
||||
/// Creates a new [LinuxApp] from an existing executable.
|
||||
///
|
||||
/// `applicationBinary` is the path to the executable.
|
||||
factory LinuxApp.fromPrebuiltApp(FileSystemEntity applicationBinary) {
|
||||
return PrebuiltLinuxApp(
|
||||
executable: applicationBinary.path,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String get displayName => id;
|
||||
|
||||
String executable(BuildMode buildMode);
|
||||
}
|
||||
|
||||
class PrebuiltLinuxApp extends LinuxApp {
|
||||
PrebuiltLinuxApp({
|
||||
@required String executable,
|
||||
}) : _executable = executable,
|
||||
super(projectBundleId: executable);
|
||||
|
||||
final String _executable;
|
||||
|
||||
@override
|
||||
String executable(BuildMode buildMode) => _executable;
|
||||
|
||||
@override
|
||||
String get name => _executable;
|
||||
}
|
||||
|
||||
class BuildableLinuxApp extends LinuxApp {
|
||||
BuildableLinuxApp({this.project}) : super(projectBundleId: project.project.manifest.appName);
|
||||
|
||||
final LinuxProject project;
|
||||
|
||||
@override
|
||||
String executable(BuildMode buildMode) {
|
||||
final ProcessResult result = processManager.runSync(<String>[
|
||||
project.nameScript.path,
|
||||
buildMode == BuildMode.debug ? 'debug' : 'release',
|
||||
]);
|
||||
if (result.exitCode != 0) {
|
||||
throwToolExit('Failed to find Linux project name');
|
||||
}
|
||||
return result.stdout.toString().trim();
|
||||
}
|
||||
|
||||
@override
|
||||
String get name => project.project.manifest.appName;
|
||||
}
|
||||
44
packages/flutter_tools/lib/src/linux/build_linux.dart
Normal file
44
packages/flutter_tools/lib/src/linux/build_linux.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2019 The Chromium 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 '../base/common.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import '../convert.dart';
|
||||
import '../globals.dart';
|
||||
import '../project.dart';
|
||||
|
||||
/// Builds the Linux project through the project shell script.
|
||||
Future<void> buildLinux(LinuxProject linuxProject, BuildInfo buildInfo) async {
|
||||
final Process process = await processManager.start(<String>[
|
||||
linuxProject.buildScript.path,
|
||||
Cache.flutterRoot,
|
||||
buildInfo?.isDebug == true ? 'debug' : 'release',
|
||||
buildInfo?.trackWidgetCreation == true ? 'track-widget-creation' : 'no-track-widget-creation',
|
||||
], runInShell: true);
|
||||
final Status status = logger.startProgress(
|
||||
'Building Linux application...',
|
||||
timeout: null,
|
||||
);
|
||||
int result;
|
||||
try {
|
||||
process.stderr
|
||||
.transform(utf8.decoder)
|
||||
.transform(const LineSplitter())
|
||||
.listen(printError);
|
||||
process.stdout
|
||||
.transform(utf8.decoder)
|
||||
.transform(const LineSplitter())
|
||||
.listen(printTrace);
|
||||
result = await process.exitCode;
|
||||
} finally {
|
||||
status.cancel();
|
||||
}
|
||||
if (result != 0) {
|
||||
throwToolExit('Build process failed');
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,19 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import '../application_package.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/os.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../build_info.dart';
|
||||
import '../convert.dart';
|
||||
import '../desktop.dart';
|
||||
import '../device.dart';
|
||||
import '../globals.dart';
|
||||
import '../project.dart';
|
||||
import '../protocol_discovery.dart';
|
||||
import 'application_package.dart';
|
||||
import 'build_linux.dart';
|
||||
import 'linux_workflow.dart';
|
||||
|
||||
/// A device that represents a desktop Linux target.
|
||||
@@ -19,20 +28,20 @@ class LinuxDevice extends Device {
|
||||
@override
|
||||
DeviceLogReader getLogReader({ ApplicationPackage app }) => NoOpDeviceLogReader('linux');
|
||||
|
||||
// Since the host and target devices are the same, no work needs to be done
|
||||
// to install the application.
|
||||
@override
|
||||
Future<bool> installApp(ApplicationPackage app) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
Future<bool> installApp(ApplicationPackage app) async => true;
|
||||
|
||||
// Since the host and target devices are the same, no work needs to be done
|
||||
// to install the application.
|
||||
@override
|
||||
Future<bool> isAppInstalled(ApplicationPackage app) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
Future<bool> isAppInstalled(ApplicationPackage app) async => true;
|
||||
|
||||
// Since the host and target devices are the same, no work needs to be done
|
||||
// to install the application.
|
||||
@override
|
||||
Future<bool> isLatestBuildInstalled(ApplicationPackage app) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
Future<bool> isLatestBuildInstalled(ApplicationPackage app) async => true;
|
||||
|
||||
@override
|
||||
Future<bool> get isLocalEmulator async => false;
|
||||
@@ -51,7 +60,7 @@ class LinuxDevice extends Device {
|
||||
|
||||
@override
|
||||
Future<LaunchResult> startApp(
|
||||
ApplicationPackage package, {
|
||||
covariant LinuxApp package, {
|
||||
String mainPath,
|
||||
String route,
|
||||
DebuggingOptions debuggingOptions,
|
||||
@@ -59,22 +68,43 @@ class LinuxDevice extends Device {
|
||||
bool prebuiltApplication = false,
|
||||
bool usesTerminalUi = true,
|
||||
bool ipv6 = false,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}) async {
|
||||
if (!prebuiltApplication) {
|
||||
await buildLinux((await FlutterProject.current()).linux, debuggingOptions.buildInfo);
|
||||
}
|
||||
await stopApp(package);
|
||||
final Process process = await processManager.start(<String>[
|
||||
package.executable(debuggingOptions?.buildInfo?.mode)
|
||||
]);
|
||||
if (debuggingOptions?.buildInfo?.isRelease == true) {
|
||||
return LaunchResult.succeeded();
|
||||
}
|
||||
final LinuxLogReader logReader = LinuxLogReader(package, process);
|
||||
final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(logReader);
|
||||
try {
|
||||
final Uri observatoryUri = await observatoryDiscovery.uri;
|
||||
return LaunchResult.succeeded(observatoryUri: observatoryUri);
|
||||
} catch (error) {
|
||||
printError('Error waiting for a debug connection: $error');
|
||||
return LaunchResult.failed();
|
||||
} finally {
|
||||
await observatoryDiscovery.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> stopApp(ApplicationPackage app) {
|
||||
throw UnimplementedError();
|
||||
Future<bool> stopApp(covariant LinuxApp app) async {
|
||||
// Assume debug for now.
|
||||
return killProcess(app.executable(BuildMode.debug));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TargetPlatform> get targetPlatform async => TargetPlatform.linux_x64;
|
||||
|
||||
// Since the host and target devices are the same, no work needs to be done
|
||||
// to uninstall the application.
|
||||
@override
|
||||
Future<bool> uninstallApp(ApplicationPackage app) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
Future<bool> uninstallApp(ApplicationPackage app) async => true;
|
||||
}
|
||||
|
||||
class LinuxDevices extends PollingDeviceDiscovery {
|
||||
@@ -99,3 +129,18 @@ class LinuxDevices extends PollingDeviceDiscovery {
|
||||
@override
|
||||
Future<List<String>> getDiagnostics() async => const <String>[];
|
||||
}
|
||||
|
||||
class LinuxLogReader extends DeviceLogReader {
|
||||
LinuxLogReader(this.linuxApp, this.process);
|
||||
|
||||
final LinuxApp linuxApp;
|
||||
final Process process;
|
||||
|
||||
@override
|
||||
Stream<String> get logLines {
|
||||
return process.stdout.transform(utf8.decoder);
|
||||
}
|
||||
|
||||
@override
|
||||
String get name => linuxApp.displayName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user