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

Side by Side Diff: pkg/analyzer_cli/lib/src/options.dart

Issue 1830463002: Change analyzer_cli's "package mode" into a "build mode". (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library analyzer_cli.src.options; 5 library analyzer_cli.src.options;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analyzer_cli/src/driver.dart'; 9 import 'package:analyzer_cli/src/driver.dart';
10 import 'package:args/args.dart'; 10 import 'package:args/args.dart';
(...skipping 15 matching lines...) Expand all
26 /// Exit handler. 26 /// Exit handler.
27 /// 27 ///
28 /// *Visible for testing.* 28 /// *Visible for testing.*
29 typedef void ExitHandler(int code); 29 typedef void ExitHandler(int code);
30 30
31 /// Analyzer commandline configuration options. 31 /// Analyzer commandline configuration options.
32 class CommandLineOptions { 32 class CommandLineOptions {
33 /// The path to an analysis options file 33 /// The path to an analysis options file
34 final String analysisOptionsFile; 34 final String analysisOptionsFile;
35 35
36 /// The path to output analysis results when in build mode.
37 final String buildAnalysisOutput;
38
39 /// Whether to use build mode.
40 final bool buildMode;
41
42 /// List of summary file paths to use in build mode.
43 final List<String> buildSummaryInputs;
44
45 /// Whether to skip analysis when creating summaries in build mode.
46 final bool buildSummaryOnly;
47
48 /// The path to output the summary when creating summaries in build mode.
49 final String buildSummaryOutput;
50
51 /// Whether to suppress a nonzero exit code in build mode.
52 final bool buildSuppressExitCode;
53
36 /// The path to the dart SDK 54 /// The path to the dart SDK
37 String dartSdkPath; 55 String dartSdkPath;
38 56
39 /// A table mapping the names of defined variables to their values. 57 /// A table mapping the names of defined variables to their values.
40 final Map<String, String> definedVariables; 58 final Map<String, String> definedVariables;
41 59
42 /// Whether to report hints 60 /// Whether to report hints
43 final bool disableHints; 61 final bool disableHints;
44 62
45 /// Whether to display version information 63 /// Whether to display version information
(...skipping 24 matching lines...) Expand all
70 88
71 /// Whether to report lints 89 /// Whether to report lints
72 final bool lints; 90 final bool lints;
73 91
74 /// Whether to log additional analysis messages and exceptions 92 /// Whether to log additional analysis messages and exceptions
75 final bool log; 93 final bool log;
76 94
77 /// Whether to use machine format for error display 95 /// Whether to use machine format for error display
78 final bool machineFormat; 96 final bool machineFormat;
79 97
80 /// Whether to use the whole package analysis mode.
81 final bool packageMode;
82
83 /// The path of the root folder of the package to analyze.
84 final String packageModePath;
85
86 /// The name of the package being analyzed.
87 final String packageName;
88
89 /// Mapping of package names to package summary file paths.
90 final Map<String, String> packageSummaryInputs;
91
92 /// Whether to skip analysis when creating summaries.
93 final bool packageSummaryOnly;
94
95 /// The path to find the package summary.
96 final String packageSummaryOutput;
97
98 /// The path to the package root 98 /// The path to the package root
99 final String packageRootPath; 99 final String packageRootPath;
100 100
101 /// The path to a `.packages` configuration file 101 /// The path to a `.packages` configuration file
102 final String packageConfigPath; 102 final String packageConfigPath;
103 103
104 /// The path to a file to write a performance log. 104 /// The path to a file to write a performance log.
105 /// (Or null if not enabled.) 105 /// (Or null if not enabled.)
106 final String perfReport; 106 final String perfReport;
107 107
(...skipping 14 matching lines...) Expand all
122 122
123 /// Whether to treat warnings as fatal 123 /// Whether to treat warnings as fatal
124 final bool warningsAreFatal; 124 final bool warningsAreFatal;
125 125
126 /// Whether to use strong static checking. 126 /// Whether to use strong static checking.
127 final bool strongMode; 127 final bool strongMode;
128 128
129 /// Initialize options from the given parsed [args]. 129 /// Initialize options from the given parsed [args].
130 CommandLineOptions._fromArgs( 130 CommandLineOptions._fromArgs(
131 ArgResults args, Map<String, String> definedVariables) 131 ArgResults args, Map<String, String> definedVariables)
132 : dartSdkPath = args['dart-sdk'], 132 : buildAnalysisOutput = args['build-analysis-output'],
133 buildMode = args['build-mode'],
134 buildSummaryInputs = args['build-summary-input'],
135 buildSummaryOnly = args['build-summary-only'],
136 buildSummaryOutput = args['build-summary-output'],
137 buildSuppressExitCode = args['build-suppress-exit-code'],
138 dartSdkPath = args['dart-sdk'],
133 definedVariables = definedVariables, 139 definedVariables = definedVariables,
134 analysisOptionsFile = args['options'], 140 analysisOptionsFile = args['options'],
135 disableHints = args['no-hints'], 141 disableHints = args['no-hints'],
136 displayVersion = args['version'], 142 displayVersion = args['version'],
137 enableConditionalDirectives = args['enable-conditional-directives'], 143 enableConditionalDirectives = args['enable-conditional-directives'],
138 enableNullAwareOperators = args['enable-null-aware-operators'], 144 enableNullAwareOperators = args['enable-null-aware-operators'],
139 enableStrictCallChecks = args['enable-strict-call-checks'], 145 enableStrictCallChecks = args['enable-strict-call-checks'],
140 enableSuperMixins = args['supermixin'], 146 enableSuperMixins = args['supermixin'],
141 enableTypeChecks = args['enable_type_checks'], 147 enableTypeChecks = args['enable_type_checks'],
142 hintsAreFatal = args['fatal-hints'], 148 hintsAreFatal = args['fatal-hints'],
143 ignoreUnrecognizedFlags = args['ignore-unrecognized-flags'], 149 ignoreUnrecognizedFlags = args['ignore-unrecognized-flags'],
144 lints = args['lints'], 150 lints = args['lints'],
145 log = args['log'], 151 log = args['log'],
146 machineFormat = args['machine'] || args['format'] == 'machine', 152 machineFormat = args['machine'] || args['format'] == 'machine',
147 packageMode = args['package-mode'],
148 packageModePath = args['package-mode-path'],
149 packageName = args['package-name'],
150 packageSummaryInputs = _parsePackageSummaryInputs(args),
151 packageSummaryOnly = args['package-summary-only'],
152 packageSummaryOutput = args['package-summary-output'],
153 packageConfigPath = args['packages'], 153 packageConfigPath = args['packages'],
154 packageRootPath = args['package-root'], 154 packageRootPath = args['package-root'],
155 perfReport = args['x-perf-report'], 155 perfReport = args['x-perf-report'],
156 shouldBatch = args['batch'], 156 shouldBatch = args['batch'],
157 showPackageWarnings = args['show-package-warnings'] || 157 showPackageWarnings = args['show-package-warnings'] ||
158 args['package-warnings'] || 158 args['package-warnings'] ||
159 args['x-package-warnings-prefix'] != null, 159 args['x-package-warnings-prefix'] != null,
160 showPackageWarningsPrefix = args['x-package-warnings-prefix'], 160 showPackageWarningsPrefix = args['x-package-warnings-prefix'],
161 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'], 161 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'],
162 sourceFiles = args.rest, 162 sourceFiles = args.rest,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 help: 'Display this help message.', 297 help: 'Display this help message.',
298 defaultsTo: false, 298 defaultsTo: false,
299 negatable: false) 299 negatable: false)
300 ..addOption('url-mapping', 300 ..addOption('url-mapping',
301 help: '--url-mapping=libraryUri,/path/to/library.dart directs the ' 301 help: '--url-mapping=libraryUri,/path/to/library.dart directs the '
302 'analyzer to use "library.dart" as the source for an import ' 302 'analyzer to use "library.dart" as the source for an import '
303 'of "libraryUri".', 303 'of "libraryUri".',
304 allowMultiple: true, 304 allowMultiple: true,
305 splitCommas: false) 305 splitCommas: false)
306 // 306 //
307 // Package analysis mode and summary. 307 // Build mode.
308 // 308 //
309 ..addFlag('package-mode', 309 ..addOption('build-analysis-output',
310 help: 'Enable the whole package analysis mode. ' 310 help:
311 'Exactly one input path must be specified, which must be a path ' 311 'Specefies the path to the file where analysis results should be w ritten.',
scheglov 2016/03/23 01:11:50 "Specifies"
Paul Berry 2016/03/23 03:28:02 Done.
312 'to the folder with a Pub package.', 312 hide: true)
313 ..addFlag('build-mode',
314 // TODO(paulberry): add more documentation.
315 help: 'Enable build mode.',
313 defaultsTo: false, 316 defaultsTo: false,
314 negatable: false, 317 negatable: false,
315 hide: true) 318 hide: true)
316 ..addOption('package-mode-path', 319 ..addOption('build-summary-input',
317 help: 'The path of the root folder of the package to analyze.', 320 help: 'Path to a summary file that contains information from a '
321 'previous analysis run. May be specified multiple times.',
322 allowMultiple: true,
318 hide: true) 323 hide: true)
319 ..addOption('package-name', 324 ..addOption('build-summary-output',
320 help: 'The name of the package to analyze, as it is used by clients.', 325 help: 'Specifies the path to the file where the summary information '
326 'should be written.',
321 hide: true) 327 hide: true)
322 ..addOption('package-summary-input', 328 ..addFlag('build-summary-only',
323 help: '--package-summary-input=packageName,/path/to/package.sum ' 329 help: 'Disable analysis (only generate summaries).',
324 'specifies the summary file that contains information about ' 330 defaultsTo: false,
325 'every library of the specified package.', 331 negatable: false,
326 allowMultiple: true,
327 splitCommas: false,
328 hide: true) 332 hide: true)
329 ..addOption('package-summary-output', 333 ..addFlag('build-suppress-exit-code',
330 help: 'Specifies the path to the file where the summary information ' 334 help: 'Exit with code 0 even if errors are found.',
331 'about the package should be written to.',
332 hide: true)
333 ..addFlag('package-summary-only',
334 help: 'Disable analysis (only generate summaries).',
335 defaultsTo: false, 335 defaultsTo: false,
336 negatable: false, 336 negatable: false,
337 hide: true) 337 hide: true)
338 // 338 //
339 // Hidden flags. 339 // Hidden flags.
340 // 340 //
341 ..addFlag('enable-async', 341 ..addFlag('enable-async',
342 help: 'Enable support for the proposed async feature.', 342 help: 'Enable support for the proposed async feature.',
343 defaultsTo: false, 343 defaultsTo: false,
344 negatable: false, 344 negatable: false,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 419 }
420 return new CommandLineOptions._fromArgs(results, definedVariables); 420 return new CommandLineOptions._fromArgs(results, definedVariables);
421 } on FormatException catch (e) { 421 } on FormatException catch (e) {
422 errorSink.writeln(e.message); 422 errorSink.writeln(e.message);
423 _showUsage(parser); 423 _showUsage(parser);
424 exitHandler(15); 424 exitHandler(15);
425 return null; // Only reachable in testing. 425 return null; // Only reachable in testing.
426 } 426 }
427 } 427 }
428 428
429 /// Parse the `--package-summary-input` arguments into a Map of package
430 /// names to summary paths.
431 static Map<String, String> _parsePackageSummaryInputs(ArgResults args) {
432 Map<String, String> result = <String, String>{};
433 List<String> argList = args['package-summary-input'];
434 for (String arg in argList) {
435 int index = arg.indexOf(',');
436 if (index == -1) {
437 errorSink.writeln(
438 'The syntax is --package-summary-input=packageName,/path/to/pkg.sum' );
439 errorSink.writeln('No comma found in: $arg');
440 exitHandler(15);
441 return null; // Only reachable in testing.
442 }
443 String packageName = arg.substring(0, index);
444 String summaryPath = arg.substring(index + 1);
445 result[packageName] = summaryPath;
446 }
447 return result;
448 }
449
450 static _showUsage(parser) { 429 static _showUsage(parser) {
451 errorSink 430 errorSink
452 .writeln('Usage: $_binaryName [options...] <libraries to analyze...>'); 431 .writeln('Usage: $_binaryName [options...] <libraries to analyze...>');
453 errorSink.writeln(parser.getUsage()); 432 errorSink.writeln(parser.getUsage());
454 errorSink.writeln(''); 433 errorSink.writeln('');
455 errorSink.writeln( 434 errorSink.writeln(
456 'For more information, see http://www.dartlang.org/tools/analyzer.'); 435 'For more information, see http://www.dartlang.org/tools/analyzer.');
457 } 436 }
458 } 437 }
459 438
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 570
592 int _getNextFlagIndex(args, i) { 571 int _getNextFlagIndex(args, i) {
593 for (; i < args.length; ++i) { 572 for (; i < args.length; ++i) {
594 if (args[i].startsWith('--')) { 573 if (args[i].startsWith('--')) {
595 return i; 574 return i;
596 } 575 }
597 } 576 }
598 return i; 577 return i;
599 } 578 }
600 } 579 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698