@@ -11,7 +11,8 @@ import 'package:dartdoc/src/package_meta.dart';
11
11
import 'package:grinder/grinder.dart' ;
12
12
import 'package:path/path.dart' as p;
13
13
14
- import 'subprocess_launcher.dart' ;
14
+ import 'src/subprocess_launcher.dart' ;
15
+ import 'src/warnings_collection.dart' ;
15
16
import 'task.dart' as task;
16
17
17
18
void main (List <String > args) => grind (args);
@@ -105,8 +106,6 @@ Future<FlutterRepo> get cleanFlutterRepo async {
105
106
106
107
final String _dartdocDocsPath = createTempSync ('dartdoc' ).path;
107
108
108
- final Directory _sdkDocsDir = createTempSync ('sdkdocs' ).absolute;
109
-
110
109
Directory cleanFlutterDir = Directory (
111
110
p.join (p.context.resolveTildePath ('~/.dartdoc_grinder' ), 'cleanFlutter' ));
112
111
@@ -243,107 +242,7 @@ void presubmit() {}
243
242
void buildbot () {}
244
243
245
244
@Task ('Generate docs for the Dart SDK' )
246
- Future <void > buildSdkDocs () async {
247
- log ('building SDK docs' );
248
- await _buildSdkDocs (_sdkDocsDir.path, Future .value (Directory .current.path));
249
- }
250
-
251
- class WarningsCollection {
252
- final String tempDir;
253
- final Map <String , int > warningKeyCounts;
254
- final String branch;
255
- final String ? pubCachePath;
256
-
257
- WarningsCollection (this .tempDir, this .pubCachePath, this .branch)
258
- : warningKeyCounts = {};
259
-
260
- static const String kPubCachePathReplacement = '_xxxPubDirectoryxxx_' ;
261
- static const String kTempDirReplacement = '_xxxTempDirectoryxxx_' ;
262
-
263
- String _toKey (String text) {
264
- var key = text.replaceAll (tempDir, kTempDirReplacement);
265
- var pubCachePath = this .pubCachePath;
266
- if (pubCachePath != null ) {
267
- key = key.replaceAll (pubCachePath, kPubCachePathReplacement);
268
- }
269
- return key;
270
- }
271
-
272
- String _fromKey (String text) {
273
- var key = text.replaceAll (kTempDirReplacement, tempDir);
274
- if (pubCachePath != null ) {
275
- key = key.replaceAll (kPubCachePathReplacement, pubCachePath! );
276
- }
277
- return key;
278
- }
279
-
280
- void add (String text) {
281
- var key = _toKey (text);
282
- warningKeyCounts.update (key, (e) => e + 1 , ifAbsent: () => 1 );
283
- }
284
-
285
- /// Output formatter for comparing warnings. `this` is the original.
286
- String getPrintableWarningDelta (String title, WarningsCollection current) {
287
- var printBuffer = StringBuffer ();
288
- var quantityChangedOuts = < String > {};
289
- var onlyOriginal = < String > {};
290
- var onlyCurrent = < String > {};
291
- var identical = < String > {};
292
- var allKeys = < String > {
293
- ...warningKeyCounts.keys,
294
- ...current.warningKeyCounts.keys
295
- };
296
-
297
- for (var key in allKeys) {
298
- if (warningKeyCounts.containsKey (key) &&
299
- ! current.warningKeyCounts.containsKey (key)) {
300
- onlyOriginal.add (key);
301
- } else if (! warningKeyCounts.containsKey (key) &&
302
- current.warningKeyCounts.containsKey (key)) {
303
- onlyCurrent.add (key);
304
- } else if (warningKeyCounts.containsKey (key) &&
305
- current.warningKeyCounts.containsKey (key) &&
306
- warningKeyCounts[key] != current.warningKeyCounts[key]) {
307
- quantityChangedOuts.add (key);
308
- } else {
309
- identical.add (key);
310
- }
311
- }
312
-
313
- if (onlyOriginal.isNotEmpty) {
314
- printBuffer.writeln (
315
- '*** $title : ${onlyOriginal .length } warnings from $branch , missing in ${current .branch }:' );
316
- for (var key in onlyOriginal) {
317
- printBuffer.writeln (_fromKey (key));
318
- }
319
- }
320
- if (onlyCurrent.isNotEmpty) {
321
- printBuffer.writeln (
322
- '*** $title : ${onlyCurrent .length } new warnings in ${current .branch }, missing in $branch ' );
323
- for (var key in onlyCurrent) {
324
- printBuffer.writeln (current._fromKey (key));
325
- }
326
- }
327
- if (quantityChangedOuts.isNotEmpty) {
328
- printBuffer.writeln ('*** $title : Identical warning quantity changed' );
329
- for (var key in quantityChangedOuts) {
330
- printBuffer.writeln (
331
- '* Appeared ${warningKeyCounts [key ]} times in $branch , ${current .warningKeyCounts [key ]} in ${current .branch }:' );
332
- printBuffer.writeln (current._fromKey (key));
333
- }
334
- }
335
- if (onlyOriginal.isEmpty &&
336
- onlyCurrent.isEmpty &&
337
- quantityChangedOuts.isEmpty) {
338
- printBuffer.writeln (
339
- '*** $title : No difference in warning output from $branch to ${current .branch }${allKeys .isEmpty ? "" : " (${allKeys .length } warnings found)" }' );
340
- } else if (identical.isNotEmpty) {
341
- printBuffer.writeln (
342
- '*** $title : Difference in warning output found for ${allKeys .length - identical .length } warnings (${allKeys .length } warnings found)"' );
343
- }
344
- return printBuffer.toString ();
345
- }
346
- }
245
+ Future <void > buildSdkDocs () async => await task.docSdk ();
347
246
348
247
/// Returns a map of warning texts to the number of times each has been seen.
349
248
WarningsCollection jsonMessageIterableToWarnings (
@@ -363,27 +262,6 @@ WarningsCollection jsonMessageIterableToWarnings(
363
262
return warningTexts;
364
263
}
365
264
366
- @Task ('Display delta in SDK warnings' )
367
- Future <void > compareSdkWarnings () async {
368
- var originalDartdocSdkDocs =
369
- Directory .systemTemp.createTempSync ('dartdoc-comparison-sdkdocs' );
370
- var originalDartdoc = createComparisonDartdoc ();
371
- var currentDartdocSdkBuild = _buildSdkDocs (
372
- _sdkDocsDir.path, Future .value (Directory .current.path), 'current' );
373
- var originalDartdocSdkBuild =
374
- _buildSdkDocs (originalDartdocSdkDocs.path, originalDartdoc, 'original' );
375
- var currentDartdocWarnings = jsonMessageIterableToWarnings (
376
- await currentDartdocSdkBuild, _sdkDocsDir.path, null , 'HEAD' );
377
- var originalDartdocWarnings = jsonMessageIterableToWarnings (
378
- await originalDartdocSdkBuild,
379
- originalDartdocSdkDocs.absolute.path,
380
- null ,
381
- dartdocOriginalBranch);
382
-
383
- print (originalDartdocWarnings.getPrintableWarningDelta (
384
- 'SDK docs' , currentDartdocWarnings));
385
- }
386
-
387
265
/// Helper function to create a clean version of dartdoc (based on the current
388
266
/// directory, assumed to be a git repository). Uses [dartdocOriginalBranch]
389
267
/// to checkout a branch or tag.
@@ -468,29 +346,6 @@ Future<void> testWithAnalyzerSdk() async {
468
346
}
469
347
}
470
348
471
- Future <Iterable <Map <String , Object ?>>> _buildSdkDocs (
472
- String sdkDocsPath, Future <String > futureCwd,
473
- [String label = '' ]) async {
474
- if (label != '' ) label = '-$label ' ;
475
- var launcher = SubprocessLauncher ('build-sdk-docs$label ' );
476
- var cwd = await futureCwd;
477
- await launcher.runStreamed (Platform .resolvedExecutable, ['pub' , 'get' ],
478
- workingDirectory: cwd);
479
- return await launcher.runStreamed (
480
- Platform .resolvedExecutable,
481
- [
482
- '--enable-asserts' ,
483
- p.join ('bin' , 'dartdoc.dart' ),
484
- '--output' ,
485
- sdkDocsPath,
486
- '--sdk-docs' ,
487
- '--json' ,
488
- '--show-progress' ,
489
- ..._extraDartdocParameters,
490
- ],
491
- workingDirectory: cwd);
492
- }
493
-
494
349
Future <Iterable <Map <String , Object ?>>> _buildTestPackageDocs (
495
350
String outputDir, String cwd,
496
351
{List <String > params = const [],
@@ -609,7 +464,7 @@ Future<void> serveSdkDocs() async {
609
464
'--port' ,
610
465
'8000' ,
611
466
'--path' ,
612
- _sdkDocsDir .path,
467
+ task.sdkDocsDir .path,
613
468
]);
614
469
}
615
470
@@ -638,7 +493,7 @@ Future<void> compareFlutterWarnings() async {
638
493
envOriginal['PUB_CACHE' ],
639
494
dartdocOriginalBranch);
640
495
641
- print (originalDartdocWarnings.getPrintableWarningDelta (
496
+ print (originalDartdocWarnings.warningDeltaText (
642
497
'Flutter repo' , currentDartdocWarnings));
643
498
644
499
if (Platform .environment['SERVE_FLUTTER' ] == '1' ) {
@@ -1076,7 +931,7 @@ void validateSdkDocs() {
1076
931
const expectedLibCounts = 0 ;
1077
932
const expectedSubLibCount = {19 , 20 , 21 };
1078
933
const expectedTotalCount = {19 , 20 , 21 };
1079
- var indexHtml = joinFile (_sdkDocsDir , ['index.html' ]);
934
+ var indexHtml = joinFile (task.sdkDocsDir , ['index.html' ]);
1080
935
if (! indexHtml.existsSync ()) {
1081
936
fail ("No 'index.html' found for the SDK docs" );
1082
937
}
@@ -1098,17 +953,19 @@ void validateSdkDocs() {
1098
953
log ('$foundSubLibs index.html dart: entries in categories found' );
1099
954
1100
955
// check for the existence of certain files/dirs
1101
- var libsLength =
1102
- _sdkDocsDir.listSync ().where ((fs) => fs.path.contains ('dart-' )).length;
956
+ var libsLength = task.sdkDocsDir
957
+ .listSync ()
958
+ .where ((fs) => fs.path.contains ('dart-' ))
959
+ .length;
1103
960
if (! expectedTotalCount.contains (libsLength)) {
1104
961
fail ('Docs not generated for all the SDK libraries; expected '
1105
962
'$expectedTotalCount directories, but $libsLength directories were '
1106
963
'generated' );
1107
964
}
1108
965
log ("Found $libsLength 'dart:' libraries" );
1109
966
1110
- var futureConstFile =
1111
- joinFile (_sdkDocsDir , [p.join ('dart-async' , 'Future' , 'Future.html' )]);
967
+ var futureConstFile = joinFile (
968
+ task.sdkDocsDir , [p.join ('dart-async' , 'Future' , 'Future.html' )]);
1112
969
if (! futureConstFile.existsSync ()) {
1113
970
fail ('no Future.html found for dart:async Future constructor' );
1114
971
}
0 commit comments