mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 14:07:57 +00:00
Support compiling the SDK from source
Change-Id: Ib5df97ef143c2cf98fc3d92a81d0f6b2f4cb1224 Reviewed-on: https://dart-review.googlesource.com/30452 Commit-Queue: Peter von der Ahé <ahe@google.com> Reviewed-by: Jens Johansen <jensj@google.com>
This commit is contained in:
parent
f2c2c99714
commit
3b6e403f1b
|
@ -105,6 +105,9 @@ class IncrementalCompiler extends DeprecatedIncrementalKernelGenerator {
|
|||
uriToSource: c.uriToSource);
|
||||
for (LibraryBuilder library in reusedLibraries) {
|
||||
userCode.loader.builders[library.uri] = library;
|
||||
if (library.uri.scheme == "dart" && library.uri.path == "core") {
|
||||
userCode.loader.coreLibrary = library;
|
||||
}
|
||||
}
|
||||
|
||||
userCode.read(entryPoint);
|
||||
|
|
|
@ -242,6 +242,7 @@ class KernelTarget extends TargetImplementation {
|
|||
program.addMetadataRepository(metadataCollector.repository);
|
||||
}
|
||||
loader.computeHierarchy(program);
|
||||
computeCoreTypes();
|
||||
loader.checkOverrides(myClasses);
|
||||
if (!loader.target.disableTypeInference) {
|
||||
loader.prepareTopLevelInference(myClasses);
|
||||
|
@ -513,6 +514,41 @@ class KernelTarget extends TargetImplementation {
|
|||
isSyntheticDefault: true);
|
||||
}
|
||||
|
||||
void computeCoreTypes() {
|
||||
List<Library> libraries = <Library>[];
|
||||
for (String platformLibrary in const [
|
||||
"dart:_internal",
|
||||
"dart:async",
|
||||
"dart:core",
|
||||
"dart:mirrors"
|
||||
]) {
|
||||
Uri uri = Uri.parse(platformLibrary);
|
||||
LibraryBuilder library = loader.builders[uri];
|
||||
if (library == null) {
|
||||
// TODO(ahe): This is working around a bug in kernel_driver_test or
|
||||
// kernel_driver.
|
||||
bool found = false;
|
||||
for (Library target in dillTarget.loader.libraries) {
|
||||
if (target.importUri == uri) {
|
||||
libraries.add(target);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found && uri.path != "mirrors") {
|
||||
// dart:mirrors is optional.
|
||||
throw "Can't find $uri";
|
||||
}
|
||||
} else {
|
||||
libraries.add(library.target);
|
||||
}
|
||||
}
|
||||
Program plaformLibraries = new Program();
|
||||
// Add libraries directly to prevent that their parents are changed.
|
||||
plaformLibraries.libraries.addAll(libraries);
|
||||
loader.computeCoreTypes(plaformLibraries);
|
||||
}
|
||||
|
||||
void finishAllConstructors(List<SourceClassBuilder> builders) {
|
||||
Class objectClass = this.objectClass;
|
||||
for (SourceClassBuilder builder in builders) {
|
||||
|
|
|
@ -536,6 +536,9 @@ class SourceLoader<L> extends Loader<L> {
|
|||
void computeHierarchy(Program program) {
|
||||
hierarchy = new IncrementalClassHierarchy();
|
||||
ticker.logMs("Computed class hierarchy");
|
||||
}
|
||||
|
||||
void computeCoreTypes(Program program) {
|
||||
coreTypes = new CoreTypes(program);
|
||||
ticker.logMs("Computed core types");
|
||||
}
|
||||
|
|
68
pkg/front_end/test/fasta/incremental_hello_test.dart
Normal file
68
pkg/front_end/test/fasta/incremental_hello_test.dart
Normal file
|
@ -0,0 +1,68 @@
|
|||
// 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.md file.
|
||||
|
||||
library fasta.test.incremental_dynamic_test;
|
||||
|
||||
import 'package:async_helper/async_helper.dart' show asyncTest;
|
||||
|
||||
import 'package:expect/expect.dart' show Expect;
|
||||
|
||||
import "package:front_end/src/api_prototype/compiler_options.dart"
|
||||
show CompilerOptions;
|
||||
|
||||
import 'package:front_end/src/base/processed_options.dart'
|
||||
show ProcessedOptions;
|
||||
|
||||
import 'package:front_end/src/fasta/compiler_context.dart' show CompilerContext;
|
||||
|
||||
import 'package:front_end/src/fasta/fasta_codes.dart'
|
||||
show LocatedMessage, codeDuplicatedDefinition;
|
||||
|
||||
import 'package:front_end/src/fasta/incremental_compiler.dart'
|
||||
show FastaDelta, IncrementalCompiler;
|
||||
|
||||
import 'package:front_end/src/fasta/severity.dart' show Severity;
|
||||
|
||||
void problemHandler(LocatedMessage message, Severity severity, String formatted,
|
||||
int line, int column) {
|
||||
if (message.code != codeDuplicatedDefinition ||
|
||||
message.arguments["name"] != "dynamic") {
|
||||
throw "Unexpected message: $formatted";
|
||||
} else {
|
||||
print(formatted);
|
||||
}
|
||||
}
|
||||
|
||||
test() async {
|
||||
final CompilerOptions optionBuilder = new CompilerOptions()
|
||||
..librariesSpecificationUri = Uri.base.resolve("sdk/lib/libraries.json")
|
||||
..packagesFileUri = Uri.base.resolve(".packages")
|
||||
..strongMode = false
|
||||
..onProblem = problemHandler;
|
||||
|
||||
final ProcessedOptions options =
|
||||
new ProcessedOptions(optionBuilder, false, []);
|
||||
|
||||
IncrementalCompiler compiler =
|
||||
new IncrementalCompiler(new CompilerContext(options));
|
||||
|
||||
Uri helloDart = Uri.base.resolve("pkg/front_end/testcases/hello.dart");
|
||||
|
||||
FastaDelta delta = await compiler.computeDelta(entryPoint: helloDart);
|
||||
|
||||
// Expect that the new program contains at least the following libraries:
|
||||
// dart:core, dart:async, and hello.dart.
|
||||
Expect.isTrue(delta.newProgram.libraries.length > 2);
|
||||
|
||||
compiler.invalidate(helloDart);
|
||||
|
||||
delta = await compiler.computeDelta(entryPoint: helloDart);
|
||||
// Expect that the new program contains exactly hello.dart
|
||||
Expect.isTrue(delta.newProgram.libraries.length == 1);
|
||||
print("new program has expected length");
|
||||
}
|
||||
|
||||
void main() {
|
||||
asyncTest(test);
|
||||
}
|
Loading…
Reference in a new issue