mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:09:49 +00:00
1bd1d9d320
This entrypoint is practically unused. We normally use `lib/src/dart2js.dart` instead. Long ago it wasn't possible to launch a script from the `lib` folder without running into import canonicalization issues. However, a few years ago the VM and CFE now normalize the entrypoints. When we invoke `pkg/compiler/lib/src/dart2js.dart` it gets treataed as `package:compiler/src/dart2js.dart`. As a result, we really no longer had a need to have a separate entrypoint in the `bin` folder that reexports the other entrypoint. The only remaining references to this file were from documentation and a couple unit tests. This CL updates those remaining uses. Change-Id: Ic4c3c5c030db4e497f1d136979f7212db29cc533 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302640 Reviewed-by: Nate Biggs <natebiggs@google.com> Auto-Submit: Sigmund Cherem <sigmund@google.com> Commit-Queue: Nate Biggs <natebiggs@google.com>
100 lines
3.4 KiB
Dart
100 lines
3.4 KiB
Dart
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:io' show Directory, File, Platform, Process, ProcessResult;
|
|
|
|
import 'dart:typed_data' show Uint8List;
|
|
|
|
import 'package:front_end/src/fasta/kernel/utils.dart' show serializeComponent;
|
|
|
|
import 'package:kernel/ast.dart' show Component, Library;
|
|
|
|
import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
|
|
|
|
import 'package:kernel/target/targets.dart' show TargetFlags;
|
|
|
|
import "package:vm/target/vm.dart" show VmTarget;
|
|
|
|
import 'incremental_suite.dart' show getOptions, normalCompileToComponent;
|
|
|
|
import 'utils/io_utils.dart' show computeRepoDir;
|
|
|
|
Future<void> main() async {
|
|
final Uri dart2jsUrl = Uri.base.resolve("pkg/compiler/lib/src/dart2js.dart");
|
|
Stopwatch stopwatch = new Stopwatch()..start();
|
|
Component component = await normalCompileToComponent(dart2jsUrl,
|
|
options: getOptions()
|
|
..target = new VmTarget(new TargetFlags(soundNullSafety: false))
|
|
..omitPlatform = false);
|
|
print("Compiled dart2js in ${stopwatch.elapsedMilliseconds} ms");
|
|
|
|
component.computeCanonicalNames();
|
|
|
|
stopwatch.reset();
|
|
List<List<int>> libComponents = <List<int>>[];
|
|
for (Library lib in component.libraries) {
|
|
Component libComponent = new Component(nameRoot: component.root);
|
|
libComponent.libraries.add(lib);
|
|
libComponent.uriToSource.addAll(component.uriToSource);
|
|
libComponent.setMainMethodAndMode(
|
|
component.mainMethodName, true, component.mode);
|
|
libComponents.add(serializeComponent(libComponent));
|
|
}
|
|
print("Serialized ${libComponents.length} separate library components "
|
|
"in ${stopwatch.elapsedMilliseconds} ms");
|
|
|
|
stopwatch.reset();
|
|
int totalLength = 0;
|
|
for (List<int> libComponent in libComponents) {
|
|
totalLength += libComponent.length;
|
|
}
|
|
Uint8List combined = new Uint8List(totalLength);
|
|
int index = 0;
|
|
for (List<int> libComponent in libComponents) {
|
|
combined.setRange(index, index + libComponent.length, libComponent);
|
|
index += libComponent.length;
|
|
}
|
|
print("Combined in ${stopwatch.elapsedMilliseconds} ms");
|
|
|
|
stopwatch.reset();
|
|
Component combinedComponent = new Component();
|
|
new BinaryBuilder(combined).readComponent(combinedComponent);
|
|
print("Read combined in ${stopwatch.elapsedMilliseconds} ms");
|
|
|
|
stopwatch.reset();
|
|
Uint8List merged = serializeComponent(combinedComponent);
|
|
print("Serialized combined component in ${stopwatch.elapsedMilliseconds} ms");
|
|
|
|
for (Uint8List data in [combined, merged]) {
|
|
stopwatch.reset();
|
|
Directory out = Directory.systemTemp.createTempSync("split_dill_test");
|
|
try {
|
|
File f = new File.fromUri(out.uri.resolve("out.dill"));
|
|
f.writeAsBytesSync(data);
|
|
|
|
ProcessResult result = await Process.run(
|
|
dartVm,
|
|
[
|
|
"--compile_all",
|
|
f.path,
|
|
"-h",
|
|
],
|
|
workingDirectory: out.path);
|
|
print("stdout: ${result.stdout}");
|
|
print("stderr: ${result.stderr}");
|
|
print("Exit code: ${result.exitCode}");
|
|
if (result.exitCode != 0) {
|
|
throw "Got exit code ${result.exitCode}";
|
|
}
|
|
print("Ran VM on dill in ${stopwatch.elapsedMilliseconds} ms");
|
|
} finally {
|
|
out.deleteSync(recursive: true);
|
|
}
|
|
}
|
|
}
|
|
|
|
final String repoDir = computeRepoDir();
|
|
|
|
String get dartVm => Platform.resolvedExecutable;
|