build_ios.dart 2.97 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/common.dart';
11
import '../base/logger.dart';
12
import '../base/utils.dart';
13
import '../build_info.dart';
14 15
import '../globals.dart';
import '../ios/mac.dart';
16
import 'build.dart';
17

18
class BuildIOSCommand extends BuildSubCommand {
19
  BuildIOSCommand() {
20
    usesTargetOption();
21 22 23 24 25 26 27 28 29
    argParser.addFlag('debug',
      negatable: false,
      help: 'Build a debug version of your app (default mode for iOS simulator builds).');
    argParser.addFlag('profile',
      negatable: false,
      help: 'Build a version of your app specialized for performance profiling.');
    argParser.addFlag('release',
      negatable: false,
      help: 'Build a release version of your app (default mode for device builds).');
30 31 32
    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).');
33 34 35 36 37 38
  }

  @override
  final String name = 'ios';

  @override
39
  final String description = 'Build an iOS application bundle (Mac OS X host only).';
40 41

  @override
42
  Future<Null> runCommand() async {
43 44 45
    bool forSimulator = argResults['simulator'];
    defaultBuildMode = forSimulator ? BuildMode.debug : BuildMode.release;

46
    await super.runCommand();
47 48
    if (getCurrentHostPlatform() != HostPlatform.darwin_x64)
      throwToolExit('Building for iOS is only supported on the Mac.');
49

Devon Carew's avatar
Devon Carew committed
50
    IOSApp app = applicationPackages.getPackageForPlatform(TargetPlatform.ios);
51

52 53
    if (app == null)
      throwToolExit('Application not configured for iOS');
54

55 56 57
    bool shouldCodesign = argResults['codesign'];

    if (!forSimulator && !shouldCodesign) {
58 59
      printStatus('Warning: Building for device with codesigning disabled. You will '
        'have to manually codesign before deploying to device.');
60
    }
61

62 63
    if (forSimulator && !isEmulatorBuildMode(getBuildMode()))
      throwToolExit('${toTitleCase(getModeName(getBuildMode()))} mode is not supported for emulators.');
64

65
    String logTarget = forSimulator ? 'simulator' : 'device';
66

67 68
    String typeName = path.basename(tools.getEngineArtifactsDirectory(TargetPlatform.ios, getBuildMode()).path);
    Status status = logger.startProgress('Building $app for $logTarget ($typeName)...');
69 70 71
    XcodeBuildResult result = await buildXcodeProject(
      app: app,
      mode: getBuildMode(),
72
      target: targetFile,
73 74 75
      buildForDevice: !forSimulator,
      codesign: shouldCodesign
    );
Devon Carew's avatar
Devon Carew committed
76
    status.stop();
77

78
    if (!result.success) {
79
      printError('Encountered error while building for $logTarget.');
80
      diagnoseXcodeBuildFailure(result);
81
      throwToolExit('');
82 83
    }

84 85
    if (result.output != null)
      printStatus('Built ${result.output}.');
86 87
  }
}