mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:07:49 +00:00
update analyzer cli to support include directive in analysis options file
R=brianwilkerson@google.com Review URL: https://codereview.chromium.org/2541933002 .
This commit is contained in:
parent
666d4efce2
commit
aff6b796f3
|
@ -270,7 +270,8 @@ class BuildMode {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Set context options.
|
// Set context options.
|
||||||
Driver.setAnalysisContextOptions(resourceProvider, context, options,
|
Driver.setAnalysisContextOptions(
|
||||||
|
resourceProvider, context.sourceFactory, context, options,
|
||||||
(AnalysisOptionsImpl contextOptions) {
|
(AnalysisOptionsImpl contextOptions) {
|
||||||
if (options.buildSummaryOnlyDiet) {
|
if (options.buildSummaryOnlyDiet) {
|
||||||
contextOptions.analyzeFunctionBodies = false;
|
contextOptions.analyzeFunctionBodies = false;
|
||||||
|
|
|
@ -491,13 +491,6 @@ class Driver implements CommandLineStarter {
|
||||||
// Create a context.
|
// Create a context.
|
||||||
_context = AnalysisEngine.instance.createAnalysisContext();
|
_context = AnalysisEngine.instance.createAnalysisContext();
|
||||||
|
|
||||||
AnalyzeFunctionBodiesPredicate dietParsingPolicy =
|
|
||||||
_chooseDietParsingPolicy(options);
|
|
||||||
setAnalysisContextOptions(resourceProvider, _context, options,
|
|
||||||
(AnalysisOptionsImpl contextOptions) {
|
|
||||||
contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Find package info.
|
// Find package info.
|
||||||
_PackageInfo packageInfo = _findPackages(options);
|
_PackageInfo packageInfo = _findPackages(options);
|
||||||
|
|
||||||
|
@ -528,6 +521,14 @@ class Driver implements CommandLineStarter {
|
||||||
SourceFactory sourceFactory = _chooseUriResolutionPolicy(
|
SourceFactory sourceFactory = _chooseUriResolutionPolicy(
|
||||||
options, embedderMap, packageInfo, summaryDataStore);
|
options, embedderMap, packageInfo, summaryDataStore);
|
||||||
|
|
||||||
|
AnalyzeFunctionBodiesPredicate dietParsingPolicy =
|
||||||
|
_chooseDietParsingPolicy(options);
|
||||||
|
setAnalysisContextOptions(
|
||||||
|
resourceProvider, sourceFactory, _context, options,
|
||||||
|
(AnalysisOptionsImpl contextOptions) {
|
||||||
|
contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy;
|
||||||
|
});
|
||||||
|
|
||||||
_context.sourceFactory = sourceFactory;
|
_context.sourceFactory = sourceFactory;
|
||||||
_context.resultProvider =
|
_context.resultProvider =
|
||||||
new InputPackagesResultProvider(_context, summaryDataStore);
|
new InputPackagesResultProvider(_context, summaryDataStore);
|
||||||
|
@ -680,6 +681,7 @@ class Driver implements CommandLineStarter {
|
||||||
|
|
||||||
static void setAnalysisContextOptions(
|
static void setAnalysisContextOptions(
|
||||||
file_system.ResourceProvider resourceProvider,
|
file_system.ResourceProvider resourceProvider,
|
||||||
|
SourceFactory sourceFactory,
|
||||||
AnalysisContext context,
|
AnalysisContext context,
|
||||||
CommandLineOptions options,
|
CommandLineOptions options,
|
||||||
void configureContextOptions(AnalysisOptionsImpl contextOptions)) {
|
void configureContextOptions(AnalysisOptionsImpl contextOptions)) {
|
||||||
|
@ -704,7 +706,7 @@ class Driver implements CommandLineStarter {
|
||||||
context.analysisOptions = contextOptions;
|
context.analysisOptions = contextOptions;
|
||||||
|
|
||||||
// Process analysis options file (and notify all interested parties).
|
// Process analysis options file (and notify all interested parties).
|
||||||
_processAnalysisOptions(resourceProvider, context, options);
|
_processAnalysisOptions(resourceProvider, sourceFactory, context, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform a deep comparison of two string lists.
|
/// Perform a deep comparison of two string lists.
|
||||||
|
@ -761,14 +763,16 @@ class Driver implements CommandLineStarter {
|
||||||
|
|
||||||
static void _processAnalysisOptions(
|
static void _processAnalysisOptions(
|
||||||
file_system.ResourceProvider resourceProvider,
|
file_system.ResourceProvider resourceProvider,
|
||||||
|
SourceFactory sourceFactory,
|
||||||
AnalysisContext context,
|
AnalysisContext context,
|
||||||
CommandLineOptions options) {
|
CommandLineOptions options) {
|
||||||
file_system.File file = _getOptionsFile(resourceProvider, options);
|
file_system.File file = _getOptionsFile(resourceProvider, options);
|
||||||
List<OptionsProcessor> optionsProcessors =
|
List<OptionsProcessor> optionsProcessors =
|
||||||
AnalysisEngine.instance.optionsPlugin.optionsProcessors;
|
AnalysisEngine.instance.optionsPlugin.optionsProcessors;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
AnalysisOptionsProvider analysisOptionsProvider =
|
AnalysisOptionsProvider analysisOptionsProvider =
|
||||||
new AnalysisOptionsProvider();
|
new AnalysisOptionsProvider(sourceFactory);
|
||||||
Map<String, YamlNode> optionMap =
|
Map<String, YamlNode> optionMap =
|
||||||
analysisOptionsProvider.getOptionsFromFile(file);
|
analysisOptionsProvider.getOptionsFromFile(file);
|
||||||
optionsProcessors.forEach(
|
optionsProcessors.forEach(
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
include: other_options.yaml
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Generated by pub on 2016-11-30 13:02:00.280796.
|
||||||
|
foo:pkg/foo/lib/
|
||||||
|
options_include_directive_tests_project:lib/
|
|
@ -0,0 +1,16 @@
|
||||||
|
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
library analyzer_cli.test.data.options_include_directive_test_project.test_file;
|
||||||
|
|
||||||
|
|
||||||
|
int foo() {
|
||||||
|
|
||||||
|
int x = baz(); // Undefined function.
|
||||||
|
if (x == 0) {
|
||||||
|
print('x is zero');
|
||||||
|
} else ; // Empty else statement
|
||||||
|
|
||||||
|
// Missing return
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
include: package:foo/foo_package_options.yaml
|
|
@ -0,0 +1,13 @@
|
||||||
|
analyzer:
|
||||||
|
strong-mode: true
|
||||||
|
errors:
|
||||||
|
unused_local_variable: ignore
|
||||||
|
missing_return: error
|
||||||
|
undefined_function: warning
|
||||||
|
language:
|
||||||
|
enableSuperMixins: true
|
||||||
|
|
||||||
|
linter:
|
||||||
|
rules:
|
||||||
|
# see catalog here: http://dart-lang.github.io/linter/lints/
|
||||||
|
- avoid_empty_else
|
|
@ -306,6 +306,25 @@ linter:
|
||||||
|
|
||||||
createTests('old', AnalysisEngine.ANALYSIS_OPTIONS_FILE);
|
createTests('old', AnalysisEngine.ANALYSIS_OPTIONS_FILE);
|
||||||
createTests('new', AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
|
createTests('new', AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
|
||||||
|
|
||||||
|
test('include directive', () {
|
||||||
|
String testDir = path.join(
|
||||||
|
testDirectory, 'data', 'options_include_directive_tests_project');
|
||||||
|
drive(
|
||||||
|
path.join(testDir, 'lib', 'test_file.dart'),
|
||||||
|
args: [
|
||||||
|
'--fatal-warnings',
|
||||||
|
'--packages',
|
||||||
|
path.join(testDir, '_packages'),
|
||||||
|
],
|
||||||
|
options: path.join(testDir, '.analysis_options'),
|
||||||
|
);
|
||||||
|
expect(exitCode, 3);
|
||||||
|
expect(outSink.toString(),
|
||||||
|
contains('but doesn\'t end with a return statement.'));
|
||||||
|
expect(outSink.toString(), contains('isn\'t defined'));
|
||||||
|
expect(outSink.toString(), contains('Avoid empty else statements.'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
void createTests(String designator, String optionsFileName) {
|
void createTests(String designator, String optionsFileName) {
|
||||||
|
|
Loading…
Reference in a new issue