06d938046f
and TargetFlags.soundNullSafety TEST=existing Change-Id: I5e28d3d187b0f84fa23130c042fd3c55b89c687c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413460 Reviewed-by: Ömer Ağacan <omersa@google.com> Reviewed-by: Jens Johansen <jensj@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Nate Biggs <natebiggs@google.com>
93 lines
3.4 KiB
Dart
93 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/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/modular/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())
|
|
..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);
|
|
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;
|