OLD | NEW |
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' |
| 16 show applyAnalysisOptionFlags; |
15 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 17 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
16 import 'package:analyzer/src/generated/bazel.dart'; | 18 import 'package:analyzer/src/generated/bazel.dart'; |
17 import 'package:analyzer/src/generated/engine.dart'; | 19 import 'package:analyzer/src/generated/engine.dart'; |
18 import 'package:analyzer/src/generated/sdk.dart'; | 20 import 'package:analyzer/src/generated/sdk.dart'; |
19 import 'package:analyzer/src/generated/source.dart'; | 21 import 'package:analyzer/src/generated/source.dart'; |
20 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 22 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
21 import 'package:analyzer/src/summary/pub_summary.dart'; | 23 import 'package:analyzer/src/summary/pub_summary.dart'; |
22 import 'package:analyzer/src/summary/summary_sdk.dart'; | 24 import 'package:analyzer/src/summary/summary_sdk.dart'; |
23 import 'package:analyzer/src/task/options.dart'; | 25 import 'package:analyzer/src/task/options.dart'; |
| 26 import 'package:args/args.dart'; |
24 import 'package:package_config/packages.dart'; | 27 import 'package:package_config/packages.dart'; |
25 import 'package:package_config/packages_file.dart'; | 28 import 'package:package_config/packages_file.dart'; |
26 import 'package:package_config/src/packages_impl.dart'; | 29 import 'package:package_config/src/packages_impl.dart'; |
27 import 'package:path/src/context.dart'; | 30 import 'package:path/src/context.dart'; |
28 import 'package:yaml/yaml.dart'; | 31 import 'package:yaml/yaml.dart'; |
29 | 32 |
30 /** | 33 /** |
31 * A utility class used to build an analysis context for a given directory. | 34 * A utility class used to build an analysis context for a given directory. |
32 * | 35 * |
33 * The construction of analysis contexts is as follows: | 36 * The construction of analysis contexts is as follows: |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 SourceFactory sourceFactory = | 345 SourceFactory sourceFactory = |
343 new SourceFactory(resolvers, packages, resourceProvider); | 346 new SourceFactory(resolvers, packages, resourceProvider); |
344 try { | 347 try { |
345 Map<String, YamlNode> optionMap = | 348 Map<String, YamlNode> optionMap = |
346 new AnalysisOptionsProvider(sourceFactory) | 349 new AnalysisOptionsProvider(sourceFactory) |
347 .getOptionsFromFile(optionsFile); | 350 .getOptionsFromFile(optionsFile); |
348 applyToAnalysisOptions(options, optionMap); | 351 applyToAnalysisOptions(options, optionMap); |
349 } catch (_) { | 352 } catch (_) { |
350 // Ignore exceptions thrown while trying to load the options file. | 353 // Ignore exceptions thrown while trying to load the options file. |
351 } | 354 } |
| 355 if (builderOptions.argResults != null) { |
| 356 applyAnalysisOptionFlags(options, builderOptions.argResults); |
| 357 } |
352 } | 358 } |
353 return options; | 359 return options; |
354 } | 360 } |
355 | 361 |
356 /** | 362 /** |
357 * Return the analysis options file that should be used when analyzing code in | 363 * Return the analysis options file that should be used when analyzing code in |
358 * the directory with the given [path]. | 364 * the directory with the given [path]. |
359 */ | 365 */ |
360 File getOptionsFile(String path) { | 366 File getOptionsFile(String path) { |
361 String filePath = builderOptions.defaultAnalysisOptionsFilePath; | 367 String filePath = builderOptions.defaultAnalysisOptionsFilePath; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 480 } |
475 return null; | 481 return null; |
476 } | 482 } |
477 } | 483 } |
478 | 484 |
479 /** | 485 /** |
480 * Options used by a [ContextBuilder]. | 486 * Options used by a [ContextBuilder]. |
481 */ | 487 */ |
482 class ContextBuilderOptions { | 488 class ContextBuilderOptions { |
483 /** | 489 /** |
| 490 * The results of parsing the command line arguments as defined by |
| 491 * [defineAnalysisArguments] or `null` if none. |
| 492 */ |
| 493 ArgResults argResults; |
| 494 |
| 495 /** |
484 * The file path of the file containing the summary of the SDK that should be | 496 * The file path of the file containing the summary of the SDK that should be |
485 * used to "analyze" the SDK. This option should only be specified by | 497 * used to "analyze" the SDK. This option should only be specified by |
486 * command-line tools such as 'dartanalyzer' or 'ddc'. | 498 * command-line tools such as 'dartanalyzer' or 'ddc'. |
487 */ | 499 */ |
488 String dartSdkSummaryPath; | 500 String dartSdkSummaryPath; |
489 | 501 |
490 /** | 502 /** |
491 * The file path of the analysis options file that should be used in place of | 503 * The file path of the analysis options file that should be used in place of |
492 * any file in the root directory or a parent of the root directory, or `null` | 504 * any file in the root directory or a parent of the root directory, or `null` |
493 * if the normal lookup mechanism should be used. | 505 * if the normal lookup mechanism should be used. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 String _readEmbedderYaml(Folder libDir) { | 631 String _readEmbedderYaml(Folder libDir) { |
620 File file = libDir.getChild(EMBEDDER_FILE_NAME); | 632 File file = libDir.getChild(EMBEDDER_FILE_NAME); |
621 try { | 633 try { |
622 return file.readAsStringSync(); | 634 return file.readAsStringSync(); |
623 } on FileSystemException { | 635 } on FileSystemException { |
624 // File can't be read. | 636 // File can't be read. |
625 return null; | 637 return null; |
626 } | 638 } |
627 } | 639 } |
628 } | 640 } |
OLD | NEW |