Issue 40572. Pass Packages to AnalysisDriver.
Just as SourceFactory is given to AnalysisDriver, so should be Packages. Understanding --packages and discovery in out of scope. Bug: https://github.com/dart-lang/sdk/issues/40572 Change-Id: Id120fba0f23a4423797fa9976c4cda5ed54dad53 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135188 Reviewed-by: Paul Berry <paulberry@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
e7ee11a95b
commit
abf7d1fc08
@@ -7,6 +7,7 @@ import 'dart:async';
|
||||
import 'package:analysis_server/src/services/search/search_engine.dart';
|
||||
import 'package:analysis_server/src/services/search/search_engine_internal.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/dart/analysis/byte_store.dart';
|
||||
import 'package:analyzer/src/dart/analysis/driver.dart';
|
||||
import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
@@ -489,7 +490,7 @@ class B extends A {}
|
||||
|
||||
return AnalysisDriver(scheduler, logger, resourceProvider, byteStore,
|
||||
contentOverlay, null, SourceFactory(resolvers), AnalysisOptionsImpl(),
|
||||
enableIndex: true);
|
||||
packages: Packages.empty, enableIndex: true);
|
||||
}
|
||||
|
||||
static void _assertContainsClass(Set<ClassElement> subtypes, String name) {
|
||||
|
||||
@@ -129,6 +129,7 @@ class ContextBuilder {
|
||||
contextRoot,
|
||||
sf,
|
||||
options,
|
||||
packages: createPackageMap(path),
|
||||
enableIndex: enableIndex,
|
||||
externalSummaries: summaryData);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import 'package:analyzer/error/listener.dart';
|
||||
import 'package:analyzer/exception/exception.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/context/context_root.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/dart/analysis/byte_store.dart';
|
||||
import 'package:analyzer/src/dart/analysis/feature_set_provider.dart';
|
||||
import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
@@ -131,6 +132,9 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
||||
/// The analysis options to analyze with.
|
||||
AnalysisOptionsImpl _analysisOptions;
|
||||
|
||||
/// The [Packages] object with packages and their language versions.
|
||||
Packages _packages;
|
||||
|
||||
/// The [SourceFactory] is used to resolve URIs to paths and restore URIs
|
||||
/// from file paths.
|
||||
SourceFactory _sourceFactory;
|
||||
@@ -286,11 +290,13 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
||||
this.contextRoot,
|
||||
SourceFactory sourceFactory,
|
||||
this._analysisOptions,
|
||||
{this.disableChangesAndCacheAllResults = false,
|
||||
{@required Packages packages,
|
||||
this.disableChangesAndCacheAllResults = false,
|
||||
this.enableIndex = false,
|
||||
SummaryDataStore externalSummaries,
|
||||
bool retainDataForTesting = false})
|
||||
: _logger = logger,
|
||||
_packages = packages ?? Packages.empty,
|
||||
_sourceFactory = sourceFactory,
|
||||
_externalSummaries = externalSummaries,
|
||||
testingData = retainDataForTesting ? TestingData() : null {
|
||||
@@ -488,11 +494,17 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
||||
///
|
||||
/// At least one of the optional parameters should be provided, but only those
|
||||
/// that represent state that has actually changed need be provided.
|
||||
void configure(
|
||||
{AnalysisOptions analysisOptions, SourceFactory sourceFactory}) {
|
||||
void configure({
|
||||
AnalysisOptions analysisOptions,
|
||||
Packages packages,
|
||||
SourceFactory sourceFactory,
|
||||
}) {
|
||||
if (analysisOptions != null) {
|
||||
_analysisOptions = analysisOptions;
|
||||
}
|
||||
if (packages != null) {
|
||||
_packages = packages;
|
||||
}
|
||||
if (sourceFactory != null) {
|
||||
_sourceFactory = sourceFactory;
|
||||
}
|
||||
@@ -1460,7 +1472,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
||||
|
||||
var featureSetProvider = FeatureSetProvider.build(
|
||||
resourceProvider: resourceProvider,
|
||||
contextRoot: contextRoot,
|
||||
packages: _packages,
|
||||
sourceFactory: _sourceFactory,
|
||||
defaultFeatureSet: _analysisOptions.contextFeatures,
|
||||
);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
import 'package:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/context/context_root.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
@@ -51,7 +50,7 @@ class FeatureSetProvider {
|
||||
|
||||
static FeatureSetProvider build({
|
||||
@required ResourceProvider resourceProvider,
|
||||
@required ContextRoot contextRoot,
|
||||
@required Packages packages,
|
||||
@required SourceFactory sourceFactory,
|
||||
@required FeatureSet defaultFeatureSet,
|
||||
}) {
|
||||
@@ -61,8 +60,6 @@ class FeatureSetProvider {
|
||||
defaultFeatureSet,
|
||||
);
|
||||
|
||||
var packages = _findPackages(resourceProvider, contextRoot);
|
||||
|
||||
return FeatureSetProvider._(
|
||||
sdkFeatureSet: sdkFeatureSet,
|
||||
packages: packages,
|
||||
@@ -97,16 +94,4 @@ class FeatureSetProvider {
|
||||
|
||||
return defaultFeatureSet;
|
||||
}
|
||||
|
||||
static Packages _findPackages(
|
||||
ResourceProvider resourceProvider,
|
||||
ContextRoot contextRoot,
|
||||
) {
|
||||
if (contextRoot == null) {
|
||||
return Packages(const {});
|
||||
}
|
||||
|
||||
var rootFolder = resourceProvider.getFolder(contextRoot.root);
|
||||
return findPackagesFrom(resourceProvider, rootFolder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,14 +175,16 @@ class LintDriver {
|
||||
PerformanceLog log = PerformanceLog(null);
|
||||
AnalysisDriverScheduler scheduler = AnalysisDriverScheduler(log);
|
||||
AnalysisDriver analysisDriver = AnalysisDriver(
|
||||
scheduler,
|
||||
log,
|
||||
resourceProvider,
|
||||
MemoryByteStore(),
|
||||
FileContentOverlay(),
|
||||
null,
|
||||
sourceFactory,
|
||||
_buildAnalyzerOptions(options));
|
||||
scheduler,
|
||||
log,
|
||||
resourceProvider,
|
||||
MemoryByteStore(),
|
||||
FileContentOverlay(),
|
||||
null,
|
||||
sourceFactory,
|
||||
_buildAnalyzerOptions(options),
|
||||
packages: Packages.empty,
|
||||
);
|
||||
analysisDriver.results.listen((_) {});
|
||||
analysisDriver.exceptions.listen((_) {});
|
||||
scheduler.start();
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/dart/element/type_provider.dart';
|
||||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/dart/analysis/byte_store.dart';
|
||||
import 'package:analyzer/src/dart/analysis/driver.dart';
|
||||
import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
@@ -600,7 +601,8 @@ class ResolverTestCase with ResourceProviderMixin {
|
||||
PerformanceLog log = PerformanceLog(_logBuffer);
|
||||
AnalysisDriverScheduler scheduler = AnalysisDriverScheduler(log);
|
||||
driver = AnalysisDriver(scheduler, log, resourceProvider, MemoryByteStore(),
|
||||
fileContentOverlay, null, sourceFactory, options);
|
||||
fileContentOverlay, null, sourceFactory, options,
|
||||
packages: Packages.empty);
|
||||
scheduler.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:analyzer/dart/analysis/results.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/visitor.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/dart/analysis/byte_store.dart';
|
||||
import 'package:analyzer/src/dart/analysis/driver.dart';
|
||||
import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
@@ -99,6 +100,7 @@ class BaseAnalysisDriverTest with ResourceProviderMixin {
|
||||
ResourceUriResolver(resourceProvider)
|
||||
]),
|
||||
createAnalysisOptions(),
|
||||
packages: Packages.empty,
|
||||
disableChangesAndCacheAllResults: disableChangesAndCacheAllResults,
|
||||
enableIndex: true,
|
||||
externalSummaries: externalSummaries);
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/dart/analysis/byte_store.dart';
|
||||
import 'package:analyzer/src/dart/analysis/driver.dart';
|
||||
import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
@@ -78,7 +79,8 @@ class AnalysisDriverSchedulerTest with ResourceProviderMixin {
|
||||
SourceFactory(
|
||||
[DartUriResolver(sdk), ResourceUriResolver(resourceProvider)],
|
||||
),
|
||||
AnalysisOptionsImpl());
|
||||
AnalysisOptionsImpl(),
|
||||
packages: Packages.empty);
|
||||
driver.results.forEach(allResults.add);
|
||||
return driver;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
import 'package:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/context/context_root.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/context/source.dart';
|
||||
import 'package:analyzer/src/dart/analysis/feature_set_provider.dart';
|
||||
@@ -128,11 +127,7 @@ test:lib/
|
||||
void _buildProvider(List<String> enabledExperiments) {
|
||||
provider = FeatureSetProvider.build(
|
||||
resourceProvider: resourceProvider,
|
||||
contextRoot: ContextRoot(
|
||||
convertPath('/test'),
|
||||
[],
|
||||
pathContext: resourceProvider.pathContext,
|
||||
),
|
||||
packages: findPackagesFrom(resourceProvider, getFolder('/test')),
|
||||
sourceFactory: sourceFactory,
|
||||
defaultFeatureSet: FeatureSet.fromEnableFlags(enabledExperiments),
|
||||
);
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'dart:typed_data';
|
||||
import 'package:analyzer/dart/analysis/declared_variables.dart';
|
||||
import 'package:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/dart/analysis/byte_store.dart';
|
||||
import 'package:analyzer/src/dart/analysis/feature_set_provider.dart';
|
||||
import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
@@ -61,7 +62,7 @@ class FileSystemStateTest with ResourceProviderMixin {
|
||||
AnalysisOptions analysisOptions = AnalysisOptionsImpl();
|
||||
var featureSetProvider = FeatureSetProvider.build(
|
||||
resourceProvider: resourceProvider,
|
||||
contextRoot: null,
|
||||
packages: Packages.empty,
|
||||
sourceFactory: sourceFactory,
|
||||
defaultFeatureSet: FeatureSet.fromEnableFlags([]),
|
||||
);
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'dart:async';
|
||||
import 'package:analyzer/dart/analysis/results.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/context/context_root.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/dart/analysis/byte_store.dart';
|
||||
import 'package:analyzer/src/dart/analysis/driver.dart';
|
||||
import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
@@ -75,7 +76,8 @@ class DriverResolutionTest with ResourceProviderMixin, ResolutionTest {
|
||||
PackageMapUriResolver(resourceProvider, packageMap),
|
||||
ResourceUriResolver(resourceProvider)
|
||||
]),
|
||||
analysisOptions);
|
||||
analysisOptions,
|
||||
packages: Packages.empty);
|
||||
|
||||
scheduler.start();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// 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.
|
||||
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
@@ -42,7 +43,12 @@ class DefaultNonNullableTest extends DriverResolutionTest {
|
||||
]
|
||||
}
|
||||
''');
|
||||
driver.configure();
|
||||
driver.configure(
|
||||
packages: findPackagesFrom(
|
||||
resourceProvider,
|
||||
getFolder('/test'),
|
||||
),
|
||||
);
|
||||
|
||||
newFile('/aaa/lib/a.dart', content: r'''
|
||||
int a = 0;
|
||||
@@ -80,7 +86,12 @@ var z = PI;
|
||||
]
|
||||
}
|
||||
''');
|
||||
driver.configure();
|
||||
driver.configure(
|
||||
packages: findPackagesFrom(
|
||||
resourceProvider,
|
||||
getFolder('/test'),
|
||||
),
|
||||
);
|
||||
|
||||
newFile('/aaa/lib/a.dart', content: r'''
|
||||
int a = 0;
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/source/error_processor.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/dart/analysis/byte_store.dart';
|
||||
import 'package:analyzer/src/dart/analysis/driver.dart';
|
||||
import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
@@ -303,7 +304,8 @@ class AbstractStrongTest with ResourceProviderMixin {
|
||||
fileContentOverlay,
|
||||
null,
|
||||
sourceFactory,
|
||||
analysisOptions);
|
||||
analysisOptions,
|
||||
packages: Packages.empty);
|
||||
scheduler.start();
|
||||
|
||||
mainUnit = (await _driver.getResult(mainFile.path)).unit;
|
||||
|
||||
@@ -16,6 +16,7 @@ import 'package:analyzer/diagnostic/diagnostic.dart';
|
||||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/file_system/memory_file_system.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/dart/analysis/byte_store.dart';
|
||||
import 'package:analyzer/src/dart/analysis/driver.dart';
|
||||
import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
@@ -146,6 +147,7 @@ Future<TestResult<T>> runTestForConfig<T>(
|
||||
ResourceUriResolver(resourceProvider)
|
||||
]),
|
||||
analysisOptions,
|
||||
packages: Packages.empty,
|
||||
retainDataForTesting: true);
|
||||
scheduler.start();
|
||||
var result = await driver
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/context/context.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/dart/analysis/byte_store.dart';
|
||||
import 'package:analyzer/src/dart/analysis/cache.dart';
|
||||
import 'package:analyzer/src/dart/analysis/driver.dart';
|
||||
@@ -422,6 +423,8 @@ class BuildMode with HasContextMixin {
|
||||
summaryDataStore.addBundle(null, sdkBundle);
|
||||
});
|
||||
|
||||
var packages = _findPackages(rootPath);
|
||||
|
||||
sourceFactory = SourceFactory(<UriResolver>[
|
||||
DartUriResolver(sdk),
|
||||
TrackingInSummaryUriResolver(
|
||||
@@ -435,15 +438,17 @@ class BuildMode with HasContextMixin {
|
||||
|
||||
AnalysisDriverScheduler scheduler = AnalysisDriverScheduler(logger);
|
||||
analysisDriver = AnalysisDriver(
|
||||
scheduler,
|
||||
logger,
|
||||
resourceProvider,
|
||||
MemoryByteStore(),
|
||||
FileContentOverlay(),
|
||||
null,
|
||||
sourceFactory,
|
||||
analysisOptions,
|
||||
externalSummaries: summaryDataStore);
|
||||
scheduler,
|
||||
logger,
|
||||
resourceProvider,
|
||||
MemoryByteStore(),
|
||||
FileContentOverlay(),
|
||||
null,
|
||||
sourceFactory,
|
||||
analysisOptions,
|
||||
externalSummaries: summaryDataStore,
|
||||
packages: packages,
|
||||
);
|
||||
|
||||
declaredVariables = DeclaredVariables.fromMap(options.definedVariables);
|
||||
analysisDriver.declaredVariables = declaredVariables;
|
||||
@@ -494,6 +499,14 @@ class BuildMode with HasContextMixin {
|
||||
return uriToFileMap;
|
||||
}
|
||||
|
||||
Packages _findPackages(String path) {
|
||||
if (path != null) {
|
||||
return findPackagesFrom(resourceProvider, resourceProvider.getFile(path));
|
||||
} else {
|
||||
return Packages.empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure that the parsed unit for [absoluteUri] is available.
|
||||
///
|
||||
/// If the unit is in the input [summaryDataStore], do nothing.
|
||||
|
||||
@@ -581,7 +581,8 @@ class Driver with HasContextMixin implements CommandLineStarter {
|
||||
FileContentOverlay(),
|
||||
ContextRoot(source, [], pathContext: resourceProvider.pathContext),
|
||||
sourceFactory,
|
||||
analysisOptions);
|
||||
analysisOptions,
|
||||
packages: packageInfo.packages);
|
||||
analysisDriver.results.listen((_) {});
|
||||
analysisDriver.exceptions.listen((_) {});
|
||||
scheduler.start();
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'dart:collection';
|
||||
import 'package:analyzer/dart/analysis/results.dart';
|
||||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/context/packages.dart';
|
||||
import 'package:analyzer/src/dart/analysis/driver.dart';
|
||||
import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart'
|
||||
@@ -34,7 +35,8 @@ class MockAnalysisDriver extends AnalysisDriver {
|
||||
FileContentOverlay(),
|
||||
null,
|
||||
SourceFactory([]),
|
||||
AnalysisOptionsImpl());
|
||||
AnalysisOptionsImpl(),
|
||||
packages: Packages.empty);
|
||||
|
||||
@override
|
||||
bool get hasFilesToAnalyze => false;
|
||||
|
||||
Reference in New Issue
Block a user