[vm/frontend] Fix frontend_server_test on Windows.
Assumption is that invalidated files are identified by uri.
Allow `file:`-uri so uri can be used for compilation/recompilation requests.
Fixes https://github.com/dart-lang/sdk/issues/35946
Change-Id: Ia976486841ddd5e5e78923467f8b2ca58396f994
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/95683
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
diff --git a/pkg/vm/lib/frontend_server.dart b/pkg/vm/lib/frontend_server.dart
index e0b9cfc..1aabfba 100644
--- a/pkg/vm/lib/frontend_server.dart
+++ b/pkg/vm/lib/frontend_server.dart
@@ -115,16 +115,16 @@
String usage = '''
Usage: server [options] [input.dart]
-If input dart source code is provided on the command line, then the server
-compiles it, generates dill file and exits.
-If no input dart source is provided on the command line, server waits for
+If filename or uri pointing to the entrypoint is provided on the command line,
+then the server compiles it, generates dill file and exits.
+If no entrypoint is provided on the command line, server waits for
instructions from stdin.
Instructions:
- compile <input.dart>
- recompile [<input.dart>] <boundary-key>
-<path/to/updated/file1.dart>
-<path/to/updated/file2.dart>
+<invalidated file uri>
+<invalidated file uri>
...
<boundary-key>
- accept
@@ -152,20 +152,20 @@
/// Actions that every compiler should implement.
abstract class CompilerInterface {
- /// Compile given Dart program identified by `filename` with given list of
+ /// Compile given Dart program identified by `entryPoint` with given list of
/// `options`. When `generator` parameter is omitted, new instance of
/// `IncrementalKernelGenerator` is created by this method. Main use for this
/// parameter is for mocking in tests.
/// Returns [true] if compilation was successful and produced no errors.
Future<bool> compile(
- String filename,
+ String entryPoint,
ArgResults options, {
IncrementalCompiler generator,
});
/// Assuming some Dart program was previously compiled, recompile it again
/// taking into account some changed(invalidated) sources.
- Future<Null> recompileDelta({String filename});
+ Future<Null> recompileDelta({String entryPoint});
/// Accept results of previous compilation so that next recompilation cycle
/// won't recompile sources that were previously reported as changed.
@@ -244,26 +244,21 @@
final List<String> errors = new List<String>();
- void setMainSourceFilename(String filename) {
- final Uri filenameUri = _getFileOrUri(filename);
- _mainSource = filenameUri;
- }
-
@override
Future<bool> compile(
- String filename,
+ String entryPoint,
ArgResults options, {
IncrementalCompiler generator,
}) async {
_options = options;
_fileSystem = createFrontEndFileSystem(
options['filesystem-scheme'], options['filesystem-root']);
- setMainSourceFilename(filename);
- _kernelBinaryFilenameFull = _options['output-dill'] ?? '$filename.dill';
+ _mainSource = _getFileOrUri(entryPoint);
+ _kernelBinaryFilenameFull = _options['output-dill'] ?? '$entryPoint.dill';
_kernelBinaryFilenameIncremental = _options['output-incremental-dill'] ??
(_options['output-dill'] != null
? '${_options['output-dill']}.incremental.dill'
- : '$filename.incremental.dill');
+ : '$entryPoint.incremental.dill');
_kernelBinaryFilename = _kernelBinaryFilenameFull;
_initializeFromDill =
_options['initialize-from-dill'] ?? _kernelBinaryFilenameFull;
@@ -458,12 +453,12 @@
}
@override
- Future<Null> recompileDelta({String filename}) async {
+ Future<Null> recompileDelta({String entryPoint}) async {
final String boundaryKey = new Uuid().generateV4();
_outputStream.writeln('result $boundaryKey');
await invalidateIfInitializingFromDill();
- if (filename != null) {
- setMainSourceFilename(filename);
+ if (entryPoint != null) {
+ _mainSource = _getFileOrUri(entryPoint);
}
errors.clear();
final Component deltaProgram =
@@ -683,7 +678,7 @@
_State state = _State.READY_FOR_INSTRUCTION;
_CompileExpressionRequest compileExpressionRequest;
String boundaryKey;
- String recompileFilename;
+ String recompileEntryPoint;
input
.transform(utf8.decoder)
.transform(const LineSplitter())
@@ -695,17 +690,17 @@
const String COMPILE_EXPRESSION_INSTRUCTION_SPACE =
'compile-expression ';
if (string.startsWith(COMPILE_INSTRUCTION_SPACE)) {
- final String filename =
+ final String entryPoint =
string.substring(COMPILE_INSTRUCTION_SPACE.length);
- await compiler.compile(filename, options, generator: generator);
+ await compiler.compile(entryPoint, options, generator: generator);
} else if (string.startsWith(RECOMPILE_INSTRUCTION_SPACE)) {
- // 'recompile [<filename>] <boundarykey>'
+ // 'recompile [<entryPoint>] <boundarykey>'
// where <boundarykey> can't have spaces
final String remainder =
string.substring(RECOMPILE_INSTRUCTION_SPACE.length);
final int spaceDelim = remainder.lastIndexOf(' ');
if (spaceDelim > -1) {
- recompileFilename = remainder.substring(0, spaceDelim);
+ recompileEntryPoint = remainder.substring(0, spaceDelim);
boundaryKey = remainder.substring(spaceDelim + 1);
} else {
boundaryKey = remainder;
@@ -739,7 +734,7 @@
break;
case _State.RECOMPILE_LIST:
if (string == boundaryKey) {
- compiler.recompileDelta(filename: recompileFilename);
+ compiler.recompileDelta(entryPoint: recompileEntryPoint);
state = _State.READY_FOR_INSTRUCTION;
} else
compiler.invalidate(Uri.base.resolve(string));
diff --git a/pkg/vm/lib/kernel_front_end.dart b/pkg/vm/lib/kernel_front_end.dart
index 78063e2..9313820 100644
--- a/pkg/vm/lib/kernel_front_end.dart
+++ b/pkg/vm/lib/kernel_front_end.dart
@@ -517,7 +517,7 @@
/// absolute URI.
///
/// If virtual multi-root file system is used, or [input] can be parsed to a
-/// URI with 'package' scheme, then [input] is interpreted as URI.
+/// URI with 'package' or 'file' scheme, then [input] is interpreted as URI.
/// Otherwise [input] is interpreted as a file path.
Uri convertFileOrUriArgumentToUri(FileSystem fileSystem, String input) {
if (input == null) {
@@ -530,7 +530,7 @@
}
try {
Uri uri = Uri.parse(input);
- if (uri.scheme == 'package') {
+ if (uri.scheme == 'package' || uri.scheme == 'file') {
return uri;
}
} on FormatException {
diff --git a/pkg/vm/test/frontend_server_test.dart b/pkg/vm/test/frontend_server_test.dart
index 4a4a7d8..6881882 100644
--- a/pkg/vm/test/frontend_server_test.dart
+++ b/pkg/vm/test/frontend_server_test.dart
@@ -179,7 +179,7 @@
new StreamController<List<int>>();
final ReceivePort recompileCalled = new ReceivePort();
- when(compiler.recompileDelta(filename: null))
+ when(compiler.recompileDelta(entryPoint: null))
.thenAnswer((Invocation invocation) {
recompileCalled.sendPort.send(true);
});
@@ -195,7 +195,7 @@
verifyInOrder(<void>[
compiler.invalidate(Uri.base.resolve('file1.dart')),
compiler.invalidate(Uri.base.resolve('file2.dart')),
- await compiler.recompileDelta(filename: null),
+ await compiler.recompileDelta(entryPoint: null),
]);
inputStreamController.add('quit\n'.codeUnits);
expect(await result, 0);
@@ -207,7 +207,7 @@
new StreamController<List<int>>();
final ReceivePort recompileCalled = new ReceivePort();
- when(compiler.recompileDelta(filename: 'file2.dart'))
+ when(compiler.recompileDelta(entryPoint: 'file2.dart'))
.thenAnswer((Invocation invocation) {
recompileCalled.sendPort.send(true);
});
@@ -223,7 +223,7 @@
verifyInOrder(<void>[
compiler.invalidate(Uri.base.resolve('file1.dart')),
compiler.invalidate(Uri.base.resolve('file2.dart')),
- await compiler.recompileDelta(filename: 'file2.dart'),
+ await compiler.recompileDelta(entryPoint: 'file2.dart'),
]);
inputStreamController.add('quit\n'.codeUnits);
expect(await result, 0);
@@ -274,7 +274,7 @@
new StreamController<List<int>>();
final ReceivePort recompileCalled = new ReceivePort();
- when(compiler.recompileDelta(filename: null))
+ when(compiler.recompileDelta(entryPoint: null))
.thenAnswer((Invocation invocation) {
recompileCalled.sendPort.send(true);
});
@@ -295,7 +295,7 @@
compiler.acceptLastDelta(),
compiler.invalidate(Uri.base.resolve('file2.dart')),
compiler.invalidate(Uri.base.resolve('file3.dart')),
- await compiler.recompileDelta(filename: null),
+ await compiler.recompileDelta(entryPoint: null),
]);
inputStreamController.add('quit\n'.codeUnits);
expect(await result, 0);
@@ -875,7 +875,7 @@
});
Future<int> result =
starter(args, input: inputStreamController.stream, output: ioSink);
- inputStreamController.add('compile ${file.path}\n'.codeUnits);
+ inputStreamController.add('compile ${file.uri}\n'.codeUnits);
int count = 0;
receivedResults.stream.listen((String outputFilenameAndErrorCount) {
CompilationResult result =
@@ -889,8 +889,8 @@
inputStreamController.add('accept\n'.codeUnits);
var file2 = new File('${tempDir.path}/bar.dart')..createSync();
file2.writeAsStringSync("main() { baz(); }\n");
- inputStreamController.add('recompile ${file2.path} abc\n'
- '${file2.path}\n'
+ inputStreamController.add('recompile ${file2.uri} abc\n'
+ '${file2.uri}\n'
'abc\n'
.codeUnits);
break;
@@ -902,8 +902,8 @@
inputStreamController.add('accept\n'.codeUnits);
var file2 = new File('${tempDir.path}/bar.dart')..createSync();
file2.writeAsStringSync("main() { }\n");
- inputStreamController.add('recompile ${file2.path} abc\n'
- '${file2.path}\n'
+ inputStreamController.add('recompile ${file2.uri} abc\n'
+ '${file2.uri}\n'
'abc\n'
.codeUnits);
break;