mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 16:54:55 +00:00
Cleanup the kernel service implementation and avoid printing on the console when no tracing flags are provided.
R=kmillikin@google.com, hausner@google.com BUG= Review-Url: https://codereview.chromium.org/2570483003 .
This commit is contained in:
parent
a3ec04eb99
commit
53dd819a4c
|
@ -910,7 +910,6 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
|
|||
CHECK_RESULT(result);
|
||||
|
||||
if (!Dart_IsKernelIsolate(isolate) && use_dart_frontend) {
|
||||
Log::PrintErr("Waiting for Kernel isolate to load.\n");
|
||||
// This must be the main script to be loaded. Wait for Kernel isolate
|
||||
// to finish initialization.
|
||||
Dart_Port port = Dart_ServiceWaitForKernelPort();
|
||||
|
|
|
@ -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;
|
||||
void add(List<int> data) {
|
||||
builder.add(data);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
Uri patchedSdk =
|
||||
Uri.parse(Platform.resolvedExecutable).resolve("patched_sdk");
|
||||
|
||||
var parsingDone = parseScript(scriptUri, packagesUri.path, patched_sdk.path);
|
||||
var result;
|
||||
try {
|
||||
result = await parseScript(scriptUri, packagesUri.path, patchedSdk.path);
|
||||
} catch (error) {
|
||||
tag = -tag; // Mark reply as an exception.
|
||||
result = error.toString();
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
port.send([tag, inputFileUrl, inputFileUrl, null, result]);
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
scriptLoadPort.handler = _processLoadRequest;
|
||||
Timer.run(() {});
|
||||
return scriptLoadPort;
|
||||
}
|
||||
main() => new RawReceivePort()..handler = _processLoadRequest;
|
||||
|
|
Loading…
Reference in a new issue