Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: lib/src/run_single.dart

Issue 2078453002: Speed up testing. (Closed) Base URL: git@github.com:dart-lang/rasta.git@visit_for_effect
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/run_batch.dart ('k') | test/kernel/kernel_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 library rasta.run_single; 5 library rasta.run_single;
6 6
7 import 'dart:async' show 7 import 'dart:async' show
8 Future; 8 Future;
9 9
10 import 'dart:io' show
11 IOSink;
12
13 import 'package:compiler/src/elements/elements.dart' show
14 CompilationUnitElement,
15 LibraryElement;
16
17 import 'package:kernel/ast.dart' as ir; 10 import 'package:kernel/ast.dart' as ir;
18 11
19 import 'package:kernel/binary/ast_to_binary.dart' show 12 import '../custom_compiler.dart' show
20 BinaryPrinter;
21
22 import 'package:kernel/text/ast_to_text.dart' show
23 Printer;
24
25 import 'package:rasta/custom_compiler.dart' show
26 CustomCompiler; 13 CustomCompiler;
27 14
28 import 'package:rasta/kernel.dart' show
29 Kernel;
30
31 import 'options.dart' show 15 import 'options.dart' show
32 Options; 16 Options;
33 17
34 import 'rastask.dart' show 18 import 'rastask.dart' show
35 Rastask, 19 Rastask;
36 openWrite;
37 20
38 class RunSingle extends Rastask { 21 class RunSingle extends Rastask {
39 RunSingle(CustomCompiler compiler, Stopwatch wallClock, Options options) 22 RunSingle(CustomCompiler compiler, Stopwatch wallClock, Options options)
40 : super(compiler, wallClock, options); 23 : super(compiler, wallClock, options);
41 24
42 Future<ir.TreeNode> run() async { 25 Future<ir.TreeNode> run() async {
43 Duration setupDuration = wallClock.elapsed; 26 await setup(globalOptions.input);
44 27 return runOne(globalOptions);
kasperl 2016/06/16 11:14:49 Very nice.
45 await compiler.setupSdk();
46
47 await compiler.setupPackages(options.input);
48
49 Kernel kernel = new Kernel(compiler);
50 ir.Library library = await kernel.loadLibrary(options.input);
51
52 bool generateLibrary = options.generateLibrary;
53 if (generateLibrary == null) {
54 generateLibrary = !kernel.hasMainMethod(options.input);
55 }
56 if (generateLibrary) {
57 kernel.processWorkQueue(targetLibrary: options.input);
58 } else {
59 if (!kernel.hasMainMethod(options.input)) {
60 throw "No main method in ${options.input}.";
61 }
62 kernel.processWorkQueue();
63 }
64
65 ir.Program program;
66 if (!generateLibrary) {
67 Iterable<ir.Procedure> mainMethods = library.procedures.where(
68 (ir.Procedure function) => function.name.name == "main");
69 program =
70 new ir.Program(new List<ir.Library>.from(kernel.libraries.values))
71 ..mainMethod = mainMethods.single;
72 }
73 compiler.printVerboseTimings(setupDuration);
74 if (options.output != null) {
75 await openWrite(options.output, (IOSink sink) {
76 BinaryPrinter printer = new BinaryPrinter(sink);
77 if (generateLibrary) {
78 printer.writeLibraryFile(library);
79 } else {
80 printer.writeProgramFile(program);
81 }
82 });
83 } else {
84 StringBuffer buffer = new StringBuffer();
85 Printer printer = new Printer(buffer);
86 if (generateLibrary) {
87 printer.writeLibraryFile(library);
88 } else {
89 printer.writeProgramFile(program);
90 }
91 print("$buffer");
92 }
93
94 if (options.dependenciesFile != null) {
95 await openWrite(options.dependenciesFile, (IOSink sink) {
96 void writeCompilationUnit(CompilationUnitElement unit) {
97 sink.write("${unit.script.resourceUri}\n");
98 }
99 kernel.forEachLibraryElement((LibraryElement library) {
100 library.compilationUnits.forEach(writeCompilationUnit);
101 });
102 });
103 }
104 return generateLibrary ? library : program;
105 } 28 }
106 } 29 }
OLDNEW
« no previous file with comments | « lib/src/run_batch.dart ('k') | test/kernel/kernel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698