dartdocs.dart 2.96 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:convert';
import 'dart:io';

import 'package:flutter_devicelab/framework/framework.dart';
9
import 'package:flutter_devicelab/framework/task_result.dart';
10
import 'package:flutter_devicelab/framework/utils.dart';
11
import 'package:path/path.dart' as path;
12

13
Future<void> main() async {
14
  final String dot = Platform.isWindows ? '-' : '•';
15
  await task(() async {
16
    final Stopwatch clock = Stopwatch()..start();
17
    final Process analysis = await startProcess(
18
      path.join(flutterDirectory.path, 'bin', 'flutter'),
19
      <String>['analyze', '--no-preamble', '--flutter-repo', '--dartdocs'],
20 21 22 23 24
      workingDirectory: flutterDirectory.path,
    );
    int publicMembers = 0;
    int otherErrors = 0;
    int otherLines = 0;
25
    bool sawFinalLine = false;
26
    await for (String entry in analysis.stdout.transform<String>(utf8.decoder).transform<String>(const LineSplitter())) {
27 28 29 30
      entry = entry.trim();
      print('analyzer stdout: $entry');
      if (entry == 'Building flutter tool...') {
        // ignore this line
31
      } else if (entry.startsWith('info $dot Document all public members $dot')) {
32
        publicMembers += 1;
33
      } else if (entry.startsWith('info $dot') || entry.startsWith('warning $dot') || entry.startsWith('error $dot')) {
34
        otherErrors += 1;
35 36 37
      } else if (entry.contains(' (ran in ') && !sawFinalLine) {
        // ignore this line once
        sawFinalLine = true;
38
      } else if (entry.isNotEmpty) {
39
        otherLines += 1;
40
        print('^ not sure what to do with that line ^');
41 42
      }
    }
43
    await for (final String entry in analysis.stderr.transform<String>(utf8.decoder).transform<String>(const LineSplitter())) {
44
      print('analyzer stderr: $entry');
45
      if (entry.contains(' (ran in ') && !sawFinalLine) {
46 47
        // ignore this line once
        sawFinalLine = true;
48 49
      } else {
        otherLines += 1;
50
        print('^ not sure what to do with that line ^');
51 52 53 54
      }
    }
    final int result = await analysis.exitCode;
    clock.stop();
55 56
    if (!sawFinalLine)
      throw Exception('flutter analyze did not output final message');
57
    if (publicMembers == 0 && otherErrors == 0 && result != 0)
58
      throw Exception('flutter analyze exited with unexpected error code $result');
59
    if (publicMembers != 0 && otherErrors != 0 && result == 0)
60
      throw Exception('flutter analyze exited with successful status code despite reporting errors');
61
    if (otherLines != 0)
62
      throw Exception('flutter analyze had unexpected output (we saw $otherLines unexpected line${ otherLines == 1 ? "" : "s" })');
63 64 65 66 67
    final Map<String, dynamic> data = <String, dynamic>{
      'members_missing_dartdocs': publicMembers,
      'analysis_errors': otherErrors,
      'elapsed_time_ms': clock.elapsedMilliseconds,
    };
68
    return TaskResult.success(data, benchmarkScoreKeys: data.keys.toList());
69 70
  });
}