Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(854)

Unified Diff: runtime/tools/kernel-service.dart

Issue 2570483003: Cleanup the kernel service implementation and avoid printing on the console when no tracing flags a… (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/main.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/tools/kernel-service.dart
diff --git a/runtime/tools/kernel-service.dart b/runtime/tools/kernel-service.dart
index 6ee3580b08b1d9b29fc3d63fa715aee16d998624..f473c154775f0376174f49614e7eb7ace589ec48 100644
--- a/runtime/tools/kernel-service.dart
+++ b/runtime/tools/kernel-service.dart
@@ -8,83 +8,46 @@
import 'dart:isolate';
import 'dart:async';
-import "dart:io";
-import "dart:typed_data";
+import 'dart:io';
+import 'dart:typed_data';
import 'package:kernel/binary/ast_to_binary.dart';
import 'package:kernel/analyzer/loader.dart';
import 'package:kernel/kernel.dart';
import 'package:kernel/target/targets.dart';
-bool verbose = false;
+const verbose = false;
-final RawReceivePort scriptLoadPort = new RawReceivePort();
+class DataSink implements Sink<List<int>> {
+ final BytesBuilder builder = new BytesBuilder();
-
-bool checkIsFile(String path) {
- var stat = new File(path).statSync();
- switch (stat.type) {
- case FileSystemEntityType.DIRECTORY:
- return false;
- case FileSystemEntityType.NOT_FOUND:
- return false;
- }
- return true;
-}
-
-
-void checkSdkDirectory(String path) {
- var stat = new File(path).statSync();
- switch (stat.type) {
- case FileSystemEntityType.DIRECTORY:
- case FileSystemEntityType.LINK:
- return true;
- default:
- return false;
+ void add(List<int> data) {
+ builder.add(data);
}
-}
-
-class DataSink implements StreamSink<List<int>> {
- var buffer = [];
- add(List<int> data) {
- buffer.addAll(data);
- }
- close() {
+ void close() {
// Nothing to do.
}
}
-
-List writeProgramToBuffer(Program program) {
- var sink = new DataSink();
- try {
- new BinaryPrinter(sink).writeProgramFile(program);
- } finally {
- sink.close();
- }
- return new Uint8List.fromList(sink.buffer);
-}
-
-
-Future parseScript(Uri fileName, String packageConfig, String sdkPath) async {
-
- if (!checkIsFile(fileName.path)) {
+Future<Uint8List> parseScript(
+ Uri fileName, String packageConfig, String sdkPath) async {
+ if (!FileSystemEntity.isFileSync(fileName.path)) {
throw "Input file '${fileName.path}' does not exist.";
}
- if (!checkSdkDirectory(sdkPath)) {
+ if (!FileSystemEntity.isDirectorySync(sdkPath)) {
throw "Patched sdk directory not found at $sdkPath";
}
Target target = getTarget("vm", new TargetFlags(strongMode: false));
DartOptions dartOptions = new DartOptions(
- strongMode: false,
- strongModeSdk: false,
- sdk: sdkPath,
- packagePath: packageConfig,
- customUriMappings: {},
- declaredVariables: {});
+ strongMode: false,
+ strongModeSdk: false,
+ sdk: sdkPath,
+ packagePath: packageConfig,
+ customUriMappings: const {},
+ declaredVariables: const {});
DartLoader loader =
await new DartLoaderBatch().getLoader(new Repository(), dartOptions);
var program = loader.loadProgram(fileName, target: target);
@@ -94,53 +57,39 @@ Future parseScript(Uri fileName, String packageConfig, String sdkPath) async {
throw loader.errors.first;
}
- // Link program into one file, cf. --link option in dartk
+ // Link program into one file, cf. --link option in dartk.
target.transformProgram(program);
- return writeProgramToBuffer(program);
+ // Write the program to a list of bytes and return it.
+ var sink = new DataSink();
+ new BinaryPrinter(sink).writeProgramFile(program);
+ return sink.builder.takeBytes();
}
-
-_processLoadRequest(request) {
+Future _processLoadRequest(request) async {
if (verbose) {
print("FROM DART KERNEL: load request: $request");
print("FROM DART KERNEL: package: ${Platform.packageConfig}");
print("FROM DART KERNEL: exec: ${Platform.resolvedExecutable}");
}
+
int tag = request[0];
- SendPort sp = request[1];
+ SendPort port = request[1];
String inputFileUrl = request[2];
Uri scriptUri = Uri.parse(inputFileUrl);
Uri packagesUri = Uri.parse(Platform.packageConfig ?? ".packages");
- Uri patched_sdk = Uri.parse(Platform.resolvedExecutable).resolve("patched_sdk");
-
- var parsingDone = parseScript(scriptUri, packagesUri.path, patched_sdk.path);
-
- parsingDone
- .then((data) {
- var msg = new List(5);
- msg[0] = tag;
- msg[1] = inputFileUrl;
- msg[2] = inputFileUrl;
- msg[3] = null;
- msg[4] = data;
- sp.send(msg);
- return;
- })
- .catchError((e) {
- var msg = new List(5);
- msg[0] = -tag;
- msg[1] = inputFileUrl;
- msg[2] = inputFileUrl;
- msg[3] = null;
- msg[4] = e.toString();
- sp.send(msg);
- });
-}
+ Uri patchedSdk =
+ Uri.parse(Platform.resolvedExecutable).resolve("patched_sdk");
+
+ var result;
+ try {
+ result = await parseScript(scriptUri, packagesUri.path, patchedSdk.path);
+ } catch (error) {
+ tag = -tag; // Mark reply as an exception.
+ result = error.toString();
+ }
+ port.send([tag, inputFileUrl, inputFileUrl, null, result]);
+}
-main() {
- scriptLoadPort.handler = _processLoadRequest;
- Timer.run(() {});
- return scriptLoadPort;
-}
+main() => new RawReceivePort()..handler = _processLoadRequest;
« no previous file with comments | « runtime/bin/main.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698