Skip to content

Commit 5dd0834

Browse files
authored
Remove old version checks (dart-archive/coverage#502)
1 parent ebc5af5 commit 5dd0834

File tree

4 files changed

+41
-411
lines changed

4 files changed

+41
-411
lines changed

pkgs/coverage/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.9.1-wip
2+
3+
- Remove outdated VM service version checks.
4+
15
## 1.9.0
26

37
- Require Dart ^3.4

pkgs/coverage/lib/src/collect.dart

Lines changed: 28 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,6 @@ Future<Map<String, dynamic>> collect(Uri serviceUri, bool resume,
109109
}
110110
}
111111

112-
bool _versionCheck(Version version, int minMajor, int minMinor) {
113-
final major = version.major ?? 0;
114-
final minor = version.minor ?? 0;
115-
return major > minMajor || (major == minMajor && minor >= minMinor);
116-
}
117-
118112
Future<Map<String, dynamic>> _getAllCoverage(
119113
VmService service,
120114
bool includeDart,
@@ -126,111 +120,51 @@ Future<Map<String, dynamic>> _getAllCoverage(
126120
scopedOutput ??= <String>{};
127121
final vm = await service.getVM();
128122
final allCoverage = <Map<String, dynamic>>[];
129-
final version = await service.getVersion();
130-
final reportLines = _versionCheck(version, 3, 51);
131-
final branchCoverageSupported = _versionCheck(version, 3, 56);
132-
final libraryFilters = _versionCheck(version, 3, 57);
133-
final fastIsoGroups = _versionCheck(version, 3, 61);
134-
final lineCacheSupported = _versionCheck(version, 4, 13);
135-
136-
if (branchCoverage && !branchCoverageSupported) {
137-
branchCoverage = false;
138-
stderr.writeln('Branch coverage was requested, but is not supported'
139-
' by the VM version. Try updating to a newer version of Dart');
140-
}
141123

142124
final sourceReportKinds = [
143125
SourceReportKind.kCoverage,
144126
if (branchCoverage) SourceReportKind.kBranchCoverage,
145127
];
146128

147-
final librariesAlreadyCompiled =
148-
lineCacheSupported ? coverableLineCache?.keys.toList() : null;
129+
final librariesAlreadyCompiled = coverableLineCache?.keys.toList();
149130

150131
// Program counters are shared between isolates in the same group. So we need
151132
// to make sure we're only gathering coverage data for one isolate in each
152133
// group, otherwise we'll double count the hits.
153-
final isolateOwnerGroup = <String, String>{};
154134
final coveredIsolateGroups = <String>{};
155-
if (!fastIsoGroups) {
156-
for (var isolateGroupRef in vm.isolateGroups!) {
157-
final isolateGroup = await service.getIsolateGroup(isolateGroupRef.id!);
158-
for (var isolateRef in isolateGroup.isolates!) {
159-
isolateOwnerGroup[isolateRef.id!] = isolateGroupRef.id!;
160-
}
161-
}
162-
}
163135

164136
for (var isolateRef in vm.isolates!) {
165137
if (isolateIds != null && !isolateIds.contains(isolateRef.id)) continue;
166-
final isolateGroupId = fastIsoGroups
167-
? isolateRef.isolateGroupId
168-
: isolateOwnerGroup[isolateRef.id];
138+
final isolateGroupId = isolateRef.isolateGroupId;
169139
if (isolateGroupId != null) {
170140
if (coveredIsolateGroups.contains(isolateGroupId)) continue;
171141
coveredIsolateGroups.add(isolateGroupId);
172142
}
173-
if (scopedOutput.isNotEmpty && !libraryFilters) {
174-
late final ScriptList scripts;
175-
try {
176-
scripts = await service.getScripts(isolateRef.id!);
177-
} on SentinelException {
178-
continue;
179-
}
180-
for (final script in scripts.scripts!) {
181-
// Skip scripts which should not be included in the report.
182-
if (!scopedOutput.includesScript(script.uri)) continue;
183-
late final SourceReport scriptReport;
184-
try {
185-
scriptReport = await service.getSourceReport(
186-
isolateRef.id!,
187-
sourceReportKinds,
188-
forceCompile: true,
189-
scriptId: script.id,
190-
reportLines: reportLines ? true : null,
191-
librariesAlreadyCompiled: librariesAlreadyCompiled,
192-
);
193-
} on SentinelException {
194-
continue;
195-
}
196-
final coverage = await _processSourceReport(
197-
service,
198-
isolateRef,
199-
scriptReport,
200-
includeDart,
201-
functionCoverage,
202-
reportLines,
203-
coverableLineCache,
204-
scopedOutput);
205-
allCoverage.addAll(coverage);
206-
}
207-
} else {
208-
late final SourceReport isolateReport;
209-
try {
210-
isolateReport = await service.getSourceReport(
211-
isolateRef.id!,
212-
sourceReportKinds,
213-
forceCompile: true,
214-
reportLines: reportLines ? true : null,
215-
libraryFilters: scopedOutput.isNotEmpty && libraryFilters
216-
? List.from(scopedOutput.map((filter) => 'package:$filter/'))
217-
: null,
218-
librariesAlreadyCompiled: librariesAlreadyCompiled,
219-
);
220-
} on SentinelException {
221-
continue;
222-
}
223-
final coverage = await _processSourceReport(
224-
service,
225-
isolateRef,
226-
isolateReport,
227-
includeDart,
228-
functionCoverage,
229-
reportLines,
230-
coverableLineCache,
231-
scopedOutput);
232-
allCoverage.addAll(coverage);
143+
144+
late final SourceReport isolateReport;
145+
try {
146+
isolateReport = await service.getSourceReport(
147+
isolateRef.id!,
148+
sourceReportKinds,
149+
forceCompile: true,
150+
reportLines: true,
151+
libraryFilters: scopedOutput.isNotEmpty
152+
? List.from(scopedOutput.map((filter) => 'package:$filter/'))
153+
: null,
154+
librariesAlreadyCompiled: librariesAlreadyCompiled,
155+
);
156+
} on SentinelException {
157+
continue;
233158
}
159+
final coverage = await _processSourceReport(
160+
service,
161+
isolateRef,
162+
isolateReport,
163+
includeDart,
164+
functionCoverage,
165+
coverableLineCache,
166+
scopedOutput);
167+
allCoverage.addAll(coverage);
234168
}
235169
return <String, dynamic>{'type': 'CodeCoverage', 'coverage': allCoverage};
236170
}
@@ -310,13 +244,12 @@ Future<List<Map<String, dynamic>>> _processSourceReport(
310244
SourceReport report,
311245
bool includeDart,
312246
bool functionCoverage,
313-
bool reportLines,
314247
Map<String, Set<int>>? coverableLineCache,
315248
Set<String> scopedOutput) async {
316249
final hitMaps = <Uri, HitMap>{};
317250
final scripts = <ScriptRef, Script>{};
318251
final libraries = <LibraryRef>{};
319-
final needScripts = functionCoverage || !reportLines;
252+
final needScripts = functionCoverage;
320253

321254
Future<Script?> getScript(ScriptRef? scriptRef) async {
322255
if (scriptRef == null) {
@@ -425,15 +358,7 @@ Future<List<Map<String, dynamic>>> _processSourceReport(
425358

426359
void forEachLine(List<int>? tokenPositions, void Function(int line) body) {
427360
if (tokenPositions == null) return;
428-
for (final pos in tokenPositions) {
429-
final line = reportLines ? pos : _getLineFromTokenPos(script!, pos);
430-
if (line == null) {
431-
if (_debugTokenPositions) {
432-
stderr.write(
433-
'tokenPos $pos has no line mapping for script $scriptUri');
434-
}
435-
continue;
436-
}
361+
for (final line in tokenPositions) {
437362
body(line);
438363
}
439364
}

pkgs/coverage/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: coverage
2-
version: 1.9.0
2+
version: 1.9.1-wip
33
description: Coverage data manipulation and formatting
44
repository: https://github.com/dart-lang/coverage
55

0 commit comments

Comments
 (0)