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

Side by Side Diff: pkg/analyzer/lib/src/context/builder.dart

Issue 2726783002: echo analysis options information if dartanalyzer --verbose is specified (Closed)
Patch Set: merge Created 3 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
« no previous file with comments | « pkg/analyzer/lib/src/command_line/arguments.dart ('k') | pkg/analyzer_cli/lib/src/driver.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 library analyzer.src.context.context_builder; 5 library analyzer.src.context.context_builder;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:core'; 8 import 'dart:core';
9 9
10 import 'package:analyzer/context/declared_variables.dart'; 10 import 'package:analyzer/context/declared_variables.dart';
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 FolderBasedDartSdk sdk = new FolderBasedDartSdk(resourceProvider, 359 FolderBasedDartSdk sdk = new FolderBasedDartSdk(resourceProvider,
360 resourceProvider.getFolder(sdkPath), analysisOptions.strongMode); 360 resourceProvider.getFolder(sdkPath), analysisOptions.strongMode);
361 sdk.analysisOptions = analysisOptions; 361 sdk.analysisOptions = analysisOptions;
362 sdk.useSummary = sdkManager.canUseSummaries; 362 sdk.useSummary = sdkManager.canUseSummaries;
363 return sdk; 363 return sdk;
364 }); 364 });
365 } 365 }
366 366
367 /** 367 /**
368 * Return the analysis options that should be used to analyze code in the 368 * Return the analysis options that should be used to analyze code in the
369 * directory with the given [path]. 369 * directory with the given [path]. Use [verbosePrint] to echo verbose
370 * information about the analysis options selection process.
370 */ 371 */
371 AnalysisOptions getAnalysisOptions(String path) { 372 AnalysisOptions getAnalysisOptions(String path,
373 {void verbosePrint(String text)}) {
374 void verbose(String text) {
375 if (verbosePrint != null) {
376 verbosePrint(text);
377 }
378 }
379
372 // TODO(danrubel) restructure so that we don't create a workspace 380 // TODO(danrubel) restructure so that we don't create a workspace
373 // both here and in createSourceFactory 381 // both here and in createSourceFactory
374 Workspace workspace = createWorkspace(path); 382 Workspace workspace = createWorkspace(path);
375 SourceFactory sourceFactory = workspace.createSourceFactory(null); 383 SourceFactory sourceFactory = workspace.createSourceFactory(null);
376 AnalysisOptionsProvider optionsProvider = 384 AnalysisOptionsProvider optionsProvider =
377 new AnalysisOptionsProvider(sourceFactory); 385 new AnalysisOptionsProvider(sourceFactory);
378 386
379 AnalysisOptionsImpl options = createDefaultOptions(); 387 AnalysisOptionsImpl options = createDefaultOptions();
380 File optionsFile = getOptionsFile(path); 388 File optionsFile = getOptionsFile(path);
381 Map<String, YamlNode> optionMap; 389 Map<String, YamlNode> optionMap;
382 390
383 if (optionsFile != null) { 391 if (optionsFile != null) {
384 try { 392 try {
385 optionMap = optionsProvider.getOptionsFromFile(optionsFile); 393 optionMap = optionsProvider.getOptionsFromFile(optionsFile);
386 } catch (_) { 394 verbose('Loaded analysis options from ${optionsFile.path}');
395 } catch (e) {
387 // Ignore exceptions thrown while trying to load the options file. 396 // Ignore exceptions thrown while trying to load the options file.
397 verbose('Exception: $e\n when loading ${optionsFile.path}');
388 } 398 }
389 } else { 399 } else {
390 // Search for the default analysis options 400 // Search for the default analysis options
391 Source source; 401 Source source;
392 // TODO(danrubel) determine if bazel or gn project depends upon flutter 402 // TODO(danrubel) determine if bazel or gn project depends upon flutter
393 if (workspace.hasFlutterDependency) { 403 if (workspace.hasFlutterDependency) {
394 source = 404 source =
395 sourceFactory.forUri('package:flutter/analysis_options_user.yaml'); 405 sourceFactory.forUri('package:flutter/analysis_options_user.yaml');
396 } 406 }
397 if (source == null || !source.exists()) { 407 if (source == null || !source.exists()) {
398 source = 408 source =
399 sourceFactory.forUri('package:dart.analysis_options/default.yaml'); 409 sourceFactory.forUri('package:dart.analysis_options/default.yaml');
400 } 410 }
401 if (source.exists()) { 411 if (source.exists()) {
402 try { 412 try {
403 optionMap = optionsProvider.getOptionsFromSource(source); 413 optionMap = optionsProvider.getOptionsFromSource(source);
404 } catch (_) { 414 verbose('Loaded analysis options from ${source.fullName}');
415 } catch (e) {
405 // Ignore exceptions thrown while trying to load the options file. 416 // Ignore exceptions thrown while trying to load the options file.
417 verbose('Exception: $e\n when loading ${source.fullName}');
406 } 418 }
407 } 419 }
408 } 420 }
409 421
410 if (optionMap != null) { 422 if (optionMap != null) {
411 applyToAnalysisOptions(options, optionMap); 423 applyToAnalysisOptions(options, optionMap);
412 if (builderOptions.argResults != null) { 424 if (builderOptions.argResults != null) {
413 applyAnalysisOptionFlags(options, builderOptions.argResults); 425 applyAnalysisOptionFlags(options, builderOptions.argResults,
426 verbosePrint: verbosePrint);
414 // If lints turned on but none specified, then enable default lints 427 // If lints turned on but none specified, then enable default lints
415 if (options.lint && options.lintRules.isEmpty) { 428 if (options.lint && options.lintRules.isEmpty) {
416 options.lintRules = Registry.ruleRegistry.defaultRules; 429 options.lintRules = Registry.ruleRegistry.defaultRules;
430 verbose('Using default lint rules');
417 } 431 }
418 } 432 }
433 } else {
434 verbose('Using default analysis options');
419 } 435 }
420 return options; 436 return options;
421 } 437 }
422 438
423 /** 439 /**
424 * Return the analysis options file that should be used when analyzing code in 440 * Return the analysis options file that should be used when analyzing code in
425 * the directory with the given [path]. 441 * the directory with the given [path].
426 */ 442 */
427 File getOptionsFile(String path) { 443 File getOptionsFile(String path) {
428 String filePath = builderOptions.defaultAnalysisOptionsFilePath; 444 String filePath = builderOptions.defaultAnalysisOptionsFilePath;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 789
774 // Ensure that the path is absolute and normalized. 790 // Ensure that the path is absolute and normalized.
775 if (!context.isAbsolute(path)) { 791 if (!context.isAbsolute(path)) {
776 throw new ArgumentError('not absolute: $path'); 792 throw new ArgumentError('not absolute: $path');
777 } 793 }
778 path = context.normalize(path); 794 path = context.normalize(path);
779 795
780 return new _BasicWorkspace._(provider, path, builder); 796 return new _BasicWorkspace._(provider, path, builder);
781 } 797 }
782 } 798 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/command_line/arguments.dart ('k') | pkg/analyzer_cli/lib/src/driver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698