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

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

Issue 2578113002: refactor DDC to support --ignore-unrecognized-flags (Closed)
Patch Set: merge Created 4 years 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 | « pkg/analyzer_cli/lib/src/options.dart ('k') | pkg/dev_compiler/test/worker/worker_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 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/command_line/arguments.dart' 6 import 'package:analyzer/src/command_line/arguments.dart'
7 show extractDefinedVariables; 7 show
8 extractDefinedVariables,
9 filterUnknownArguments,
10 ignoreUnrecognizedFlagsFlag;
8 import 'package:analyzer/src/generated/source.dart' show Source; 11 import 'package:analyzer/src/generated/source.dart' show Source;
9 import 'package:analyzer/src/summary/package_bundle_reader.dart' 12 import 'package:analyzer/src/summary/package_bundle_reader.dart'
10 show InSummarySource; 13 show InSummarySource;
11 import 'package:args/args.dart' show ArgParser, ArgResults; 14 import 'package:args/args.dart' show ArgParser, ArgResults;
12 import 'package:args/command_runner.dart' show UsageException; 15 import 'package:args/command_runner.dart' show UsageException;
13 import 'package:path/path.dart' as path; 16 import 'package:path/path.dart' as path;
14 17
15 import '../analyzer/context.dart' show AnalyzerOptions; 18 import '../analyzer/context.dart' show AnalyzerOptions;
16 import 'compiler.dart' show BuildUnit, CompilerOptions, ModuleCompiler; 19 import 'compiler.dart' show BuildUnit, CompilerOptions, ModuleCompiler;
17 import 'module_builder.dart'; 20 import 'module_builder.dart';
18 21
19 bool _verbose = false; 22 bool _verbose = false;
20 23
21 /// Runs a single compile for dartdevc. 24 /// Runs a single compile for dartdevc.
22 /// 25 ///
23 /// This handles argument parsing, usage, error handling. 26 /// This handles argument parsing, usage, error handling.
24 /// See bin/dartdevc.dart for the actual entry point, which includes Bazel 27 /// See bin/dartdevc.dart for the actual entry point, which includes Bazel
25 /// worker support. 28 /// worker support.
26 int compile(List<String> args, {void printFn(Object obj)}) { 29 int compile(List<String> args, {void printFn(Object obj)}) {
27 printFn ??= print; 30 printFn ??= print;
28 ArgResults argResults; 31 ArgResults argResults;
29 var declaredVars = <String, String>{}; 32 var declaredVars = <String, String>{};
30 try { 33 try {
31 args = extractDefinedVariables(args, declaredVars); 34 args = extractDefinedVariables(args, declaredVars);
32 argResults = _argParser().parse(args); 35 var parser = _argParser();
36 if (args.contains('--$ignoreUnrecognizedFlagsFlag')) {
37 args = filterUnknownArguments(args, parser);
38 }
39 argResults = parser.parse(args);
33 _verbose = argResults['verbose']; 40 _verbose = argResults['verbose'];
34 } on FormatException catch (error) { 41 } on FormatException catch (error) {
35 printFn('$error\n\n$_usageMessage'); 42 printFn('$error\n\n$_usageMessage');
36 return 64; 43 return 64;
37 } 44 }
38 try { 45 try {
39 _compile(argResults, declaredVars, printFn); 46 _compile(argResults, declaredVars, printFn);
40 return 0; 47 return 0;
41 } on UsageException catch (error) { 48 } on UsageException catch (error) {
42 // Incorrect usage, input file not found, etc. 49 // Incorrect usage, input file not found, etc.
(...skipping 27 matching lines...) Expand all
70 } 77 }
71 78
72 ArgParser _argParser({bool hide: true}) { 79 ArgParser _argParser({bool hide: true}) {
73 var argParser = new ArgParser(allowTrailingOptions: true) 80 var argParser = new ArgParser(allowTrailingOptions: true)
74 ..addFlag('help', 81 ..addFlag('help',
75 abbr: 'h', 82 abbr: 'h',
76 help: 'Display this message.\n' 83 help: 'Display this message.\n'
77 'Add --verbose to show hidden options.', 84 'Add --verbose to show hidden options.',
78 negatable: false) 85 negatable: false)
79 ..addFlag('verbose', abbr: 'v', help: 'Verbose output.') 86 ..addFlag('verbose', abbr: 'v', help: 'Verbose output.')
87 ..addFlag(ignoreUnrecognizedFlagsFlag,
88 help: 'Ignore unrecognized command line flags.',
89 defaultsTo: false,
90 negatable: false)
80 ..addOption('out', 91 ..addOption('out',
81 abbr: 'o', allowMultiple: true, help: 'Output file (required).') 92 abbr: 'o', allowMultiple: true, help: 'Output file (required).')
82 ..addOption('module-root', 93 ..addOption('module-root',
83 help: 'Root module directory.\n' 94 help: 'Root module directory.\n'
84 'Generated module paths are relative to this root.') 95 'Generated module paths are relative to this root.')
85 ..addOption('library-root', 96 ..addOption('library-root',
86 help: 'Root of source files.\n' 97 help: 'Root of source files.\n'
87 'Generated library names are relative to this root.'); 98 'Generated library names are relative to this root.');
88 addModuleFormatOptions(argParser, allowMultiple: true, hide: hide); 99 addModuleFormatOptions(argParser, allowMultiple: true, hide: hide);
89 AnalyzerOptions.addArguments(argParser, hide: hide); 100 AnalyzerOptions.addArguments(argParser, hide: hide);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 '\n\n${_argParser(hide: !_verbose).usage}'; 225 '\n\n${_argParser(hide: !_verbose).usage}';
215 226
216 void _usageException(String message) { 227 void _usageException(String message) {
217 throw new UsageException(message, _usageMessage); 228 throw new UsageException(message, _usageMessage);
218 } 229 }
219 230
220 /// Thrown when the input source code has errors. 231 /// Thrown when the input source code has errors.
221 class CompileErrorException implements Exception { 232 class CompileErrorException implements Exception {
222 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; 233 toString() => '\nPlease fix all errors before compiling (warnings are okay).';
223 } 234 }
OLDNEW
« no previous file with comments | « pkg/analyzer_cli/lib/src/options.dart ('k') | pkg/dev_compiler/test/worker/worker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698