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

[flutter_tools] remove most globals from resident web runner (#77432)

parent 85e2c52b
...@@ -73,13 +73,6 @@ class FileSystemUtils { ...@@ -73,13 +73,6 @@ class FileSystemUtils {
} }
} }
/// Return a relative path if [fullPath] is contained by the cwd, else return an
/// absolute path.
String getDisplayPath(String fullPath) {
final String cwd = _fileSystem.currentDirectory.path + _fileSystem.path.separator;
return fullPath.startsWith(cwd) ? fullPath.substring(cwd.length) : fullPath;
}
/// Escapes [path]. /// Escapes [path].
/// ///
/// On Windows it replaces all '\' with '\\'. On other platforms, it returns the /// On Windows it replaces all '\' with '\\'. On other platforms, it returns the
...@@ -115,6 +108,13 @@ class FileSystemUtils { ...@@ -115,6 +108,13 @@ class FileSystemUtils {
} }
} }
/// Return a relative path if [fullPath] is contained by the cwd, else return an
/// absolute path.
String getDisplayPath(String fullPath, FileSystem fileSystem) {
final String cwd = fileSystem.currentDirectory.path + fileSystem.path.separator;
return fullPath.startsWith(cwd) ? fullPath.substring(cwd.length) : fullPath;
}
/// Creates `destDir` if needed, then recursively copies `srcDir` to /// Creates `destDir` if needed, then recursively copies `srcDir` to
/// `destDir`, invoking [onFileCopied], if specified, for each /// `destDir`, invoking [onFileCopied], if specified, for each
/// source/destination file pair. /// source/destination file pair.
......
...@@ -11,7 +11,7 @@ import 'package:meta/meta.dart'; ...@@ -11,7 +11,7 @@ import 'package:meta/meta.dart';
import '../convert.dart'; import '../convert.dart';
import '../globals.dart' as globals; import '../globals.dart' as globals;
import 'io.dart'; import 'io.dart';
import 'terminal.dart' show AnsiTerminal, Terminal, TerminalColor, OutputPreferences; import 'terminal.dart' show Terminal, TerminalColor, OutputPreferences;
import 'utils.dart'; import 'utils.dart';
const int kDefaultStatusPadding = 59; const int kDefaultStatusPadding = 59;
...@@ -36,7 +36,7 @@ abstract class Logger { ...@@ -36,7 +36,7 @@ abstract class Logger {
bool get hasTerminal; bool get hasTerminal;
Terminal get _terminal; Terminal get terminal;
OutputPreferences get _outputPreferences; OutputPreferences get _outputPreferences;
...@@ -162,7 +162,7 @@ class DelegatingLogger implements Logger { ...@@ -162,7 +162,7 @@ class DelegatingLogger implements Logger {
bool get hasTerminal => _delegate.hasTerminal; bool get hasTerminal => _delegate.hasTerminal;
@override @override
Terminal get _terminal => _delegate._terminal; Terminal get terminal => _delegate.terminal;
@override @override
OutputPreferences get _outputPreferences => _delegate._outputPreferences; OutputPreferences get _outputPreferences => _delegate._outputPreferences;
...@@ -241,18 +241,17 @@ T asLogger<T extends Logger>(Logger logger) { ...@@ -241,18 +241,17 @@ T asLogger<T extends Logger>(Logger logger) {
class StdoutLogger extends Logger { class StdoutLogger extends Logger {
StdoutLogger({ StdoutLogger({
@required Terminal terminal, @required this.terminal,
@required Stdio stdio, @required Stdio stdio,
@required OutputPreferences outputPreferences, @required OutputPreferences outputPreferences,
StopwatchFactory stopwatchFactory = const StopwatchFactory(), StopwatchFactory stopwatchFactory = const StopwatchFactory(),
}) })
: _stdio = stdio, : _stdio = stdio,
_terminal = terminal,
_outputPreferences = outputPreferences, _outputPreferences = outputPreferences,
_stopwatchFactory = stopwatchFactory; _stopwatchFactory = stopwatchFactory;
@override @override
final Terminal _terminal; final Terminal terminal;
@override @override
final OutputPreferences _outputPreferences; final OutputPreferences _outputPreferences;
final Stdio _stdio; final Stdio _stdio;
...@@ -264,7 +263,7 @@ class StdoutLogger extends Logger { ...@@ -264,7 +263,7 @@ class StdoutLogger extends Logger {
bool get isVerbose => false; bool get isVerbose => false;
@override @override
bool get supportsColor => _terminal.supportsColor; bool get supportsColor => terminal.supportsColor;
@override @override
bool get hasTerminal => _stdio.stdinHasTerminal; bool get hasTerminal => _stdio.stdinHasTerminal;
...@@ -288,9 +287,9 @@ class StdoutLogger extends Logger { ...@@ -288,9 +287,9 @@ class StdoutLogger extends Logger {
columnWidth: _outputPreferences.wrapColumn, columnWidth: _outputPreferences.wrapColumn,
); );
if (emphasis == true) { if (emphasis == true) {
message = _terminal.bolden(message); message = terminal.bolden(message);
} }
message = _terminal.color(message, color ?? TerminalColor.red); message = terminal.color(message, color ?? TerminalColor.red);
writeToStdErr('$message\n'); writeToStdErr('$message\n');
if (stackTrace != null) { if (stackTrace != null) {
writeToStdErr('$stackTrace\n'); writeToStdErr('$stackTrace\n');
...@@ -317,10 +316,10 @@ class StdoutLogger extends Logger { ...@@ -317,10 +316,10 @@ class StdoutLogger extends Logger {
columnWidth: _outputPreferences.wrapColumn, columnWidth: _outputPreferences.wrapColumn,
); );
if (emphasis == true) { if (emphasis == true) {
message = _terminal.bolden(message); message = terminal.bolden(message);
} }
if (color != null) { if (color != null) {
message = _terminal.color(message, color); message = terminal.color(message, color);
} }
if (newline != false) { if (newline != false) {
message = '$message\n'; message = '$message\n';
...@@ -361,7 +360,7 @@ class StdoutLogger extends Logger { ...@@ -361,7 +360,7 @@ class StdoutLogger extends Logger {
onFinish: _clearStatus, onFinish: _clearStatus,
stdio: _stdio, stdio: _stdio,
stopwatch: _stopwatchFactory.createStopwatch(), stopwatch: _stopwatchFactory.createStopwatch(),
terminal: _terminal, terminal: terminal,
)..start(); )..start();
} else { } else {
_status = SummaryStatus( _status = SummaryStatus(
...@@ -385,7 +384,7 @@ class StdoutLogger extends Logger { ...@@ -385,7 +384,7 @@ class StdoutLogger extends Logger {
@override @override
void clear() { void clear() {
_status?.pause(); _status?.pause();
writeToStdOut(_terminal.clearScreen() + '\n'); writeToStdOut(terminal.clearScreen() + '\n');
_status?.resume(); _status?.resume();
} }
} }
...@@ -413,7 +412,7 @@ class WindowsStdoutLogger extends StdoutLogger { ...@@ -413,7 +412,7 @@ class WindowsStdoutLogger extends StdoutLogger {
@override @override
void writeToStdOut(String message) { void writeToStdOut(String message) {
final String windowsMessage = _terminal.supportsEmoji final String windowsMessage = terminal.supportsEmoji
? message ? message
: message.replaceAll('🔥', '') : message.replaceAll('🔥', '')
.replaceAll('🖼️', '') .replaceAll('🖼️', '')
...@@ -428,18 +427,17 @@ class WindowsStdoutLogger extends StdoutLogger { ...@@ -428,18 +427,17 @@ class WindowsStdoutLogger extends StdoutLogger {
class BufferLogger extends Logger { class BufferLogger extends Logger {
BufferLogger({ BufferLogger({
@required AnsiTerminal terminal, @required this.terminal,
@required OutputPreferences outputPreferences, @required OutputPreferences outputPreferences,
StopwatchFactory stopwatchFactory = const StopwatchFactory(), StopwatchFactory stopwatchFactory = const StopwatchFactory(),
}) : _outputPreferences = outputPreferences, }) : _outputPreferences = outputPreferences,
_terminal = terminal,
_stopwatchFactory = stopwatchFactory; _stopwatchFactory = stopwatchFactory;
/// Create a [BufferLogger] with test preferences. /// Create a [BufferLogger] with test preferences.
BufferLogger.test({ BufferLogger.test({
Terminal terminal, Terminal terminal,
OutputPreferences outputPreferences, OutputPreferences outputPreferences,
}) : _terminal = terminal ?? Terminal.test(), }) : terminal = terminal ?? Terminal.test(),
_outputPreferences = outputPreferences ?? OutputPreferences.test(), _outputPreferences = outputPreferences ?? OutputPreferences.test(),
_stopwatchFactory = const StopwatchFactory(); _stopwatchFactory = const StopwatchFactory();
...@@ -448,7 +446,7 @@ class BufferLogger extends Logger { ...@@ -448,7 +446,7 @@ class BufferLogger extends Logger {
final OutputPreferences _outputPreferences; final OutputPreferences _outputPreferences;
@override @override
final Terminal _terminal; final Terminal terminal;
final StopwatchFactory _stopwatchFactory; final StopwatchFactory _stopwatchFactory;
...@@ -456,7 +454,7 @@ class BufferLogger extends Logger { ...@@ -456,7 +454,7 @@ class BufferLogger extends Logger {
bool get isVerbose => false; bool get isVerbose => false;
@override @override
bool get supportsColor => _terminal.supportsColor; bool get supportsColor => terminal.supportsColor;
final StringBuffer _error = StringBuffer(); final StringBuffer _error = StringBuffer();
final StringBuffer _status = StringBuffer(); final StringBuffer _status = StringBuffer();
...@@ -481,7 +479,7 @@ class BufferLogger extends Logger { ...@@ -481,7 +479,7 @@ class BufferLogger extends Logger {
int hangingIndent, int hangingIndent,
bool wrap, bool wrap,
}) { }) {
_error.writeln(_terminal.color( _error.writeln(terminal.color(
wrapText(message, wrapText(message,
indent: indent, indent: indent,
hangingIndent: hangingIndent, hangingIndent: hangingIndent,
...@@ -654,7 +652,7 @@ class VerboseLogger extends DelegatingLogger { ...@@ -654,7 +652,7 @@ class VerboseLogger extends DelegatingLogger {
} else { } else {
prefix = '+$millis ms'.padLeft(prefixWidth); prefix = '+$millis ms'.padLeft(prefixWidth);
if (millis >= 100) { if (millis >= 100) {
prefix = _terminal.bolden(prefix); prefix = terminal.bolden(prefix);
} }
} }
prefix = '[$prefix] '; prefix = '[$prefix] ';
...@@ -663,12 +661,12 @@ class VerboseLogger extends DelegatingLogger { ...@@ -663,12 +661,12 @@ class VerboseLogger extends DelegatingLogger {
final String indentMessage = message.replaceAll('\n', '\n$indent'); final String indentMessage = message.replaceAll('\n', '\n$indent');
if (type == _LogType.error) { if (type == _LogType.error) {
super.printError(prefix + _terminal.bolden(indentMessage)); super.printError(prefix + terminal.bolden(indentMessage));
if (stackTrace != null) { if (stackTrace != null) {
super.printError(indent + stackTrace.toString().replaceAll('\n', '\n$indent')); super.printError(indent + stackTrace.toString().replaceAll('\n', '\n$indent'));
} }
} else if (type == _LogType.status) { } else if (type == _LogType.status) {
super.printStatus(prefix + _terminal.bolden(indentMessage)); super.printStatus(prefix + terminal.bolden(indentMessage));
} else { } else {
super.printStatus(prefix + indentMessage); super.printStatus(prefix + indentMessage);
} }
......
...@@ -484,6 +484,10 @@ class AppDomain extends Domain { ...@@ -484,6 +484,10 @@ class AppDomain extends Domain {
stayResident: true, stayResident: true,
urlTunneller: options.webEnableExposeUrl ? daemon.daemonDomain.exposeUrl : null, urlTunneller: options.webEnableExposeUrl ? daemon.daemonDomain.exposeUrl : null,
machine: machine, machine: machine,
usage: globals.flutterUsage,
systemClock: globals.systemClock,
logger: globals.logger,
fileSystem: globals.fs,
); );
} else if (enableHotReload) { } else if (enableHotReload) {
runner = HotRunner( runner = HotRunner(
......
...@@ -495,6 +495,10 @@ class RunCommand extends RunCommandBase { ...@@ -495,6 +495,10 @@ class RunCommand extends RunCommandBase {
debuggingOptions: await createDebuggingOptions(webMode), debuggingOptions: await createDebuggingOptions(webMode),
stayResident: stayResident, stayResident: stayResident,
urlTunneller: null, urlTunneller: null,
fileSystem: globals.fs,
usage: globals.flutterUsage,
logger: globals.logger,
systemClock: globals.systemClock,
); );
} }
return ColdRunner( return ColdRunner(
......
...@@ -72,6 +72,10 @@ class WebDriverService extends DriverService { ...@@ -72,6 +72,10 @@ class WebDriverService extends DriverService {
stayResident: false, stayResident: false,
urlTunneller: null, urlTunneller: null,
flutterProject: FlutterProject.current(), flutterProject: FlutterProject.current(),
fileSystem: globals.fs,
usage: globals.flutterUsage,
logger: globals.logger,
systemClock: globals.systemClock,
); );
final Completer<void> appStartedCompleter = Completer<void>.sync(); final Completer<void> appStartedCompleter = Completer<void>.sync();
final int result = await _residentRunner.run( final int result = await _residentRunner.run(
......
...@@ -565,7 +565,7 @@ class FlutterDevice { ...@@ -565,7 +565,7 @@ class FlutterDevice {
final bool prebuiltMode = hotRunner.applicationBinary != null; final bool prebuiltMode = hotRunner.applicationBinary != null;
final String modeName = hotRunner.debuggingOptions.buildInfo.friendlyModeName; final String modeName = hotRunner.debuggingOptions.buildInfo.friendlyModeName;
globals.printStatus( globals.printStatus(
'Launching ${globals.fsUtils.getDisplayPath(hotRunner.mainPath)} ' 'Launching ${getDisplayPath(hotRunner.mainPath, globals.fs)} '
'on ${device.name} in $modeName mode...', 'on ${device.name} in $modeName mode...',
); );
...@@ -645,7 +645,7 @@ class FlutterDevice { ...@@ -645,7 +645,7 @@ class FlutterDevice {
); );
} else { } else {
globals.printStatus( globals.printStatus(
'Launching ${globals.fsUtils.getDisplayPath(coldRunner.mainPath)} ' 'Launching ${getDisplayPath(coldRunner.mainPath, globals.fs)} '
'on ${device.name} in $modeName mode...', 'on ${device.name} in $modeName mode...',
); );
} }
......
...@@ -7,9 +7,13 @@ ...@@ -7,9 +7,13 @@
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import '../base/context.dart'; import '../base/context.dart';
import '../base/file_system.dart';
import '../base/logger.dart';
import '../base/net.dart'; import '../base/net.dart';
import '../base/time.dart';
import '../device.dart'; import '../device.dart';
import '../project.dart'; import '../project.dart';
import '../reporting/reporting.dart';
import '../resident_runner.dart'; import '../resident_runner.dart';
WebRunnerFactory get webRunnerFactory => context.get<WebRunnerFactory>(); WebRunnerFactory get webRunnerFactory => context.get<WebRunnerFactory>();
...@@ -27,6 +31,10 @@ abstract class WebRunnerFactory { ...@@ -27,6 +31,10 @@ abstract class WebRunnerFactory {
@required bool ipv6, @required bool ipv6,
@required DebuggingOptions debuggingOptions, @required DebuggingOptions debuggingOptions,
@required UrlTunneller urlTunneller, @required UrlTunneller urlTunneller,
@required Logger logger,
@required FileSystem fileSystem,
@required SystemClock systemClock,
@required Usage usage,
bool machine = false, bool machine = false,
}); });
} }
...@@ -799,6 +799,9 @@ class StreamLogger extends Logger { ...@@ -799,6 +799,9 @@ class StreamLogger extends Logger {
@override @override
void clear() => _log('[stdout] ${globals.terminal.clearScreen()}\n'); void clear() => _log('[stdout] ${globals.terminal.clearScreen()}\n');
@override
Terminal get terminal => Terminal.test();
} }
class LoggerInterrupted implements Exception { class LoggerInterrupted implements Exception {
......
...@@ -48,14 +48,19 @@ void main() { ...@@ -48,14 +48,19 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file(globals.fs.path.join('web', 'index.html')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('web', 'index.html')).createSync(recursive: true);
final FlutterProject project = FlutterProject.fromDirectoryTest(globals.fs.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(globals.fs.currentDirectory);
residentWebRunner = DwdsWebRunnerFactory().createWebRunner( residentWebRunner = ResidentWebRunner(
mockFlutterDevice, mockFlutterDevice,
flutterProject: project, flutterProject: project,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
ipv6: true, ipv6: true,
stayResident: true, stayResident: true,
urlTunneller: null, urlTunneller: null,
) as ResidentWebRunner; featureFlags: TestFeatureFlags(),
fileSystem: globals.fs,
logger: globals.logger,
systemClock: globals.systemClock,
usage: globals.flutterUsage,
);
} }
testUsingContext('Can successfully run and connect without vmservice', () async { testUsingContext('Can successfully run and connect without vmservice', () async {
......
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