build_ios.dart 2.31 KB
Newer Older
1 2 3 4 5 6
// 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.

import 'dart:async';

7 8
import 'package:path/path.dart' as path;

9
import '../application_package.dart';
10
import '../base/logger.dart';
11
import '../build_info.dart';
12 13
import '../globals.dart';
import '../ios/mac.dart';
14
import 'build.dart';
15

16
class BuildIOSCommand extends BuildSubCommand {
17
  BuildIOSCommand() {
18
    usesTargetOption();
19
    addBuildModeFlags();
20 21 22
    argParser.addFlag('simulator', help: 'Build for the iOS simulator instead of the device.');
    argParser.addFlag('codesign', negatable: true, defaultsTo: true,
        help: 'Codesign the application bundle (only available on device builds).');
23 24 25 26 27 28
  }

  @override
  final String name = 'ios';

  @override
29
  final String description = 'Build an iOS application bundle (Mac OS X host only).';
30 31 32

  @override
  Future<int> runInProject() async {
33
    await super.runInProject();
34
    if (getCurrentHostPlatform() != HostPlatform.darwin_x64) {
35 36 37 38
      printError('Building for iOS is only supported on the Mac.');
      return 1;
    }

Devon Carew's avatar
Devon Carew committed
39
    IOSApp app = applicationPackages.getPackageForPlatform(TargetPlatform.ios);
40 41 42 43 44 45 46

    if (app == null) {
      printError('Application not configured for iOS');
      return 1;
    }

    bool forSimulator = argResults['simulator'];
47 48 49
    bool shouldCodesign = argResults['codesign'];

    if (!forSimulator && !shouldCodesign) {
50 51
      printStatus('Warning: Building for device with codesigning disabled. You will '
        'have to manually codesign before deploying to device.');
52
    }
53

54
    String logTarget = forSimulator ? 'simulator' : 'device';
55

56 57
    String typeName = path.basename(tools.getEngineArtifactsDirectory(TargetPlatform.ios, getBuildMode()).path);
    Status status = logger.startProgress('Building $app for $logTarget ($typeName)...');
58 59 60
    XcodeBuildResult result = await buildXcodeProject(
      app: app,
      mode: getBuildMode(),
61
      target: targetFile,
62 63 64
      buildForDevice: !forSimulator,
      codesign: shouldCodesign
    );
65
    status.stop(showElapsedTime: true);
66

67
    if (!result.success) {
68 69 70 71
      printError('Encountered error while building for $logTarget.');
      return 1;
    }

72 73
    if (result.output != null)
      printStatus('Built ${result.output}.');
74 75 76 77

    return 0;
  }
}