build_info.dart 3.95 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
import 'base/context.dart';
6
import 'base/file_system.dart';
7
import 'base/platform.dart';
8
import 'base/utils.dart';
9
import 'globals.dart';
10

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

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

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

26 27 28 29 30 31 32 33 34 35
BuildMode getBuildModeForName(String mode) {
  if (mode == 'debug')
    return BuildMode.debug;
  if (mode == 'profile')
    return BuildMode.profile;
  if (mode == 'release')
    return BuildMode.release;
  return null;
}

36 37 38 39 40
// Returns true if the selected build mode uses ahead-of-time compilation.
bool isAotBuildMode(BuildMode mode) {
  return mode == BuildMode.profile || mode == BuildMode.release;
}

41 42 43
// Returns true if the given build mode can be used on emulators / simulators.
bool isEmulatorBuildMode(BuildMode mode) => mode == BuildMode.debug;

44
enum HostPlatform {
45 46
  darwin_x64,
  linux_x64,
47
  windows_x64,
48 49 50
}

String getNameForHostPlatform(HostPlatform platform) {
51 52
  switch (platform) {
    case HostPlatform.darwin_x64:
53
      return 'darwin-x64';
54
    case HostPlatform.linux_x64:
55
      return 'linux-x64';
56 57
    case HostPlatform.windows_x64:
      return 'windows-x64';
58 59
  }
  assert(false);
pq's avatar
pq committed
60
  return null;
61 62 63
}

enum TargetPlatform {
64
  android_arm,
65
  android_x64,
66
  android_x86,
67
  ios,
68
  darwin_x64,
69
  linux_x64,
70 71
  windows_x64,
  fuchsia,
72 73
}

74
String getNameForTargetPlatform(TargetPlatform platform) {
75 76
  switch (platform) {
    case TargetPlatform.android_arm:
77
      return 'android-arm';
78
    case TargetPlatform.android_x64:
79
      return 'android-x64';
80
    case TargetPlatform.android_x86:
81
      return 'android-x86';
82
    case TargetPlatform.ios:
83
      return 'ios';
84
    case TargetPlatform.darwin_x64:
85
      return 'darwin-x64';
86
    case TargetPlatform.linux_x64:
87
      return 'linux-x64';
88 89
    case TargetPlatform.windows_x64:
      return 'windows-x64';
90 91
    case TargetPlatform.fuchsia:
      return 'fuchsia';
92 93
  }
  assert(false);
pq's avatar
pq committed
94
  return null;
95 96
}

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
TargetPlatform getTargetPlatformForName(String platform) {
  switch (platform) {
    case 'android-arm':
      return TargetPlatform.android_arm;
    case 'android-x64':
      return TargetPlatform.android_x64;
    case 'android-x86':
      return TargetPlatform.android_x86;
    case 'ios':
      return TargetPlatform.ios;
    case 'darwin-x64':
      return TargetPlatform.darwin_x64;
    case 'linux-x64':
      return TargetPlatform.linux_x64;
  }
pq's avatar
pq committed
112
  assert(platform != null);
113 114 115
  return null;
}

116
HostPlatform getCurrentHostPlatform() {
117
  if (platform.isMacOS)
118
    return HostPlatform.darwin_x64;
119
  if (platform.isLinux)
120
    return HostPlatform.linux_x64;
121 122
  if (platform.isWindows)
    return HostPlatform.windows_x64;
123

124
  printError('Unsupported host platform, defaulting to Linux');
125 126

  return HostPlatform.linux_x64;
127
}
128 129 130

/// Returns the top-level build output directory.
String getBuildDirectory() {
131 132
  // TODO(johnmccutchan): Stop calling this function as part of setting
  // up command line argument processing.
133
  if (context == null || config == null)
134 135
    return 'build';

136
  final String buildDir = config.getValue('build-dir') ?? 'build';
137
  if (fs.path.isAbsolute(buildDir)) {
138 139 140 141 142 143 144 145 146 147 148 149 150 151
    throw new Exception(
        'build-dir config setting in ${config.configPath} must be relative');
  }
  return buildDir;
}

/// Returns the Android build output directory.
String getAndroidBuildDirectory() {
  // TODO(cbracken) move to android subdir.
  return getBuildDirectory();
}

/// Returns the AOT build output directory.
String getAotBuildDirectory() {
152
  return fs.path.join(getBuildDirectory(), 'aot');
153 154 155 156
}

/// Returns the asset build output directory.
String getAssetBuildDirectory() {
157
  return fs.path.join(getBuildDirectory(), 'flx');
158 159 160 161
}

/// Returns the iOS build output directory.
String getIosBuildDirectory() {
162
  return fs.path.join(getBuildDirectory(), 'ios');
163
}