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