linux_doctor.dart 2.47 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
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import '../base/io.dart';
import '../base/version.dart';
import '../doctor.dart';
8
import '../globals.dart' as globals;
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

/// A validator that checks for Clang and Make build dependencies
class LinuxDoctorValidator extends DoctorValidator {
  LinuxDoctorValidator() : super('Linux toolchain - develop for Linux desktop');

  /// The minimum version of clang supported.
  final Version minimumClangVersion = Version(3, 4, 0);

  @override
  Future<ValidationResult> validate() async {
    ValidationType validationType = ValidationType.installed;
    final List<ValidationMessage> messages = <ValidationMessage>[];
    /// Check for a minimum version of Clang.
    ProcessResult clangResult;
    try {
24
      clangResult = await globals.processManager.run(const <String>[
25 26 27 28 29 30 31 32 33 34
        'clang++',
        '--version',
      ]);
    } on ArgumentError {
      // ignore error.
    }
    if (clangResult == null || clangResult.exitCode != 0) {
      validationType = ValidationType.missing;
      messages.add(ValidationMessage.error('clang++ is not installed'));
    } else {
35
      final String firstLine = (clangResult.stdout as String).split('\n').first.trim();
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
      final String versionString = RegExp(r'[0-9]+\.[0-9]+\.[0-9]+').firstMatch(firstLine).group(0);
      final Version version = Version.parse(versionString);
      if (version >= minimumClangVersion) {
        messages.add(ValidationMessage('clang++ $version'));
      } else {
        validationType = ValidationType.partial;
        messages.add(ValidationMessage.error('clang++ $version is below minimum version of $minimumClangVersion'));
      }
    }

    /// Check for make.
    // TODO(jonahwilliams): tighten this check to include a version when we have
    // a better idea about what is supported.
    ProcessResult makeResult;
    try {
51
      makeResult = await globals.processManager.run(const <String>[
52 53 54 55 56 57 58 59 60 61
        'make',
        '--version',
      ]);
    } on ArgumentError {
      // ignore error.
    }
    if (makeResult == null || makeResult.exitCode != 0) {
      validationType = ValidationType.missing;
      messages.add(ValidationMessage.error('make is not installed'));
    } else {
62
      final String firstLine = (makeResult.stdout as String).split('\n').first.trim();
63 64 65 66 67 68
      messages.add(ValidationMessage(firstLine));
    }

    return ValidationResult(validationType, messages);
  }
}