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

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

Issue 1848543002: Support --persistent_worker flag in --build-mode. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fixes for review comments. Created 4 years, 8 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 21 matching lines...) Expand all
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. 36 /// The path to output analysis results when in build mode.
37 final String buildAnalysisOutput; 37 final String buildAnalysisOutput;
38 38
39 /// Whether to use build mode. 39 /// Whether to use build mode.
40 final bool buildMode; 40 final bool buildMode;
41 41
42 /// Whether to use build mode as a Bazel persistent worker.
43 final bool buildModePersistentWorker;
44
42 /// List of summary file paths to use in build mode. 45 /// List of summary file paths to use in build mode.
43 final List<String> buildSummaryInputs; 46 final List<String> buildSummaryInputs;
44 47
45 /// Whether to skip analysis when creating summaries in build mode. 48 /// Whether to skip analysis when creating summaries in build mode.
46 final bool buildSummaryOnly; 49 final bool buildSummaryOnly;
47 50
48 /// Whether to create summaries using only ASTs, i.e. don't perform 51 /// Whether to create summaries using only ASTs, i.e. don't perform
49 /// resolution. 52 /// resolution.
50 final bool buildSummaryOnlyAst; 53 final bool buildSummaryOnlyAst;
51 54
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 final bool warningsAreFatal; 141 final bool warningsAreFatal;
139 142
140 /// Whether to use strong static checking. 143 /// Whether to use strong static checking.
141 final bool strongMode; 144 final bool strongMode;
142 145
143 /// Initialize options from the given parsed [args]. 146 /// Initialize options from the given parsed [args].
144 CommandLineOptions._fromArgs( 147 CommandLineOptions._fromArgs(
145 ArgResults args, Map<String, String> definedVariables) 148 ArgResults args, Map<String, String> definedVariables)
146 : buildAnalysisOutput = args['build-analysis-output'], 149 : buildAnalysisOutput = args['build-analysis-output'],
147 buildMode = args['build-mode'], 150 buildMode = args['build-mode'],
151 buildModePersistentWorker = args['persistent_worker'],
148 buildSummaryFallback = args['build-summary-fallback'], 152 buildSummaryFallback = args['build-summary-fallback'],
149 buildSummaryInputs = args['build-summary-input'], 153 buildSummaryInputs = args['build-summary-input'],
150 buildSummaryOnly = args['build-summary-only'], 154 buildSummaryOnly = args['build-summary-only'],
151 buildSummaryOnlyAst = args['build-summary-only-ast'], 155 buildSummaryOnlyAst = args['build-summary-only-ast'],
152 buildSummaryOnlyDiet = args['build-summary-only-diet'], 156 buildSummaryOnlyDiet = args['build-summary-only-diet'],
153 buildSummaryExcludeInformative = 157 buildSummaryExcludeInformative =
154 args['build-summary-exclude-informative'], 158 args['build-summary-exclude-informative'],
155 buildSummaryOutput = args['build-summary-output'], 159 buildSummaryOutput = args['build-summary-output'],
156 buildSuppressExitCode = args['build-suppress-exit-code'], 160 buildSuppressExitCode = args['build-suppress-exit-code'],
157 dartSdkPath = args['dart-sdk'], 161 dartSdkPath = args['dart-sdk'],
(...skipping 21 matching lines...) Expand all
179 showPackageWarningsPrefix = args['x-package-warnings-prefix'], 183 showPackageWarningsPrefix = args['x-package-warnings-prefix'],
180 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'], 184 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'],
181 sourceFiles = args.rest, 185 sourceFiles = args.rest,
182 warningsAreFatal = args['fatal-warnings'], 186 warningsAreFatal = args['fatal-warnings'],
183 strongMode = args['strong']; 187 strongMode = args['strong'];
184 188
185 /// Parse [args] into [CommandLineOptions] describing the specified 189 /// Parse [args] into [CommandLineOptions] describing the specified
186 /// analyzer options. In case of a format error, calls [printAndFail], which 190 /// analyzer options. In case of a format error, calls [printAndFail], which
187 /// by default prints an error message to stderr and exits. 191 /// by default prints an error message to stderr and exits.
188 static CommandLineOptions parse(List<String> args, 192 static CommandLineOptions parse(List<String> args,
189 [printAndFail = printAndFail]) { 193 [printAndFail(String msg) = printAndFail]) {
190 CommandLineOptions options = _parse(args); 194 CommandLineOptions options = _parse(args);
191 // Check SDK. 195 // Check SDK.
192 { 196 {
193 // Infer if unspecified. 197 // Infer if unspecified.
194 if (options.dartSdkPath == null) { 198 if (options.dartSdkPath == null) {
195 Directory sdkDir = getSdkDir(args); 199 Directory sdkDir = getSdkDir(args);
196 if (sdkDir != null) { 200 if (sdkDir != null) {
197 options.dartSdkPath = sdkDir.path; 201 options.dartSdkPath = sdkDir.path;
198 } 202 }
199 } 203 }
(...skipping 22 matching lines...) Expand all
222 } 226 }
223 227
224 // OK. Report deprecated options. 228 // OK. Report deprecated options.
225 if (options.enableNullAwareOperators) { 229 if (options.enableNullAwareOperators) {
226 errorSink.writeln( 230 errorSink.writeln(
227 "Info: Option '--enable-null-aware-operators' is no longer needed. " 231 "Info: Option '--enable-null-aware-operators' is no longer needed. "
228 "Null aware operators are supported by default."); 232 "Null aware operators are supported by default.");
229 } 233 }
230 234
231 // Build mode. 235 // Build mode.
236 if (options.buildModePersistentWorker && !options.buildMode) {
237 printAndFail('The option --persisten_worker can be used only '
238 'together with --build-mode.');
239 }
232 if (options.buildSummaryOnlyDiet && !options.buildSummaryOnly) { 240 if (options.buildSummaryOnlyDiet && !options.buildSummaryOnly) {
233 printAndFail('The option --build-summary-only-diet can be used only ' 241 printAndFail('The option --build-summary-only-diet can be used only '
234 'together with --build-summary-only.'); 242 'together with --build-summary-only.');
235 } 243 }
236 244
237 return options; 245 return options;
238 } 246 }
239 247
240 static String _getVersion() { 248 static String _getVersion() {
241 try { 249 try {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 negatable: false) 332 negatable: false)
325 ..addOption('url-mapping', 333 ..addOption('url-mapping',
326 help: '--url-mapping=libraryUri,/path/to/library.dart directs the ' 334 help: '--url-mapping=libraryUri,/path/to/library.dart directs the '
327 'analyzer to use "library.dart" as the source for an import ' 335 'analyzer to use "library.dart" as the source for an import '
328 'of "libraryUri".', 336 'of "libraryUri".',
329 allowMultiple: true, 337 allowMultiple: true,
330 splitCommas: false) 338 splitCommas: false)
331 // 339 //
332 // Build mode. 340 // Build mode.
333 // 341 //
342 ..addFlag('persistent_worker',
343 help: 'Enable Bazel persistent worker mode.',
344 defaultsTo: false,
345 negatable: false,
346 hide: true)
334 ..addOption('build-analysis-output', 347 ..addOption('build-analysis-output',
335 help: 348 help:
336 'Specifies the path to the file where analysis results should be w ritten.', 349 'Specifies the path to the file where analysis results should be w ritten.',
337 hide: true) 350 hide: true)
338 ..addFlag('build-mode', 351 ..addFlag('build-mode',
339 // TODO(paulberry): add more documentation. 352 // TODO(paulberry): add more documentation.
340 help: 'Enable build mode.', 353 help: 'Enable build mode.',
341 defaultsTo: false, 354 defaultsTo: false,
342 negatable: false, 355 negatable: false,
343 hide: true) 356 hide: true)
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 hide: true) 443 hide: true)
431 ..addFlag('strong', 444 ..addFlag('strong',
432 help: 'Enable strong static checks (https://goo.gl/DqcBsw)'); 445 help: 'Enable strong static checks (https://goo.gl/DqcBsw)');
433 446
434 try { 447 try {
435 // TODO(scheglov) https://code.google.com/p/dart/issues/detail?id=11061 448 // TODO(scheglov) https://code.google.com/p/dart/issues/detail?id=11061
436 args = 449 args =
437 args.map((String arg) => arg == '-batch' ? '--batch' : arg).toList(); 450 args.map((String arg) => arg == '-batch' ? '--batch' : arg).toList();
438 Map<String, String> definedVariables = <String, String>{}; 451 Map<String, String> definedVariables = <String, String>{};
439 var results = parser.parse(args, definedVariables); 452 var results = parser.parse(args, definedVariables);
453
454 // Persistent worker.
455 if (args.contains('--persistent_worker')) {
456 if (args.length != 2 || !args.contains('--build-mode')) {
457 printAndFail('The --persistent_worker flag should be used with and '
458 'only with the --build-mode flag.');
459 return null; // Only reachable in testing.
460 }
461 return new CommandLineOptions._fromArgs(results, definedVariables);
462 }
463
440 // Help requests. 464 // Help requests.
441 if (results['help']) { 465 if (results['help']) {
442 _showUsage(parser); 466 _showUsage(parser);
443 exitHandler(0); 467 exitHandler(0);
444 return null; // Only reachable in testing. 468 return null; // Only reachable in testing.
445 } 469 }
446 // Batch mode and input files. 470 // Batch mode and input files.
447 if (results['batch']) { 471 if (results['batch']) {
448 if (results.rest.isNotEmpty) { 472 if (results.rest.isNotEmpty) {
449 errorSink.writeln('No source files expected in the batch mode.'); 473 errorSink.writeln('No source files expected in the batch mode.');
450 _showUsage(parser); 474 _showUsage(parser);
451 exitHandler(15); 475 exitHandler(15);
452 return null; // Only reachable in testing. 476 return null; // Only reachable in testing.
453 } 477 }
478 } else if (results['persistent_worker']) {
479 if (results.rest.isNotEmpty) {
480 errorSink.writeln(
481 'No source files expected in the persistent worker mode.');
482 _showUsage(parser);
483 exitHandler(15);
484 return null; // Only reachable in testing.
485 }
454 } else if (results['version']) { 486 } else if (results['version']) {
455 outSink.write('$_binaryName version ${_getVersion()}'); 487 outSink.write('$_binaryName version ${_getVersion()}');
456 exitHandler(0); 488 exitHandler(0);
457 return null; // Only reachable in testing. 489 return null; // Only reachable in testing.
458 } else { 490 } else {
459 if (results.rest.isEmpty) { 491 if (results.rest.isEmpty) {
460 _showUsage(parser); 492 _showUsage(parser);
461 exitHandler(15); 493 exitHandler(15);
462 return null; // Only reachable in testing. 494 return null; // Only reachable in testing.
463 } 495 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 647
616 int _getNextFlagIndex(args, i) { 648 int _getNextFlagIndex(args, i) {
617 for (; i < args.length; ++i) { 649 for (; i < args.length; ++i) {
618 if (args[i].startsWith('--')) { 650 if (args[i].startsWith('--')) {
619 return i; 651 return i;
620 } 652 }
621 } 653 }
622 return i; 654 return i;
623 } 655 }
624 } 656 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698