cf8a477cb7
This allows dartdevk to compile tests that import packages like expect.
There are a few pieces to this:
- Add support to build_pkgs.dart to build the kernel summaries for each
test package (in addition to the analyzer summaries it already
builds).
- Plumb that through the dartdevc_test target in the GN build as well.
- While we're at it, use GN to build the ddc_sdk.dill file and have
test.dart load that one instead of the manually built one from calling
./tool/kernel_sdk.dart.
- Add command-line arguments to dartdevk for passing in the path to the
SDK summary and the other summaries to compile against.
- Fix a little typo in processed_options.dart that was preventing it
from resolving "package:" URIs.
- In test.dart, when compiling a test, link in the summaries for all of
the test packages.
At runtime, it still uses the JS for those packages generated from the
old analyzer-based front end since the kernel-based compiler isn't
complete enough to compile any of those packages yet.
With all of this, if I change a test to:
import "package:expect/expect.dart";
main() {
Expect.equals("a", "b");
}
Then it compiles but fails at runtime. The compiler is completing, but
the generated code has some bugs. I don't know enough to fix them
myself, but here's what I've found out:
- In _libraryToModule(), the Library we get from kernel has a null
fileUri, so this returns an empty string. That in turn means the
generated JS tries to use "$" as the module name.
Using this works around it temporarily:
if (moduleName.isEmpty) moduleName = library.name;
- In _emitTopLevelNameNoInterop(), it doesn't handle the case where the
NamedNode is a static method on a class. It just generates the library
and method name, skipping the class, so "Expect.equals(1, 2)" gets
compiled to "expect.equals(1, 2)" instead of
"expect.Expect.equals(1, 2)".
Change-Id: I6bd9d98bc9706965160d8fb7cf70b20eeebab3a8
Reviewed-on: https://dart-review.googlesource.com/16687
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Vijay Menon <vsm@google.com>
37 lines
1.2 KiB
Dart
37 lines
1.2 KiB
Dart
#!/usr/bin/env dart
|
|
// Copyright (c) 2017, 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:async';
|
|
import 'dart:io';
|
|
import 'package:dev_compiler/src/kernel/target.dart';
|
|
import 'package:front_end/compiler_options.dart';
|
|
import 'package:front_end/kernel_generator.dart';
|
|
import 'package:kernel/kernel.dart';
|
|
import 'package:path/path.dart' as path;
|
|
|
|
Future main(List<String> args) async {
|
|
Directory.current = path.dirname(path.dirname(path.fromUri(Platform.script)));
|
|
|
|
var outputPath = path.absolute('lib/sdk/ddc_sdk.dill');
|
|
if (args.isNotEmpty) {
|
|
outputPath = args[0];
|
|
}
|
|
|
|
var target = new DevCompilerTarget();
|
|
var options = new CompilerOptions()
|
|
..compileSdk = true
|
|
..chaseDependencies = true
|
|
..packagesFileUri = path.toUri(path.absolute('../../.packages'))
|
|
..sdkRoot = path.toUri(path.absolute('tool/input_sdk'))
|
|
..target = target;
|
|
|
|
var inputs = target.extraRequiredLibraries.map(Uri.parse).toList();
|
|
var program = await kernelForBuildUnit(inputs, options);
|
|
|
|
// Useful for debugging:
|
|
// writeProgramToText(program);
|
|
await writeProgramToBinary(program, outputPath);
|
|
}
|