Unverified Commit e819f292 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] do not require a dependency on devtools server (#66842)

Re-arrange the implementation of the devtools launcher so that google3 is not required to depend on any devtools packages. Also renames the build_runner folders to isolated to better clarify their intention.
parent e8fbb43a
...@@ -9,13 +9,7 @@ import 'src/base/context.dart'; ...@@ -9,13 +9,7 @@ import 'src/base/context.dart';
import 'src/base/io.dart'; import 'src/base/io.dart';
import 'src/base/logger.dart'; import 'src/base/logger.dart';
import 'src/base/template.dart'; import 'src/base/template.dart';
// The build_runner code generation is provided here to make it easier to
// avoid introducing the dependency into google3. Not all build* packages
// are synced internally.
import 'src/base/terminal.dart'; import 'src/base/terminal.dart';
import 'src/build_runner/mustache_template.dart';
import 'src/build_runner/resident_web_runner.dart';
import 'src/build_runner/web_compilation_delegate.dart';
import 'src/commands/analyze.dart'; import 'src/commands/analyze.dart';
import 'src/commands/assemble.dart'; import 'src/commands/assemble.dart';
import 'src/commands/attach.dart'; import 'src/commands/attach.dart';
...@@ -51,6 +45,12 @@ import 'src/commands/upgrade.dart'; ...@@ -51,6 +45,12 @@ import 'src/commands/upgrade.dart';
import 'src/commands/version.dart'; import 'src/commands/version.dart';
import 'src/features.dart'; import 'src/features.dart';
import 'src/globals.dart' as globals; import 'src/globals.dart' as globals;
// Files in `isolated` are intentionally excluded from google3 tooling.
import 'src/isolated/devtools_launcher.dart';
import 'src/isolated/mustache_template.dart';
import 'src/isolated/resident_web_runner.dart';
import 'src/isolated/web_compilation_delegate.dart';
import 'src/resident_runner.dart';
import 'src/runner/flutter_command.dart'; import 'src/runner/flutter_command.dart';
import 'src/web/compile.dart'; import 'src/web/compile.dart';
import 'src/web/web_runner.dart'; import 'src/web/web_runner.dart';
...@@ -136,6 +136,9 @@ Future<void> main(List<String> args) async { ...@@ -136,6 +136,9 @@ Future<void> main(List<String> args) async {
WebRunnerFactory: () => DwdsWebRunnerFactory(), WebRunnerFactory: () => DwdsWebRunnerFactory(),
// The mustache dependency is different in google3 // The mustache dependency is different in google3
TemplateRenderer: () => const MustacheTemplateRenderer(), TemplateRenderer: () => const MustacheTemplateRenderer(),
// The devtools launcher is not supported in google3 because it depends on
// devtools source code.
DevtoolsLauncher: () => DevtoolsServerLauncher(logger: globals.logger),
Logger: () { Logger: () {
final LoggerFactory loggerFactory = LoggerFactory( final LoggerFactory loggerFactory = LoggerFactory(
outputPreferences: globals.outputPreferences, outputPreferences: globals.outputPreferences,
...@@ -153,7 +156,6 @@ Future<void> main(List<String> args) async { ...@@ -153,7 +156,6 @@ Future<void> main(List<String> args) async {
}); });
} }
/// An abstraction for instantiation of the correct logger type. /// An abstraction for instantiation of the correct logger type.
/// ///
/// Our logger class hierarchy and runtime requirements are overly complicated. /// Our logger class hierarchy and runtime requirements are overly complicated.
......
// Copyright 2014 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 'package:devtools_server/devtools_server.dart' as devtools_server;
import 'package:meta/meta.dart';
import '../base/io.dart' as io;
import '../base/logger.dart';
import '../resident_runner.dart';
/// An implementation of the devtools launcher that uses the server package.
///
/// This is implemented in isolated to prevent the flutter_tool from needing
/// a devtools dep in google3.
class DevtoolsServerLauncher extends DevtoolsLauncher {
DevtoolsServerLauncher({
@required Logger logger,
}) : _logger = logger;
final Logger _logger;
io.HttpServer _devtoolsServer;
@override
Future<void> launch(Uri observatoryAddress) async {
try {
await serve();
await devtools_server.launchDevTools(
<String, dynamic>{
'reuseWindows': true,
},
observatoryAddress,
'http://${_devtoolsServer.address.host}:${_devtoolsServer.port}',
false, // headless mode,
false, // machine mode
);
} on Exception catch (e, st) {
_logger.printTrace('Failed to launch DevTools: $e\n$st');
}
}
@override
Future<DevToolsServerAddress> serve() async {
try {
_devtoolsServer ??= await devtools_server.serveDevTools(
enableStdinCommands: false,
);
return DevToolsServerAddress(_devtoolsServer.address.host, _devtoolsServer.port);
} on Exception catch (e, st) {
_logger.printTrace('Failed to serve DevTools: $e\n$st');
return null;
}
}
@override
Future<void> close() async {
await _devtoolsServer?.close();
_devtoolsServer = null;
}
}
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
import 'dart:async'; import 'dart:async';
import 'package:devtools_server/devtools_server.dart' as devtools_server;
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart'; import 'package:package_config/package_config.dart';
import 'package:vm_service/vm_service.dart' as vm_service; import 'package:vm_service/vm_service.dart' as vm_service;
...@@ -1703,43 +1702,15 @@ String nextPlatform(String currentPlatform, FeatureFlags featureFlags) { ...@@ -1703,43 +1702,15 @@ String nextPlatform(String currentPlatform, FeatureFlags featureFlags) {
} }
} }
class DevtoolsLauncher { /// A launcher for the devtools debugger and analysis tool.
io.HttpServer _devtoolsServer; abstract class DevtoolsLauncher {
Future<void> launch(Uri observatoryAddress) async { Future<void> launch(Uri observatoryAddress);
try {
await serve();
await devtools_server.launchDevTools(
<String, dynamic>{
'reuseWindows': true,
},
observatoryAddress,
'http://${_devtoolsServer.address.host}:${_devtoolsServer.port}',
false, // headless mode,
false, // machine mode
);
} on Exception catch (e, st) {
globals.printTrace('Failed to launch DevTools: $e\n$st');
}
}
Future<DevToolsServerAddress> serve() async { Future<DevToolsServerAddress> serve();
try {
_devtoolsServer ??= await devtools_server.serveDevTools(
enableStdinCommands: false,
);
return DevToolsServerAddress(_devtoolsServer.address.host, _devtoolsServer.port);
} on Exception catch (e, st) {
globals.printTrace('Failed to serve DevTools: $e\n$st');
return null;
}
}
Future<void> close() async { Future<void> close();
await _devtoolsServer?.close();
_devtoolsServer = null;
}
static DevtoolsLauncher get instance => context.get<DevtoolsLauncher>() ?? DevtoolsLauncher(); static DevtoolsLauncher get instance => context.get<DevtoolsLauncher>();
} }
class DevToolsServerAddress { class DevToolsServerAddress {
......
...@@ -10,8 +10,8 @@ import 'package:flutter_tools/src/base/logger.dart'; ...@@ -10,8 +10,8 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/terminal.dart'; import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_runner/devfs_web.dart'; import 'package:flutter_tools/src/isolated/devfs_web.dart';
import 'package:flutter_tools/src/build_runner/resident_web_runner.dart'; import 'package:flutter_tools/src/isolated/resident_web_runner.dart';
import 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/dart/pub.dart'; import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
......
...@@ -15,8 +15,8 @@ import 'package:flutter_tools/src/base/logger.dart'; ...@@ -15,8 +15,8 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/terminal.dart'; import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_runner/devfs_web.dart'; import 'package:flutter_tools/src/isolated/devfs_web.dart';
import 'package:flutter_tools/src/build_runner/resident_web_runner.dart'; import 'package:flutter_tools/src/isolated/resident_web_runner.dart';
import 'package:flutter_tools/src/compile.dart'; import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/dart/pub.dart'; import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/devfs.dart'; import 'package:flutter_tools/src/devfs.dart';
......
...@@ -10,7 +10,7 @@ import 'package:flutter_tools/src/base/file_system.dart'; ...@@ -10,7 +10,7 @@ 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/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_runner/devfs_web.dart'; import 'package:flutter_tools/src/isolated/devfs_web.dart';
import 'package:flutter_tools/src/compile.dart'; import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/convert.dart'; import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
......
...@@ -6,7 +6,7 @@ import 'package:file/memory.dart'; ...@@ -6,7 +6,7 @@ import 'package:file/memory.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/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_runner/devfs_web.dart'; import 'package:flutter_tools/src/isolated/devfs_web.dart';
import 'package:shelf/shelf.dart'; import 'package:shelf/shelf.dart';
import '../../src/common.dart'; import '../../src/common.dart';
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import 'package:dwds/dwds.dart'; import 'package:dwds/dwds.dart';
import 'package:flutter_tools/src/compile.dart'; import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/build_runner/devfs_web.dart'; import 'package:flutter_tools/src/isolated/devfs_web.dart';
import 'package:matcher/matcher.dart'; import 'package:matcher/matcher.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
......
...@@ -86,7 +86,6 @@ void main() { ...@@ -86,7 +86,6 @@ void main() {
test('no unauthorized imports of test_api', () { test('no unauthorized imports of test_api', () {
final List<String> allowedPaths = <String>[ final List<String> allowedPaths = <String>[
fileSystem.path.join(flutterTools, 'lib', 'src', 'build_runner', 'build_script.dart'),
fileSystem.path.join(flutterTools, 'lib', 'src', 'test', 'flutter_platform.dart'), fileSystem.path.join(flutterTools, 'lib', 'src', 'test', 'flutter_platform.dart'),
fileSystem.path.join(flutterTools, 'lib', 'src', 'test', 'flutter_web_platform.dart'), fileSystem.path.join(flutterTools, 'lib', 'src', 'test', 'flutter_web_platform.dart'),
fileSystem.path.join(flutterTools, 'lib', 'src', 'test', 'test_wrapper.dart'), fileSystem.path.join(flutterTools, 'lib', 'src', 'test', 'test_wrapper.dart'),
...@@ -113,7 +112,7 @@ void main() { ...@@ -113,7 +112,7 @@ void main() {
test('no unauthorized imports of package:path', () { test('no unauthorized imports of package:path', () {
final List<String> allowedPath = <String>[ final List<String> allowedPath = <String>[
fileSystem.path.join(flutterTools, 'lib', 'src', 'build_runner', 'web_compilation_delegate.dart'), fileSystem.path.join(flutterTools, 'lib', 'src', 'isolated', 'web_compilation_delegate.dart'),
fileSystem.path.join(flutterTools, 'test', 'general.shard', 'platform_plugins_test.dart'), fileSystem.path.join(flutterTools, 'test', 'general.shard', 'platform_plugins_test.dart'),
]; ];
for (final String dirName in <String>['lib', 'bin', 'test']) { for (final String dirName in <String>['lib', 'bin', 'test']) {
...@@ -181,10 +180,10 @@ void main() { ...@@ -181,10 +180,10 @@ void main() {
} }
}); });
test('no unauthorized imports of build_runner or dwds', () { test('no unauthorized imports of build_runner/dwds/devtools', () {
final List<String> allowedPaths = <String>[ final List<String> allowedPaths = <String>[
fileSystem.path.join(flutterTools, 'test', 'src', 'build_runner'), fileSystem.path.join(flutterTools, 'test', 'src', 'isolated'),
fileSystem.path.join(flutterTools, 'lib', 'src', 'build_runner'), fileSystem.path.join(flutterTools, 'lib', 'src', 'isolated'),
fileSystem.path.join(flutterTools, 'lib', 'executable.dart'), fileSystem.path.join(flutterTools, 'lib', 'executable.dart'),
fileSystem.path.join(flutterTools, 'lib', 'devfs_web.dart'), fileSystem.path.join(flutterTools, 'lib', 'devfs_web.dart'),
fileSystem.path.join(flutterTools, 'lib', 'resident_web_runner.dart'), fileSystem.path.join(flutterTools, 'lib', 'resident_web_runner.dart'),
...@@ -203,9 +202,10 @@ void main() { ...@@ -203,9 +202,10 @@ void main() {
line.startsWith(RegExp(r'import.*package:build_runner/build_runner.dart')) || line.startsWith(RegExp(r'import.*package:build_runner/build_runner.dart')) ||
line.startsWith(RegExp(r'import.*package:build_config/build_config.dart')) || line.startsWith(RegExp(r'import.*package:build_config/build_config.dart')) ||
line.startsWith(RegExp(r'import.*dwds:*.dart')) || line.startsWith(RegExp(r'import.*dwds:*.dart')) ||
line.startsWith(RegExp(r'import.*devtools_server:*.dart')) ||
line.startsWith(RegExp(r'import.*build_runner/.*.dart'))) { line.startsWith(RegExp(r'import.*build_runner/.*.dart'))) {
final String relativePath = fileSystem.path.relative(file.path, from:flutterTools); final String relativePath = fileSystem.path.relative(file.path, from:flutterTools);
fail('$relativePath imports a build_runner package'); fail('$relativePath imports a build_runner/dwds/devtools package');
} }
} }
} }
......
...@@ -17,7 +17,7 @@ import 'package:flutter_tools/src/base/signals.dart'; ...@@ -17,7 +17,7 @@ import 'package:flutter_tools/src/base/signals.dart';
import 'package:flutter_tools/src/base/template.dart'; import 'package:flutter_tools/src/base/template.dart';
import 'package:flutter_tools/src/base/terminal.dart'; import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/base/time.dart'; import 'package:flutter_tools/src/base/time.dart';
import 'package:flutter_tools/src/build_runner/mustache_template.dart'; import 'package:flutter_tools/src/isolated/mustache_template.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/context_runner.dart'; import 'package:flutter_tools/src/context_runner.dart';
import 'package:flutter_tools/src/dart/pub.dart'; import 'package:flutter_tools/src/dart/pub.dart';
......
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