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

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

Issue 2503803004: fix #27784 and fix #27785, fromEnvironment constants in DDC (Closed)
Patch Set: allow trailing opts Created 4 years, 1 month 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:io'; 5 import 'dart:io';
6 import 'package:analyzer/src/generated/source.dart' show Source; 6 import 'package:analyzer/src/generated/source.dart' show Source;
7 import 'package:analyzer/src/summary/package_bundle_reader.dart' 7 import 'package:analyzer/src/summary/package_bundle_reader.dart'
8 show InSummarySource; 8 show InSummarySource;
9 import 'package:args/args.dart' show ArgParser, ArgResults; 9 import 'package:args/args.dart' show ArgParser, ArgResults;
10 import 'package:args/command_runner.dart' show UsageException; 10 import 'package:args/command_runner.dart' show UsageException;
11 import 'package:path/path.dart' as path; 11 import 'package:path/path.dart' as path;
12 12
13 import '../analyzer/context.dart' show AnalyzerOptions; 13 import '../analyzer/context.dart' show AnalyzerOptions, parseDeclaredVariables;
14 import 'compiler.dart' show BuildUnit, CompilerOptions, ModuleCompiler; 14 import 'compiler.dart' show BuildUnit, CompilerOptions, ModuleCompiler;
15 import 'module_builder.dart'; 15 import 'module_builder.dart';
16 16
17 final ArgParser _argParser = () { 17 final ArgParser _argParser = () {
18 var argParser = new ArgParser(allowTrailingOptions: true) 18 var argParser = new ArgParser(allowTrailingOptions: true)
19 ..addFlag('help', abbr: 'h', help: 'Display this message.') 19 ..addFlag('help', abbr: 'h', help: 'Display this message.')
20 ..addOption('out', 20 ..addOption('out',
21 abbr: 'o', allowMultiple: true, help: 'Output file (required).') 21 abbr: 'o', allowMultiple: true, help: 'Output file (required).')
22 ..addOption('module-root', 22 ..addOption('module-root',
23 help: 'Root module directory.\n' 23 help: 'Root module directory.\n'
(...skipping 10 matching lines...) Expand all
34 }(); 34 }();
35 35
36 /// Runs a single compile for dartdevc. 36 /// Runs a single compile for dartdevc.
37 /// 37 ///
38 /// This handles argument parsing, usage, error handling. 38 /// This handles argument parsing, usage, error handling.
39 /// See bin/dartdevc.dart for the actual entry point, which includes Bazel 39 /// See bin/dartdevc.dart for the actual entry point, which includes Bazel
40 /// worker support. 40 /// worker support.
41 int compile(List<String> args, {void printFn(Object obj)}) { 41 int compile(List<String> args, {void printFn(Object obj)}) {
42 printFn ??= print; 42 printFn ??= print;
43 ArgResults argResults; 43 ArgResults argResults;
44 var declaredVars = <String, String>{};
44 try { 45 try {
45 argResults = _argParser.parse(args); 46 argResults = _argParser.parse(parseDeclaredVariables(args, declaredVars));
46 } on FormatException catch (error) { 47 } on FormatException catch (error) {
47 printFn('$error\n\n$_usageMessage'); 48 printFn('$error\n\n$_usageMessage');
48 return 64; 49 return 64;
49 } 50 }
50 try { 51 try {
51 _compile(argResults, printFn); 52 _compile(argResults, declaredVars, printFn);
52 return 0; 53 return 0;
53 } on UsageException catch (error) { 54 } on UsageException catch (error) {
54 // Incorrect usage, input file not found, etc. 55 // Incorrect usage, input file not found, etc.
55 printFn(error); 56 printFn(error);
56 return 64; 57 return 64;
57 } on CompileErrorException catch (error) { 58 } on CompileErrorException catch (error) {
58 // Code has error(s) and failed to compile. 59 // Code has error(s) and failed to compile.
59 printFn(error); 60 printFn(error);
60 return 1; 61 return 1;
61 } catch (error, stackTrace) { 62 } catch (error, stackTrace) {
(...skipping 21 matching lines...) Expand all
83 84
84 bool _changed(List<int> list1, List<int> list2) { 85 bool _changed(List<int> list1, List<int> list2) {
85 var length = list1.length; 86 var length = list1.length;
86 if (length != list2.length) return true; 87 if (length != list2.length) return true;
87 for (var i = 0; i < length; ++i) { 88 for (var i = 0; i < length; ++i) {
88 if (list1[i] != list2[i]) return true; 89 if (list1[i] != list2[i]) return true;
89 } 90 }
90 return false; 91 return false;
91 } 92 }
92 93
93 void _compile(ArgResults argResults, void printFn(Object obj)) { 94 void _compile(ArgResults argResults, Map<String, String> declaredVars,
95 void printFn(Object obj)) {
94 if (argResults['help']) { 96 if (argResults['help']) {
95 printFn(_usageMessage); 97 printFn(_usageMessage);
96 return; 98 return;
97 } 99 }
98 var compiler = 100 var compiler = new ModuleCompiler(
99 new ModuleCompiler(new AnalyzerOptions.fromArguments(argResults)); 101 new AnalyzerOptions.fromArguments(argResults, declaredVars));
100 var compilerOpts = new CompilerOptions.fromArguments(argResults); 102 var compilerOpts = new CompilerOptions.fromArguments(argResults);
101 var outPaths = argResults['out'] as List<String>; 103 var outPaths = argResults['out'] as List<String>;
102 var moduleFormats = parseModuleFormatOption(argResults); 104 var moduleFormats = parseModuleFormatOption(argResults);
103 bool singleOutFile = argResults['single-out-file']; 105 bool singleOutFile = argResults['single-out-file'];
104 if (singleOutFile) { 106 if (singleOutFile) {
105 for (var format in moduleFormats) { 107 for (var format in moduleFormats) {
106 if (format != ModuleFormat.amd && format != ModuleFormat.legacy) { 108 if (format != ModuleFormat.amd && format != ModuleFormat.legacy) {
107 _usageException('Format $format cannot be combined with ' 109 _usageException('Format $format cannot be combined with '
108 'single-out-file. Only amd and legacy modes are supported.'); 110 'single-out-file. Only amd and legacy modes are supported.');
109 } 111 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 '\n\n${_argParser.usage}'; 206 '\n\n${_argParser.usage}';
205 207
206 void _usageException(String message) { 208 void _usageException(String message) {
207 throw new UsageException(message, _usageMessage); 209 throw new UsageException(message, _usageMessage);
208 } 210 }
209 211
210 /// Thrown when the input source code has errors. 212 /// Thrown when the input source code has errors.
211 class CompileErrorException implements Exception { 213 class CompileErrorException implements Exception {
212 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; 214 toString() => '\nPlease fix all errors before compiling (warnings are okay).';
213 } 215 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698