build.dart 2.57 KB
Newer Older
1
// Copyright 2016 The Chromium Authors. All rights reserved.
2 3 4 5 6
// 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:meta/meta.dart';

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

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

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

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

35
  @override
36
  Future<Null> verifyThenRunCommand() async {
37
    commandValidator();
38 39 40 41
    return super.verifyThenRunCommand();
  }

  @override
42
  Future<Null> runCommand() async { }
43
}
44

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

  @override
  @mustCallSuper
55
  Future<Null> runCommand() async {
56
    if (isRunningOnBot) {
57
      final File dotPackages = fs.file('.packages');
58 59 60 61 62 63
      printStatus('Contents of .packages:');
      if (dotPackages.existsSync())
        printStatus(dotPackages.readAsStringSync());
      else
        printError('File not found: ${dotPackages.absolute.path}');

64
      final File pubspecLock = fs.file('pubspec.lock');
65 66 67 68 69 70 71 72 73
      printStatus('Contents of pubspec.lock:');
      if (pubspecLock.existsSync())
        printStatus(pubspecLock.readAsStringSync());
      else
        printError('File not found: ${pubspecLock.absolute.path}');
    }
  }
}

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

78 79
  @override
  final String description = 'Delete the build/ directory.';
80

81
  @override
82
  Future<Null> verifyThenRunCommand() async {
83
    commandValidator();
84 85 86 87
    return super.verifyThenRunCommand();
  }

  @override
88
  Future<Null> runCommand() async {
89
    final Directory buildDir = fs.directory(getBuildDirectory());
90
    printStatus("Deleting '${buildDir.path}${fs.path.separator}'.");
91 92

    if (!buildDir.existsSync())
93
      return;
94 95 96 97

    try {
      buildDir.deleteSync(recursive: true);
    } catch (error) {
98
      throwToolExit(error.toString());
99
    }
100 101
  }
}