-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "options map support scaffolding in driver"
This reverts commit 717ce7a. Reason for revert: breaking Google3 Original change's description: > options map support scaffolding in driver > > Konstantin and I chatted a bit about this so at least some of it shouldn't be too surprising to him but please do feel free to grab me to chat. > > That said a few pointers would be handy. Notably, this change: > > * introduces a new `SharedOptionsOptionsMap` for use in SDK drivers (and preserve current semantics) > * this is currently public but will be private once driver is more evolved to accommodate multiple options files > * removes the shared `_analysisOptions` from the analysis driver with a baby step to using the one shared in SharedOptionsOptionsMap > * removes context_builder and collection v2 experiments (and tests) > * I'll harvest some more functionality from these in future changes but for now they're distracting and hard to maintain > > This work is all to setup moving analysis options awareness into file state objects which will allow us to remove `sdkVersionConstraint` info from options (finally) and a host of other good stuff (see #54124). > > > > Change-Id: Ic4278184016d1018b4b5b1c6ac5ba9e2546927a5 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/344860 > Reviewed-by: Brian Wilkerson <[email protected]> > Reviewed-by: Konstantin Shcheglov <[email protected]> > Commit-Queue: Phil Quitslund <[email protected]> Change-Id: Ia988c5c9cd328d0adce3d8e6ff019e389819a957 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/344960 Auto-Submit: Phil Quitslund <[email protected]> Bot-Commit: Rubber Stamper <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
- Loading branch information
Showing
12 changed files
with
996 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
pkg/analyzer/lib/src/dart/analysis/analysis_context_collection2.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
import 'package:analyzer/dart/analysis/analysis_context_collection.dart'; | ||
import 'package:analyzer/dart/analysis/context_root.dart'; | ||
import 'package:analyzer/dart/analysis/declared_variables.dart'; | ||
import 'package:analyzer/file_system/file_system.dart'; | ||
import 'package:analyzer/file_system/physical_file_system.dart'; | ||
import 'package:analyzer/src/dart/analysis/byte_store.dart'; | ||
import 'package:analyzer/src/dart/analysis/context_builder2.dart'; | ||
import 'package:analyzer/src/dart/analysis/context_locator2.dart'; | ||
import 'package:analyzer/src/dart/analysis/driver.dart'; | ||
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart'; | ||
import 'package:analyzer/src/dart/analysis/file_content_cache.dart'; | ||
import 'package:analyzer/src/dart/analysis/info_declaration_store.dart'; | ||
import 'package:analyzer/src/dart/analysis/performance_logger.dart'; | ||
import 'package:analyzer/src/dart/analysis/unlinked_unit_store.dart'; | ||
import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl; | ||
import 'package:analyzer/src/generated/sdk.dart'; | ||
import 'package:analyzer/src/summary2/kernel_compilation_service.dart'; | ||
import 'package:analyzer/src/summary2/macro.dart'; | ||
import 'package:analyzer/src/util/sdk.dart'; | ||
|
||
/// An implementation of [AnalysisContextCollection]. | ||
class AnalysisContextCollectionImpl2 implements AnalysisContextCollection { | ||
/// The resource provider used to access the file system. | ||
final ResourceProvider resourceProvider; | ||
|
||
/// The support for executing macros. | ||
late final MacroSupport macroSupport; | ||
|
||
/// The shared container into which drivers record files ownership. | ||
final OwnedFiles ownedFiles = OwnedFiles(); | ||
|
||
/// The list of analysis contexts. | ||
@override | ||
final List<DriverBasedAnalysisContext> contexts = []; | ||
|
||
/// Initialize a newly created analysis context manager. | ||
AnalysisContextCollectionImpl2({ | ||
ByteStore? byteStore, | ||
Map<String, String>? declaredVariables, | ||
bool drainStreams = true, | ||
bool enableIndex = false, | ||
required List<String> includedPaths, | ||
List<String>? excludedPaths, | ||
List<String>? librarySummaryPaths, | ||
String? optionsFile, | ||
String? packagesFile, | ||
PerformanceLog? performanceLog, | ||
ResourceProvider? resourceProvider, | ||
bool retainDataForTesting = false, | ||
String? sdkPath, | ||
String? sdkSummaryPath, | ||
AnalysisDriverScheduler? scheduler, | ||
FileContentCache? fileContentCache, | ||
UnlinkedUnitStore? unlinkedUnitStore, | ||
InfoDeclarationStore? infoDeclarationStore, | ||
@Deprecated('Use updateAnalysisOptions2, which must be a function that ' | ||
'accepts a second parameter') | ||
void Function(AnalysisOptionsImpl)? updateAnalysisOptions, | ||
void Function({ | ||
required AnalysisOptionsImpl analysisOptions, | ||
required ContextRoot contextRoot, | ||
required DartSdk sdk, | ||
})? updateAnalysisOptions2, | ||
MacroSupport? macroSupport, | ||
}) : resourceProvider = | ||
resourceProvider ?? PhysicalResourceProvider.INSTANCE { | ||
sdkPath ??= getSdkPath(); | ||
|
||
_throwIfAnyNotAbsoluteNormalizedPath(includedPaths); | ||
_throwIfNotAbsoluteNormalizedPath(sdkPath); | ||
|
||
if (updateAnalysisOptions != null && updateAnalysisOptions2 != null) { | ||
throw ArgumentError( | ||
'Either updateAnalysisOptions or updateAnalysisOptions2 must be ' | ||
'given, but not both.'); | ||
} | ||
|
||
this.macroSupport = macroSupport ??= KernelMacroSupport(); | ||
|
||
var contextLocator = ContextLocatorImpl2( | ||
resourceProvider: this.resourceProvider, | ||
); | ||
var roots = contextLocator.locateRoots( | ||
includedPaths: includedPaths, | ||
excludedPaths: excludedPaths, | ||
optionsFile: optionsFile, | ||
packagesFile: packagesFile, | ||
); | ||
for (var root in roots) { | ||
var contextBuilder = ContextBuilderImpl2( | ||
resourceProvider: this.resourceProvider, | ||
); | ||
var context = contextBuilder.createContext( | ||
byteStore: byteStore, | ||
contextRoot: root, | ||
declaredVariables: DeclaredVariables.fromMap(declaredVariables ?? {}), | ||
drainStreams: drainStreams, | ||
enableIndex: enableIndex, | ||
librarySummaryPaths: librarySummaryPaths, | ||
performanceLog: performanceLog, | ||
retainDataForTesting: retainDataForTesting, | ||
sdkPath: sdkPath, | ||
sdkSummaryPath: sdkSummaryPath, | ||
scheduler: scheduler, | ||
// ignore: deprecated_member_use_from_same_package | ||
updateAnalysisOptions: updateAnalysisOptions, | ||
updateAnalysisOptions2: updateAnalysisOptions2, | ||
fileContentCache: fileContentCache, | ||
unlinkedUnitStore: unlinkedUnitStore ?? UnlinkedUnitStoreImpl(), | ||
infoDeclarationStore: infoDeclarationStore, | ||
macroSupport: macroSupport, | ||
ownedFiles: ownedFiles, | ||
); | ||
contexts.add(context); | ||
} | ||
} | ||
|
||
/// Return `true` if the read state of configuration files is consistent | ||
/// with their current state on the file system. We use this as a work | ||
/// around an issue with watching for file system changes. | ||
bool get areWorkspacesConsistent { | ||
for (var analysisContext in contexts) { | ||
var contextRoot = analysisContext.contextRoot; | ||
var workspace = contextRoot.workspace; | ||
if (!workspace.isConsistentWithFileSystem) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@override | ||
DriverBasedAnalysisContext contextFor(String path) { | ||
_throwIfNotAbsoluteNormalizedPath(path); | ||
|
||
for (var context in contexts) { | ||
if (context.contextRoot.isAnalyzed(path)) { | ||
return context; | ||
} | ||
} | ||
|
||
throw StateError('Unable to find the context to $path'); | ||
} | ||
|
||
Future<void> dispose({ | ||
bool forTesting = false, | ||
}) async { | ||
for (final analysisContext in contexts) { | ||
await analysisContext.driver.dispose2(); | ||
} | ||
await macroSupport.dispose(); | ||
// If there are other collections, they will have to start it again. | ||
if (!forTesting) { | ||
await KernelCompilationService.dispose(); | ||
} | ||
} | ||
|
||
/// Check every element with [_throwIfNotAbsoluteNormalizedPath]. | ||
void _throwIfAnyNotAbsoluteNormalizedPath(List<String> paths) { | ||
for (var path in paths) { | ||
_throwIfNotAbsoluteNormalizedPath(path); | ||
} | ||
} | ||
|
||
/// The driver supports only absolute normalized paths, this method is used | ||
/// to validate any input paths to prevent errors later. | ||
void _throwIfNotAbsoluteNormalizedPath(String path) { | ||
var pathContext = resourceProvider.pathContext; | ||
if (!pathContext.isAbsolute(path) || pathContext.normalize(path) != path) { | ||
throw ArgumentError( | ||
'Only absolute normalized paths are supported: $path'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.