@@ -109,12 +109,6 @@ Future<Map<String, dynamic>> collect(Uri serviceUri, bool resume,
109
109
}
110
110
}
111
111
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
-
118
112
Future <Map <String , dynamic >> _getAllCoverage (
119
113
VmService service,
120
114
bool includeDart,
@@ -126,111 +120,51 @@ Future<Map<String, dynamic>> _getAllCoverage(
126
120
scopedOutput ?? = < String > {};
127
121
final vm = await service.getVM ();
128
122
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
- }
141
123
142
124
final sourceReportKinds = [
143
125
SourceReportKind .kCoverage,
144
126
if (branchCoverage) SourceReportKind .kBranchCoverage,
145
127
];
146
128
147
- final librariesAlreadyCompiled =
148
- lineCacheSupported ? coverableLineCache? .keys.toList () : null ;
129
+ final librariesAlreadyCompiled = coverableLineCache? .keys.toList ();
149
130
150
131
// Program counters are shared between isolates in the same group. So we need
151
132
// to make sure we're only gathering coverage data for one isolate in each
152
133
// group, otherwise we'll double count the hits.
153
- final isolateOwnerGroup = < String , String > {};
154
134
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
- }
163
135
164
136
for (var isolateRef in vm.isolates! ) {
165
137
if (isolateIds != null && ! isolateIds.contains (isolateRef.id)) continue ;
166
- final isolateGroupId = fastIsoGroups
167
- ? isolateRef.isolateGroupId
168
- : isolateOwnerGroup[isolateRef.id];
138
+ final isolateGroupId = isolateRef.isolateGroupId;
169
139
if (isolateGroupId != null ) {
170
140
if (coveredIsolateGroups.contains (isolateGroupId)) continue ;
171
141
coveredIsolateGroups.add (isolateGroupId);
172
142
}
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 ;
233
158
}
159
+ final coverage = await _processSourceReport (
160
+ service,
161
+ isolateRef,
162
+ isolateReport,
163
+ includeDart,
164
+ functionCoverage,
165
+ coverableLineCache,
166
+ scopedOutput);
167
+ allCoverage.addAll (coverage);
234
168
}
235
169
return < String , dynamic > {'type' : 'CodeCoverage' , 'coverage' : allCoverage};
236
170
}
@@ -310,13 +244,12 @@ Future<List<Map<String, dynamic>>> _processSourceReport(
310
244
SourceReport report,
311
245
bool includeDart,
312
246
bool functionCoverage,
313
- bool reportLines,
314
247
Map <String , Set <int >>? coverableLineCache,
315
248
Set <String > scopedOutput) async {
316
249
final hitMaps = < Uri , HitMap > {};
317
250
final scripts = < ScriptRef , Script > {};
318
251
final libraries = < LibraryRef > {};
319
- final needScripts = functionCoverage || ! reportLines ;
252
+ final needScripts = functionCoverage;
320
253
321
254
Future <Script ?> getScript (ScriptRef ? scriptRef) async {
322
255
if (scriptRef == null ) {
@@ -425,15 +358,7 @@ Future<List<Map<String, dynamic>>> _processSourceReport(
425
358
426
359
void forEachLine (List <int >? tokenPositions, void Function (int line) body) {
427
360
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) {
437
362
body (line);
438
363
}
439
364
}
0 commit comments