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

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/command.dart

Issue 2757753002: Migrate DDC to the new analysis driver.
Patch Set: Rebase Created 3 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
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 file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async';
5 import 'dart:io'; 6 import 'dart:io';
6 import 'package:analyzer/src/command_line/arguments.dart' 7 import 'package:analyzer/src/command_line/arguments.dart'
7 show 8 show
8 defineAnalysisArguments, 9 defineAnalysisArguments,
9 filterUnknownArguments, 10 filterUnknownArguments,
10 ignoreUnrecognizedFlagsFlag; 11 ignoreUnrecognizedFlagsFlag;
11 import 'package:analyzer/src/generated/source.dart' show Source; 12 import 'package:analyzer/src/generated/source.dart' show Source;
12 import 'package:analyzer/src/summary/package_bundle_reader.dart' 13 import 'package:analyzer/src/summary/package_bundle_reader.dart'
13 show ConflictingSummaryException, InSummarySource; 14 show ConflictingSummaryException, InSummarySource;
14 import 'package:args/args.dart' show ArgParser, ArgResults; 15 import 'package:args/args.dart' show ArgParser, ArgResults;
15 import 'package:args/command_runner.dart' show UsageException; 16 import 'package:args/command_runner.dart' show UsageException;
17 import 'package:dev_compiler/src/compiler/compiler.dart';
16 import 'package:path/path.dart' as path; 18 import 'package:path/path.dart' as path;
17 19
18 import '../analyzer/context.dart' show AnalyzerOptions; 20 import '../analyzer/context.dart' show AnalyzerOptions;
19 import 'compiler.dart' show BuildUnit, CompilerOptions, ModuleCompiler;
20 import 'module_builder.dart'; 21 import 'module_builder.dart';
21 22
22 const _binaryName = 'dartdevc'; 23 const _binaryName = 'dartdevc';
23 24
24 bool _verbose = false; 25 bool _verbose = false;
25 26
26 /// Runs a single compile for dartdevc. 27 /// Runs a single compile for dartdevc.
27 /// 28 ///
28 /// This handles argument parsing, usage, error handling. 29 /// This handles argument parsing, usage, error handling.
29 /// See bin/dartdevc.dart for the actual entry point, which includes Bazel 30 /// See bin/dartdevc.dart for the actual entry point, which includes Bazel
30 /// worker support. 31 /// worker support.
31 int compile(List<String> args, {void printFn(Object obj)}) { 32 Future<int> compile(List<String> args, {void printFn(Object obj)}) async {
32 printFn ??= print; 33 printFn ??= print;
33 34
34 ArgResults argResults; 35 ArgResults argResults;
35 AnalyzerOptions analyzerOptions; 36 AnalyzerOptions analyzerOptions;
36 try { 37 try {
37 var parser = ddcArgParser(); 38 var parser = ddcArgParser();
38 if (args.contains('--$ignoreUnrecognizedFlagsFlag')) { 39 if (args.contains('--$ignoreUnrecognizedFlagsFlag')) {
39 args = filterUnknownArguments(args, parser); 40 args = filterUnknownArguments(args, parser);
40 } 41 }
41 argResults = parser.parse(args); 42 argResults = parser.parse(args);
42 analyzerOptions = new AnalyzerOptions.fromArguments(argResults); 43 analyzerOptions = new AnalyzerOptions.fromArguments(argResults);
43 } on FormatException catch (error) { 44 } on FormatException catch (error) {
44 printFn('$error\n\n$_usageMessage'); 45 printFn('$error\n\n$_usageMessage');
45 return 64; 46 return 64;
46 } 47 }
47 48
48 _verbose = argResults['verbose']; 49 _verbose = argResults['verbose'];
49 if (argResults['help'] || args.isEmpty) { 50 if (argResults['help'] || args.isEmpty) {
50 printFn(_usageMessage); 51 printFn(_usageMessage);
51 return 0; 52 return 0;
52 } 53 }
53 54
54 if (argResults['version']) { 55 if (argResults['version']) {
55 printFn('$_binaryName version ${_getVersion()}'); 56 printFn('$_binaryName version ${_getVersion()}');
56 return 0; 57 return 0;
57 } 58 }
58 59
59 try { 60 try {
60 _compile(argResults, analyzerOptions, printFn); 61 await _compile(argResults, analyzerOptions, printFn);
61 return 0; 62 return 0;
62 } on UsageException catch (error) { 63 } on UsageException catch (error) {
63 // Incorrect usage, input file not found, etc. 64 // Incorrect usage, input file not found, etc.
64 printFn(error); 65 printFn(error);
65 return 64; 66 return 64;
66 } on ConflictingSummaryException catch (error) { 67 } on ConflictingSummaryException catch (error) {
67 // Same input file appears in multiple provided summaries. 68 // Same input file appears in multiple provided summaries.
68 printFn(error); 69 printFn(error);
69 return 65; 70 return 65;
70 } on CompileErrorException catch (error) { 71 } on CompileErrorException catch (error) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 125
125 bool _changed(List<int> list1, List<int> list2) { 126 bool _changed(List<int> list1, List<int> list2) {
126 var length = list1.length; 127 var length = list1.length;
127 if (length != list2.length) return true; 128 if (length != list2.length) return true;
128 for (var i = 0; i < length; ++i) { 129 for (var i = 0; i < length; ++i) {
129 if (list1[i] != list2[i]) return true; 130 if (list1[i] != list2[i]) return true;
130 } 131 }
131 return false; 132 return false;
132 } 133 }
133 134
134 void _compile(ArgResults argResults, AnalyzerOptions analyzerOptions, 135 Future<Null> _compile(ArgResults argResults, AnalyzerOptions analyzerOptions,
135 void printFn(Object obj)) { 136 void printFn(Object obj)) async {
136 var compiler = new ModuleCompiler(analyzerOptions); 137 var compiler = new ModuleCompiler(analyzerOptions);
137 var compilerOpts = new CompilerOptions.fromArguments(argResults); 138 var compilerOpts = new CompilerOptions.fromArguments(argResults);
138 var outPaths = argResults['out'] as List<String>; 139 var outPaths = argResults['out'] as List<String>;
139 var moduleFormats = parseModuleFormatOption(argResults); 140 var moduleFormats = parseModuleFormatOption(argResults);
140 bool singleOutFile = argResults['single-out-file']; 141 bool singleOutFile = argResults['single-out-file'];
141 if (singleOutFile) { 142 if (singleOutFile) {
142 for (var format in moduleFormats) { 143 for (var format in moduleFormats) {
143 if (format != ModuleFormat.amd && format != ModuleFormat.legacy) { 144 if (format != ModuleFormat.amd && format != ModuleFormat.legacy) {
144 _usageException('Format $format cannot be combined with ' 145 _usageException('Format $format cannot be combined with '
145 'single-out-file. Only amd and legacy modes are supported.'); 146 'single-out-file. Only amd and legacy modes are supported.');
(...skipping 30 matching lines...) Expand all
176 modulePath = 177 modulePath =
177 path.withoutExtension(path.relative(firstOutPath, from: moduleRoot)); 178 path.withoutExtension(path.relative(firstOutPath, from: moduleRoot));
178 } else { 179 } else {
179 moduleRoot = path.dirname(firstOutPath); 180 moduleRoot = path.dirname(firstOutPath);
180 modulePath = path.basenameWithoutExtension(firstOutPath); 181 modulePath = path.basenameWithoutExtension(firstOutPath);
181 } 182 }
182 183
183 var unit = new BuildUnit(modulePath, libraryRoot, argResults.rest, 184 var unit = new BuildUnit(modulePath, libraryRoot, argResults.rest,
184 (source) => _moduleForLibrary(moduleRoot, source, compilerOpts)); 185 (source) => _moduleForLibrary(moduleRoot, source, compilerOpts));
185 186
186 var module = compiler.compile(unit, compilerOpts); 187 JSModuleFile module = await compiler.compile(unit, compilerOpts);
187 module.errors.forEach(printFn); 188 module.errors.forEach(printFn);
188 189
189 if (!module.isValid) { 190 if (!module.isValid) {
190 throw compilerOpts.unsafeForceCompile 191 throw compilerOpts.unsafeForceCompile
191 ? new ForceCompileErrorException() 192 ? new ForceCompileErrorException()
192 : new CompileErrorException(); 193 : new CompileErrorException();
193 } 194 }
194 195
195 // Write JS file, as well as source map and summary (if requested). 196 // Write JS file, as well as source map and summary (if requested).
196 for (var i = 0; i < outPaths.length; i++) { 197 for (var i = 0; i < outPaths.length; i++) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 /// Thrown when the input source code has errors. 266 /// Thrown when the input source code has errors.
266 class CompileErrorException implements Exception { 267 class CompileErrorException implements Exception {
267 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; 268 toString() => '\nPlease fix all errors before compiling (warnings are okay).';
268 } 269 }
269 270
270 /// Thrown when force compilation failed (probably due to static errors). 271 /// Thrown when force compilation failed (probably due to static errors).
271 class ForceCompileErrorException extends CompileErrorException { 272 class ForceCompileErrorException extends CompileErrorException {
272 toString() => 273 toString() =>
273 '\nForce-compilation not successful. Please check static errors.'; 274 '\nForce-compilation not successful. Please check static errors.';
274 } 275 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/code_generator.dart ('k') | pkg/dev_compiler/lib/src/compiler/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698