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

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

8 9
import 'package:meta/meta.dart';

10
import '../build_info.dart';
11
import '../globals.dart';
12
import '../runner/flutter_command.dart';
13
import '../base/utils.dart';
14
import 'build_apk.dart';
15
import 'build_aot.dart';
16
import 'build_flx.dart';
17
import 'build_ios.dart';
18

19
class BuildCommand extends FlutterCommand {
20
  BuildCommand({bool verboseHelp: false}) {
21
    addSubcommand(new BuildApkCommand());
22
    addSubcommand(new BuildAotCommand());
23
    addSubcommand(new BuildCleanCommand());
24
    addSubcommand(new BuildIOSCommand());
25
    addSubcommand(new BuildFlxCommand(verboseHelp: verboseHelp));
26 27
  }

28
  @override
29
  final String name = 'build';
30 31

  @override
32
  final String description = 'Flutter build commands.';
33

34
  @override
35 36 37 38 39 40 41 42
  Future<int> verifyThenRunCommand() async {
    if (!commandValidator())
      return 1;
    return super.verifyThenRunCommand();
  }

  @override
  Future<int> runCommand() => new Future<int>.value(0);
43
}
44

45 46 47
abstract class BuildSubCommand extends FlutterCommand {
  @override
  @mustCallSuper
48 49 50 51 52 53 54 55 56
  Future<int> verifyThenRunCommand() async {
    if (!commandValidator())
      return 1;
    return super.verifyThenRunCommand();
  }

  @override
  @mustCallSuper
  Future<int> runCommand() async {
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    if (isRunningOnBot) {
      File dotPackages = new File('.packages');
      printStatus('Contents of .packages:');
      if (dotPackages.existsSync())
        printStatus(dotPackages.readAsStringSync());
      else
        printError('File not found: ${dotPackages.absolute.path}');

      File pubspecLock = new File('pubspec.lock');
      printStatus('Contents of pubspec.lock:');
      if (pubspecLock.existsSync())
        printStatus(pubspecLock.readAsStringSync());
      else
        printError('File not found: ${pubspecLock.absolute.path}');
    }
    return 0;
  }
}

76
class BuildCleanCommand extends FlutterCommand {
77
  @override
78
  final String name = 'clean';
79

80 81
  @override
  final String description = 'Delete the build/ directory.';
82

83
  @override
84 85 86 87 88 89 90 91
  Future<int> verifyThenRunCommand() async {
    if (!commandValidator())
      return 1;
    return super.verifyThenRunCommand();
  }

  @override
  Future<int> runCommand() async {
92
    Directory buildDir = new Directory(getBuildDirectory());
93 94 95 96 97 98 99 100 101 102 103 104
    printStatus("Deleting '${buildDir.path}${Platform.pathSeparator}'.");

    if (!buildDir.existsSync())
      return 0;

    try {
      buildDir.deleteSync(recursive: true);
      return 0;
    } catch (error) {
      printError(error.toString());
      return 1;
    }
105 106
  }
}