Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 64f7ed6

Browse files
author
Dart CI
committed
Version 2.15.0-244.0.dev
Merge commit 'd9edb9bc297469bb87d4dcb8196c3a1c49aeb824' into 'dev'
2 parents 2d22eeb + d9edb9b commit 64f7ed6

File tree

14 files changed

+233
-255
lines changed

14 files changed

+233
-255
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import 'dart:typed_data';
6+
7+
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
8+
import 'package:analyzer/dart/analysis/session.dart';
9+
import 'package:analyzer/file_system/file_system.dart';
10+
import 'package:analyzer/src/context/packages.dart';
11+
import 'package:analyzer/src/dart/analysis/byte_store.dart';
12+
import 'package:analyzer/src/dart/analysis/driver.dart';
13+
import 'package:analyzer/src/dart/analysis/performance_logger.dart';
14+
import 'package:analyzer/src/generated/engine.dart';
15+
import 'package:analyzer/src/generated/source.dart';
16+
import 'package:analyzer/src/summary/package_bundle_reader.dart';
17+
import 'package:analyzer/src/summary/summary_sdk.dart';
18+
import 'package:analyzer/src/summary2/package_bundle_format.dart';
19+
20+
export 'package:analyzer/src/context/packages.dart' show Packages, Package;
21+
export 'package:analyzer/src/dart/analysis/experiments.dart'
22+
show ExperimentStatus;
23+
export 'package:analyzer/src/generated/engine.dart'
24+
show AnalysisOptions, AnalysisOptionsImpl;
25+
export 'package:analyzer/src/generated/source.dart' show Source, UriResolver;
26+
27+
/// A somewhat low level API to create [AnalysisSession].
28+
///
29+
/// Ideally we want clients to use [AnalysisContextCollection], which
30+
/// encapsulates any internals and is driven by `package_config.json` and
31+
/// `analysis_options.yaml` files. But so far it looks that `build_resolvers`
32+
/// wants to provide [UriResolver], and push [Packages] created by other means
33+
/// than parsing `package_config.json`.
34+
AnalysisDriverForPackageBuild createAnalysisDriver({
35+
required ResourceProvider resourceProvider,
36+
required Uint8List sdkSummaryBytes,
37+
required AnalysisOptions analysisOptions,
38+
required List<UriResolver> uriResolvers,
39+
required Packages packages,
40+
}) {
41+
var sdkBundle = PackageBundleReader(sdkSummaryBytes);
42+
var sdk = SummaryBasedDartSdk.forBundle(sdkBundle);
43+
44+
var sourceFactory = SourceFactory([
45+
DartUriResolver(sdk),
46+
...uriResolvers,
47+
]);
48+
49+
var dataStore = SummaryDataStore([]);
50+
dataStore.addBundle('', sdkBundle);
51+
52+
var logger = PerformanceLog(null);
53+
var scheduler = AnalysisDriverScheduler(logger);
54+
var driver = AnalysisDriver.tmp1(
55+
scheduler: scheduler,
56+
logger: logger,
57+
resourceProvider: resourceProvider,
58+
byteStore: MemoryByteStore(),
59+
sourceFactory: sourceFactory,
60+
analysisOptions: analysisOptions as AnalysisOptionsImpl,
61+
externalSummaries: dataStore,
62+
packages: packages,
63+
);
64+
65+
scheduler.start();
66+
67+
return AnalysisDriverForPackageBuild._(driver);
68+
}
69+
70+
/// [AnalysisSession] plus a tiny bit more.
71+
class AnalysisDriverForPackageBuild {
72+
final AnalysisDriver _driver;
73+
74+
AnalysisDriverForPackageBuild._(this._driver);
75+
76+
AnalysisSession get currentSession {
77+
return _driver.currentSession;
78+
}
79+
80+
/// The file with the given [path] might have changed - updated, added or
81+
/// removed. Or not, we don't know. Or it might have, but then changed back.
82+
///
83+
/// The [path] must be absolute and normalized.
84+
///
85+
/// The [currentSession] most probably will be invalidated.
86+
/// Note, is does NOT at the time of writing this comment.
87+
/// But we are going to fix this.
88+
void changeFile(String path) {
89+
_driver.changeFile(path);
90+
}
91+
92+
/// Return `true` if the [uri] can be resolved to an existing file.
93+
bool isUriOfExistingFile(Uri uri) {
94+
var source = _driver.sourceFactory.forUri2(uri);
95+
return source != null && source.exists();
96+
}
97+
}

pkg/analyzer/lib/src/dart/analysis/context_builder.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import 'package:analyzer/src/generated/source.dart';
2525
import 'package:analyzer/src/hint/sdk_constraint_extractor.dart';
2626
import 'package:analyzer/src/summary/package_bundle_reader.dart';
2727
import 'package:analyzer/src/summary/summary_sdk.dart';
28+
import 'package:analyzer/src/summary2/package_bundle_format.dart';
2829
import 'package:analyzer/src/task/options.dart';
2930
import 'package:analyzer/src/workspace/workspace.dart';
3031
import 'package:cli_util/cli_util.dart';
@@ -150,8 +151,11 @@ class ContextBuilderImpl implements ContextBuilder {
150151
String? sdkSummaryPath,
151152
}) {
152153
if (sdkSummaryPath != null) {
153-
return SummaryBasedDartSdk(sdkSummaryPath, true,
154-
resourceProvider: resourceProvider);
154+
var file = resourceProvider.getFile(sdkSummaryPath);
155+
var bytes = file.readAsBytesSync();
156+
return SummaryBasedDartSdk.forBundle(
157+
PackageBundleReader(bytes),
158+
);
155159
}
156160

157161
var folderSdk = FolderBasedDartSdk(

pkg/analyzer/lib/src/summary/package_bundle_reader.dart

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class InSummarySource extends BasicSource {
8888
/// The [UriResolver] that knows about sources that are served from their
8989
/// summaries.
9090
class InSummaryUriResolver extends UriResolver {
91+
/// TODO(scheglov) Remove it, we don't need it.
9192
ResourceProvider? resourceProvider;
9293
final SummaryDataStore _dataStore;
9394

pkg/analyzer/lib/src/summary/summary_sdk.dart

+14-1
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,31 @@ import 'package:pub_semver/pub_semver.dart';
1414
/// suitable only for command-line tools, but not for IDEs - it does not
1515
/// implement [sdkLibraries], [uris] and [fromFileUri].
1616
class SummaryBasedDartSdk implements DartSdk {
17+
late final PackageBundleReader _bundle;
1718
late final SummaryDataStore _dataStore;
1819
late final InSummaryUriResolver _uriResolver;
19-
late final PackageBundleReader _bundle;
20+
21+
/// TODO(scheglov) Remove it when the default constructor.
2022
ResourceProvider? resourceProvider;
2123

24+
@Deprecated('Use SummaryBasedDartSdk.forBundle() instead')
2225
SummaryBasedDartSdk(String summaryPath, bool _, {this.resourceProvider}) {
2326
_dataStore = SummaryDataStore(<String>[summaryPath],
2427
resourceProvider: resourceProvider);
2528
_uriResolver = InSummaryUriResolver(resourceProvider, _dataStore);
2629
_bundle = _dataStore.bundles.single;
2730
}
2831

32+
SummaryBasedDartSdk.forBundle(PackageBundleReader bundle) {
33+
_bundle = bundle;
34+
35+
_dataStore = SummaryDataStore([]);
36+
// TODO(scheglov) We need a solution to avoid these paths at all.
37+
_dataStore.addBundle('', bundle);
38+
39+
_uriResolver = InSummaryUriResolver(resourceProvider, _dataStore);
40+
}
41+
2942
@override
3043
String get allowedExperimentsJson {
3144
return _bundle.sdk!.allowedExperimentsJson;

pkg/analyzer/lib/src/test_utilities/mock_sdk.dart

+7
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,19 @@ class pragma {
318318
}
319319
320320
abstract class double extends num {
321+
// TODO: remove these old constants when no tests rely on them.
321322
static const double NAN = 0.0 / 0.0;
322323
static const double INFINITY = 1.0 / 0.0;
323324
static const double NEGATIVE_INFINITY = -INFINITY;
324325
static const double MIN_POSITIVE = 5e-324;
325326
static const double MAX_FINITE = 1.7976931348623157e+308;
326327
328+
static const double nan = 0.0 / 0.0;
329+
static const double infinity = 1.0 / 0.0;
330+
static const double negativeInfinity = -infinity;
331+
static const double minPositive = 5e-324;
332+
static const double maxFinite = 1.7976931348623157e+308;
333+
327334
double get sign;
328335
double operator %(num other);
329336
double operator *(num other);

pkg/analyzer_plugin/lib/src/protocol/protocol_internal.dart

+2-32
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'dart:collection';
66
import 'dart:convert' hide JsonDecoder;
7-
import 'dart:math' as math;
87

98
import 'package:analyzer_plugin/protocol/protocol.dart';
109
import 'package:analyzer_plugin/protocol/protocol_common.dart';
@@ -29,17 +28,6 @@ void addAllEditsForSource(
2928
/// If the invariants can't be preserved, then a [ConflictingEditException] is
3029
/// thrown.
3130
void addEditForSource(SourceFileEdit sourceFileEdit, SourceEdit sourceEdit) {
32-
/// If the [leftEdit] and the [rightEdit] can be merged, then merge them.
33-
SourceEdit? _merge(SourceEdit leftEdit, SourceEdit rightEdit) {
34-
assert(leftEdit.offset <= rightEdit.offset);
35-
if (leftEdit.isDeletion && rightEdit.isDeletion) {
36-
var offset = leftEdit.offset;
37-
var end = math.max(leftEdit.end, rightEdit.end);
38-
return SourceEdit(offset, end - offset, '');
39-
}
40-
return null;
41-
}
42-
4331
var edits = sourceFileEdit.edits;
4432
var length = edits.length;
4533
var index = 0;
@@ -51,12 +39,7 @@ void addEditForSource(SourceFileEdit sourceFileEdit, SourceEdit sourceEdit) {
5139
// The [previousEdit] has an offset that is strictly greater than the offset
5240
// of the [sourceEdit] so we only need to look at the end of the
5341
// [sourceEdit] to know whether they overlap.
54-
if (sourceEdit.end > previousEdit.offset) {
55-
var mergedEdit = _merge(sourceEdit, previousEdit);
56-
if (mergedEdit != null) {
57-
edits[index - 1] = mergedEdit;
58-
return;
59-
}
42+
if (sourceEdit.offset + sourceEdit.length > previousEdit.offset) {
6043
throw ConflictingEditException(
6144
newEdit: sourceEdit, existingEdit: previousEdit);
6245
}
@@ -71,12 +54,7 @@ void addEditForSource(SourceFileEdit sourceFileEdit, SourceEdit sourceEdit) {
7154
if ((sourceEdit.offset == nextEdit.offset &&
7255
sourceEdit.length > 0 &&
7356
nextEdit.length > 0) ||
74-
nextEdit.end > sourceEdit.offset) {
75-
var mergedEdit = _merge(nextEdit, sourceEdit);
76-
if (mergedEdit != null) {
77-
edits[index] = mergedEdit;
78-
return;
79-
}
57+
nextEdit.offset + nextEdit.length > sourceEdit.offset) {
8058
throw ConflictingEditException(
8159
newEdit: sourceEdit, existingEdit: nextEdit);
8260
}
@@ -490,11 +468,3 @@ abstract class ResponseResult implements HasToJson {
490468
/// the given [id], where the request was received at the given [requestTime].
491469
Response toResponse(String id, int requestTime);
492470
}
493-
494-
extension SourceEditExtensions on SourceEdit {
495-
/// Return `true` if this source edit represents a deletion.
496-
bool get isDeletion => replacement.isEmpty;
497-
498-
/// Return `true` if this source edit represents an insertion.
499-
bool get isInsertion => length == 0;
500-
}

0 commit comments

Comments
 (0)