build_ios.dart 2.22 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 14 15 16 17
import '../globals.dart';
import '../ios/mac.dart';
import '../runner/flutter_command.dart';

class BuildIOSCommand extends FlutterCommand {
  BuildIOSCommand() {
18
    addBuildModeFlags();
19 20 21
    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).');
22 23 24 25 26 27
  }

  @override
  final String name = 'ios';

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

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

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

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

    bool forSimulator = argResults['simulator'];
45 46 47
    bool shouldCodesign = argResults['codesign'];

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

52
    String logTarget = forSimulator ? 'simulator' : 'device';
53

54 55 56
    String typeName = path.basename(tools.getEngineArtifactsDirectory(TargetPlatform.ios, getBuildMode()).path);
    Status status = logger.startProgress('Building $app for $logTarget ($typeName)...');
    XcodeBuildResult result = await buildXcodeProject(app, getBuildMode(),
57 58
        buildForDevice: !forSimulator,
        codesign: shouldCodesign);
59
    status.stop(showElapsedTime: true);
60

61
    if (!result.success) {
62 63 64 65
      printError('Encountered error while building for $logTarget.');
      return 1;
    }

66 67
    if (result.output != null)
      printStatus('Built ${result.output}.');
68 69 70 71

    return 0;
  }
}