ios_workflow.dart 4.26 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'dart:async';
6 7
import 'dart:io';

8
import '../base/os.dart';
9 10
import '../base/process.dart';
import '../doctor.dart';
11
import 'mac.dart';
12

13 14 15 16
XCode get xcode => XCode.instance;

class IOSWorkflow extends DoctorValidator implements Workflow {
  IOSWorkflow() : super('iOS toolchain - develop for iOS devices');
17

18
  @override
19 20 21
  bool get appliesToHostPlatform => Platform.isMacOS;

  // We need xcode (+simctl) to list simulator devices, and idevice_id to list real devices.
22
  @override
23
  bool get canListDevices => xcode.isInstalledAndMeetsVersionCheck;
24 25 26

  // We need xcode to launch simulator devices, and ideviceinstaller and ios-deploy
  // for real devices.
27
  @override
28 29 30
  bool get canLaunchDevices => xcode.isInstalledAndMeetsVersionCheck;

  bool get hasIDeviceId => exitsHappy(<String>['idevice_id', '-h']);
31

32
  @override
33
  Future<ValidationResult> validate() async {
34
    List<ValidationMessage> messages = <ValidationMessage>[];
35 36
    ValidationType xcodeStatus = ValidationType.missing;
    ValidationType brewStatus = ValidationType.missing;
37 38 39
    String xcodeVersionInfo;

    if (xcode.isInstalled) {
40
      xcodeStatus = ValidationType.installed;
41

42 43
      messages.add(new ValidationMessage('XCode at ${xcode.xcodeSelectPath}'));

44 45 46 47 48 49
      xcodeVersionInfo = xcode.xcodeVersionText;
      if (xcodeVersionInfo.contains(','))
        xcodeVersionInfo = xcodeVersionInfo.substring(0, xcodeVersionInfo.indexOf(','));
      messages.add(new ValidationMessage(xcode.xcodeVersionText));

      if (!xcode.isInstalledAndMeetsVersionCheck) {
50
        xcodeStatus = ValidationType.partial;
51 52 53 54 55 56 57
        messages.add(new ValidationMessage.error(
          'Flutter requires a minimum XCode version of $kXcodeRequiredVersionMajor.$kXcodeRequiredVersionMinor.0.\n'
          'Download the latest version or update via the Mac App Store.'
        ));
      }

      if (!xcode.eulaSigned) {
58
        xcodeStatus = ValidationType.partial;
59 60 61 62 63
        messages.add(new ValidationMessage.error(
          'XCode end user license agreement not signed; open XCode or run the command \'sudo xcodebuild -license\'.'
        ));
      }
    } else {
64
      xcodeStatus = ValidationType.missing;
65 66 67 68 69 70 71
      messages.add(new ValidationMessage.error(
        'XCode not installed; this is necessary for iOS development.\n'
        'Download at https://developer.apple.com/xcode/download/.'
      ));
    }

    // brew installed
72
    if (os.which('brew') != null) {
73
      brewStatus = ValidationType.installed;
74 75

      if (!exitsHappy(<String>['ideviceinstaller', '-h'])) {
76
        brewStatus = ValidationType.partial;
77 78 79 80 81 82 83
        messages.add(new ValidationMessage.error(
          'ideviceinstaller not available; this is used to discover connected iOS devices.\n'
          'Install via \'brew install ideviceinstaller\'.'
        ));
      }

      if (!hasIDeviceId) {
84
        brewStatus = ValidationType.partial;
85 86 87 88
        messages.add(new ValidationMessage.error(
          'ios-deploy not available; this is used to deploy to connected iOS devices.\n'
          'Install via \'brew install ios-deploy\'.'
        ));
89 90 91 92 93
      } else {
        // Check for compatibility between libimobiledevice and Xcode.
        // TODO(cbracken) remove this check once libimobiledevice > 1.2.0 is released.
        ProcessResult result = (await runAsync(<String>['idevice_id', '-l'])).processResult;
        if (result.exitCode == 0 && result.stdout.isNotEmpty && !exitsHappy(<String>['ideviceName'])) {
94
          brewStatus = ValidationType.partial;
95 96 97 98 99 100
          messages.add(new ValidationMessage.error(
            'libimobiledevice is incompatible with the installed XCode version. To update, run:\n'
            'brew uninstall libimobiledevice\n'
            'brew install --HEAD libimobiledevice'
          ));
        }
101 102
      }
    } else {
103
      brewStatus = ValidationType.missing;
104 105 106 107 108 109 110
      messages.add(new ValidationMessage.error(
        'Brew not installed; use this to install tools for iOS device development.\n'
        'Download brew at http://brew.sh/.'
      ));
    }

    return new ValidationResult(
111
      xcodeStatus == brewStatus ? xcodeStatus : ValidationType.partial,
112 113
      messages,
      statusInfo: xcodeVersionInfo
114
    );
115 116
  }
}