build_ios.dart 1.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// 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';

import '../application_package.dart';
import '../build_configuration.dart';
import '../globals.dart';
import '../ios/mac.dart';
import '../runner/flutter_command.dart';

class BuildIOSCommand extends FlutterCommand {
  BuildIOSCommand() {
15 16 17
    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).');
18 19 20 21 22 23
  }

  @override
  final String name = 'ios';

  @override
24
  final String description = 'Build an iOS application bundle (Mac OSX host only).';
25 26 27

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

Devon Carew's avatar
Devon Carew committed
33
    IOSApp app = applicationPackages.getPackageForPlatform(TargetPlatform.ios);
34 35 36 37 38 39 40

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

    bool forSimulator = argResults['simulator'];
41 42 43 44 45 46
    bool shouldCodesign = argResults['codesign'];

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

    String logTarget = forSimulator ? "simulator" : "device";

Devon Carew's avatar
Devon Carew committed
50
    printStatus('Building $app for $logTarget...');
51

52
    bool result = await buildIOSXcodeProject(app,
53
        buildForDevice: !forSimulator, codesign: shouldCodesign);
54 55 56 57 58 59

    if (!result) {
      printError('Encountered error while building for $logTarget.');
      return 1;
    }

60
    printStatus('Built in ios/.generated.');
61 62 63 64

    return 0;
  }
}