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

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

Issue 2745653012: enable/disable default package contributed analysis options (Closed)
Patch Set: 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
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';
11 import 'package:analyzer/file_system/file_system.dart'; 11 import 'package:analyzer/file_system/file_system.dart';
12 import 'package:analyzer/plugin/resolver_provider.dart'; 12 import 'package:analyzer/plugin/resolver_provider.dart';
13 import 'package:analyzer/source/analysis_options_provider.dart'; 13 import 'package:analyzer/source/analysis_options_provider.dart';
14 import 'package:analyzer/source/package_map_resolver.dart'; 14 import 'package:analyzer/source/package_map_resolver.dart';
15 import 'package:analyzer/src/command_line/arguments.dart' 15 import 'package:analyzer/src/command_line/arguments.dart'
16 show applyAnalysisOptionFlags; 16 show
17 applyAnalysisOptionFlags,
18 bazelAnalysisOptionsPath,
19 flutterAnalysisOptionsPath;
17 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 20 import 'package:analyzer/src/dart/analysis/byte_store.dart';
18 import 'package:analyzer/src/dart/analysis/driver.dart' 21 import 'package:analyzer/src/dart/analysis/driver.dart'
19 show AnalysisDriver, AnalysisDriverScheduler, PerformanceLog; 22 show AnalysisDriver, AnalysisDriverScheduler, PerformanceLog;
20 import 'package:analyzer/src/dart/analysis/file_state.dart'; 23 import 'package:analyzer/src/dart/analysis/file_state.dart';
21 import 'package:analyzer/src/dart/sdk/sdk.dart'; 24 import 'package:analyzer/src/dart/sdk/sdk.dart';
22 import 'package:analyzer/src/generated/bazel.dart'; 25 import 'package:analyzer/src/generated/bazel.dart';
23 import 'package:analyzer/src/generated/engine.dart'; 26 import 'package:analyzer/src/generated/engine.dart';
24 import 'package:analyzer/src/generated/gn.dart'; 27 import 'package:analyzer/src/generated/gn.dart';
25 import 'package:analyzer/src/generated/sdk.dart'; 28 import 'package:analyzer/src/generated/sdk.dart';
26 import 'package:analyzer/src/generated/source.dart'; 29 import 'package:analyzer/src/generated/source.dart';
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 if (optionsFile != null) { 394 if (optionsFile != null) {
392 try { 395 try {
393 optionMap = optionsProvider.getOptionsFromFile(optionsFile); 396 optionMap = optionsProvider.getOptionsFromFile(optionsFile);
394 verbose('Loaded analysis options from ${optionsFile.path}'); 397 verbose('Loaded analysis options from ${optionsFile.path}');
395 } catch (e) { 398 } catch (e) {
396 // Ignore exceptions thrown while trying to load the options file. 399 // Ignore exceptions thrown while trying to load the options file.
397 verbose('Exception: $e\n when loading ${optionsFile.path}'); 400 verbose('Exception: $e\n when loading ${optionsFile.path}');
398 } 401 }
399 } else { 402 } else {
400 // Search for the default analysis options 403 // Search for the default analysis options
404 // unless explicitly directed not to do so.
401 Source source; 405 Source source;
402 // TODO(danrubel) determine if bazel or gn project depends upon flutter 406 if (builderOptions.packageDefaultAnalysisOptions) {
403 if (workspace.hasFlutterDependency) { 407 // TODO(danrubel) determine if bazel or gn project depends upon flutter
404 source = 408 if (workspace.hasFlutterDependency) {
405 sourceFactory.forUri('package:flutter/analysis_options_user.yaml'); 409 source = sourceFactory.forUri(flutterAnalysisOptionsPath);
406 } 410 }
407 if (source == null || !source.exists()) { 411 if (source == null || !source.exists()) {
408 source = 412 source = sourceFactory.forUri(bazelAnalysisOptionsPath);
409 sourceFactory.forUri('package:dart.analysis_options/default.yaml'); 413 }
410 } 414 if (source.exists()) {
411 if (source.exists()) { 415 try {
412 try { 416 optionMap = optionsProvider.getOptionsFromSource(source);
413 optionMap = optionsProvider.getOptionsFromSource(source); 417 verbose('Loaded analysis options from ${source.fullName}');
414 verbose('Loaded analysis options from ${source.fullName}'); 418 } catch (e) {
415 } catch (e) { 419 // Ignore exceptions thrown while trying to load the options file.
416 // Ignore exceptions thrown while trying to load the options file. 420 verbose('Exception: $e\n when loading ${source.fullName}');
417 verbose('Exception: $e\n when loading ${source.fullName}'); 421 }
418 } 422 }
419 } 423 }
420 } 424 }
421 425
422 if (optionMap != null) { 426 if (optionMap != null) {
423 applyToAnalysisOptions(options, optionMap); 427 applyToAnalysisOptions(options, optionMap);
424 if (builderOptions.argResults != null) { 428 if (builderOptions.argResults != null) {
425 applyAnalysisOptionFlags(options, builderOptions.argResults, 429 applyAnalysisOptionFlags(options, builderOptions.argResults,
426 verbosePrint: verbosePrint); 430 verbosePrint: verbosePrint);
427 // If lints turned on but none specified, then enable default lints 431 // If lints turned on but none specified, then enable default lints
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 String defaultPackageFilePath; 625 String defaultPackageFilePath;
622 626
623 /** 627 /**
624 * The file path of the packages directory that should be used in place of any 628 * The file path of the packages directory that should be used in place of any
625 * file found using the normal (Package Specification DEP) lookup mechanism, 629 * file found using the normal (Package Specification DEP) lookup mechanism,
626 * or `null` if the normal lookup mechanism should be used. 630 * or `null` if the normal lookup mechanism should be used.
627 */ 631 */
628 String defaultPackagesDirectoryPath; 632 String defaultPackagesDirectoryPath;
629 633
630 /** 634 /**
635 * Allow Flutter and bazel default analysis options to be used.
636 */
637 bool packageDefaultAnalysisOptions = true;
638
639 /**
631 * Initialize a newly created set of options 640 * Initialize a newly created set of options
632 */ 641 */
633 ContextBuilderOptions(); 642 ContextBuilderOptions();
634 } 643 }
635 644
636 /** 645 /**
637 * Given a package map, check in each package's lib directory for the existence 646 * Given a package map, check in each package's lib directory for the existence
638 * of an `_embedder.yaml` file. If the file contains a top level YamlMap, it 647 * of an `_embedder.yaml` file. If the file contains a top level YamlMap, it
639 * will be added to the [embedderYamls] map. 648 * will be added to the [embedderYamls] map.
640 */ 649 */
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 798
790 // Ensure that the path is absolute and normalized. 799 // Ensure that the path is absolute and normalized.
791 if (!context.isAbsolute(path)) { 800 if (!context.isAbsolute(path)) {
792 throw new ArgumentError('not absolute: $path'); 801 throw new ArgumentError('not absolute: $path');
793 } 802 }
794 path = context.normalize(path); 803 path = context.normalize(path);
795 804
796 return new _BasicWorkspace._(provider, path, builder); 805 return new _BasicWorkspace._(provider, path, builder);
797 } 806 }
798 } 807 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/command_line/arguments.dart ('k') | pkg/analyzer/test/src/command_line/arguments_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698