build_configuration.dart 2.64 KB
Newer Older
1 2 3 4
// Copyright 2015 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.

5 6
import 'dart:io';

7 8
import 'package:path/path.dart' as path;

9
import 'base/utils.dart';
10
import 'globals.dart';
11

12 13 14 15 16 17
enum BuildType {
  prebuilt,
  release,
  debug,
}

18
/// The type of build - `debug`, `profile`, or `release`.
19 20
enum BuildMode {
  debug,
21
  profile,
22
  release
23 24
}

25
String getModeName(BuildMode mode) => getEnumName(mode);
26

27 28 29 30 31
// Returns true if the selected build mode uses ahead-of-time compilation.
bool isAotBuildMode(BuildMode mode) {
  return mode == BuildMode.profile || mode == BuildMode.release;
}

32
enum HostPlatform {
33 34 35 36 37
  darwin_x64,
  linux_x64,
}

String getNameForHostPlatform(HostPlatform platform) {
38 39
  switch (platform) {
    case HostPlatform.darwin_x64:
40
      return "mac_debug";
41 42 43 44
    case HostPlatform.linux_x64:
      return "linux-x64";
  }
  assert(false);
45 46 47
}

enum TargetPlatform {
48
  android_arm,
49
  android_x64,
50
  android_x86,
51
  ios,
52 53
  darwin_x64,
  linux_x64
54 55
}

56
String getNameForTargetPlatform(TargetPlatform platform) {
57 58 59 60 61 62 63 64 65 66
  switch (platform) {
    case TargetPlatform.android_arm:
      return "android-arm";
    case TargetPlatform.android_x64:
      return "android-x64";
    case TargetPlatform.android_x86:
      return "android-x86";
    case TargetPlatform.ios:
      return "ios_release";
    case TargetPlatform.darwin_x64:
67
      return "mac_debug";
68 69 70 71
    case TargetPlatform.linux_x64:
      return "linux-x64";
  }
  assert(false);
72 73
}

74 75
HostPlatform getCurrentHostPlatform() {
  if (Platform.isMacOS)
76
    return HostPlatform.darwin_x64;
77
  if (Platform.isLinux)
78 79
    return HostPlatform.linux_x64;

80
  printError('Unsupported host platform, defaulting to Linux');
81 82

  return HostPlatform.linux_x64;
83 84
}

Ian Hickson's avatar
Ian Hickson committed
85 86
TargetPlatform getCurrentHostPlatformAsTarget() {
  if (Platform.isMacOS)
87
    return TargetPlatform.darwin_x64;
Ian Hickson's avatar
Ian Hickson committed
88
  if (Platform.isLinux)
89
    return TargetPlatform.linux_x64;
90
  printError('Unsupported host platform, defaulting to Linux');
91
  return TargetPlatform.linux_x64;
Ian Hickson's avatar
Ian Hickson committed
92 93
}

94
class BuildConfiguration {
95 96 97
  BuildConfiguration.prebuilt({
    this.hostPlatform,
    this.targetPlatform,
98 99
    this.testable: false
  }) : type = BuildType.prebuilt, buildDir = null;
100 101 102

  BuildConfiguration.local({
    this.type,
103 104
    this.hostPlatform,
    this.targetPlatform,
105
    String enginePath,
106
    String buildPath,
Ian Hickson's avatar
Ian Hickson committed
107
    this.testable: false
108 109 110 111 112
  }) : buildDir = path.normalize(path.join(enginePath, buildPath)) {
    assert(type == BuildType.debug || type == BuildType.release);
  }

  final BuildType type;
113 114
  final HostPlatform hostPlatform;
  final TargetPlatform targetPlatform;
115
  final String buildDir;
Ian Hickson's avatar
Ian Hickson committed
116
  final bool testable;
117
}