build_info.dart 21.5 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
import 'package:meta/meta.dart';

7
import 'base/context.dart';
8
import 'base/logger.dart';
9
import 'base/utils.dart';
10
import 'build_system/targets/icon_tree_shaker.dart';
11
import 'globals.dart' as globals;
12

13 14
/// Information about a build to be performed or used.
class BuildInfo {
15 16 17
  const BuildInfo(
    this.mode,
    this.flavor, {
18
    this.trackWidgetCreation = false,
19 20
    this.extraFrontEndOptions,
    this.extraGenSnapshotOptions,
21 22
    this.fileSystemRoots,
    this.fileSystemScheme,
23 24
    this.buildNumber,
    this.buildName,
25
    this.splitDebugInfoPath,
26
    this.dartObfuscation = false,
27
    this.dartDefines = const <String>[],
28
    this.bundleSkSLPath,
29
    this.dartExperiments = const <String>[],
30
    @required this.treeShakeIcons,
31
    this.performanceMeasurementFile,
32
    this.packagesPath = '.packages',
33
  });
34 35

  final BuildMode mode;
36

37 38 39
  /// Whether the build should subdset icon fonts.
  final bool treeShakeIcons;

40 41 42 43 44 45 46 47
  /// Represents a custom Android product flavor or an Xcode scheme, null for
  /// using the default.
  ///
  /// If not null, the Gradle build task will be `assembleFlavorMode` (e.g.
  /// `assemblePaidRelease`), and the Xcode build configuration will be
  /// Mode-Flavor (e.g. Release-Paid).
  final String flavor;

48 49 50 51 52 53
  /// The path to the .packages file to use for compilation.
  ///
  /// This is used by package:package_config to locate the actual package_config.json
  /// file. If not provded, defaults to `.packages`.
  final String packagesPath;

54 55 56
  final List<String> fileSystemRoots;
  final String fileSystemScheme;

57 58 59
  /// Whether the build should track widget creation locations.
  final bool trackWidgetCreation;

60
  /// Extra command-line options for front-end.
61
  final List<String> extraFrontEndOptions;
62 63

  /// Extra command-line options for gen_snapshot.
64
  final List<String> extraGenSnapshotOptions;
65

66 67 68 69 70
  /// Internal version number (not displayed to users).
  /// Each build must have a unique number to differentiate it from previous builds.
  /// It is used to determine whether one build is more recent than another, with higher numbers indicating more recent build.
  /// On Android it is used as versionCode.
  /// On Xcode builds it is used as CFBundleVersion.
71
  final String buildNumber;
72 73 74 75 76 77 78

  /// A "x.y.z" string used as the version number shown to users.
  /// For each new version of your app, you will provide a version number to differentiate it from previous versions.
  /// On Android it is used as versionName.
  /// On Xcode builds it is used as CFBundleShortVersionString,
  final String buildName;

79 80 81 82 83
  /// An optional directory path to save debugging information from dwarf stack
  /// traces. If null, stack trace information is not stripped from the
  /// executable.
  final String splitDebugInfoPath;

84 85 86
  /// Whether to apply dart source code obfuscation.
  final bool dartObfuscation;

87 88 89 90 91
  /// An optional path to a JSON containing object SkSL shaders
  ///
  /// Currently this is only supported for Android builds.
  final String bundleSkSLPath;

92 93 94 95 96 97
  /// Additional constant values to be made available in the Dart program.
  ///
  /// These values can be used with the const `fromEnvironment` constructors of
  /// [bool], [String], [int], and [double].
  final List<String> dartDefines;

98 99 100
  /// A list of Dart experiments.
  final List<String> dartExperiments;

101 102 103 104 105 106 107
  /// The name of a file where flutter assemble will output performance
  /// information in a JSON format.
  ///
  /// This is not considered a build input and will not force assemble to
  /// rerun tasks.
  final String performanceMeasurementFile;

108 109 110 111
  static const BuildInfo debug = BuildInfo(BuildMode.debug, null, treeShakeIcons: false);
  static const BuildInfo profile = BuildInfo(BuildMode.profile, null, treeShakeIcons: kIconTreeShakerEnabledDefault);
  static const BuildInfo jitRelease = BuildInfo(BuildMode.jitRelease, null, treeShakeIcons: kIconTreeShakerEnabledDefault);
  static const BuildInfo release = BuildInfo(BuildMode.release, null, treeShakeIcons: kIconTreeShakerEnabledDefault);
112 113 114 115 116 117 118 119

  /// Returns whether a debug build is requested.
  ///
  /// Exactly one of [isDebug], [isProfile], or [isRelease] is true.
  bool get isDebug => mode == BuildMode.debug;

  /// Returns whether a profile build is requested.
  ///
120 121
  /// Exactly one of [isDebug], [isProfile], [isJitRelease],
  /// or [isRelease] is true.
122
  bool get isProfile => mode == BuildMode.profile;
123 124 125

  /// Returns whether a release build is requested.
  ///
126 127
  /// Exactly one of [isDebug], [isProfile], [isJitRelease],
  /// or [isRelease] is true.
128
  bool get isRelease => mode == BuildMode.release;
129

130 131 132 133 134 135
  /// Returns whether a JIT release build is requested.
  ///
  /// Exactly one of [isDebug], [isProfile], [isJitRelease],
  /// or [isRelease] is true.
  bool get isJitRelease => mode == BuildMode.jitRelease;

136 137 138 139
  bool get usesAot => isAotBuildMode(mode);
  bool get supportsEmulator => isEmulatorBuildMode(mode);
  bool get supportsSimulator => isEmulatorBuildMode(mode);
  String get modeName => getModeName(mode);
140
  String get friendlyModeName => getFriendlyModeName(mode);
141 142 143 144 145 146 147 148

  /// Convert to a structued string encoded structure appropriate for usage as
  /// environment variables or to embed in other scripts.
  ///
  /// Fields that are `null` are excluded from this configration.
  Map<String, String> toEnvironmentConfig() {
    return <String, String>{
      if (dartDefines?.isNotEmpty ?? false)
149
        'DART_DEFINES': encodeDartDefines(dartDefines),
150 151 152
      if (dartObfuscation != null)
        'DART_OBFUSCATION': dartObfuscation.toString(),
      if (extraFrontEndOptions?.isNotEmpty ?? false)
153
        'EXTRA_FRONT_END_OPTIONS': encodeDartDefines(extraFrontEndOptions),
154
      if (extraGenSnapshotOptions?.isNotEmpty ?? false)
155
        'EXTRA_GEN_SNAPSHOT_OPTIONS': encodeDartDefines(extraGenSnapshotOptions),
156 157 158 159 160 161
      if (splitDebugInfoPath != null)
        'SPLIT_DEBUG_INFO': splitDebugInfoPath,
      if (trackWidgetCreation != null)
        'TRACK_WIDGET_CREATION': trackWidgetCreation.toString(),
      if (treeShakeIcons != null)
        'TREE_SHAKE_ICONS': treeShakeIcons.toString(),
162 163
      if (performanceMeasurementFile != null)
        'PERFORMANCE_MEASUREMENT_FILE': performanceMeasurementFile,
164 165
      if (bundleSkSLPath != null)
        'BUNDLE_SKSL_PATH': bundleSkSLPath,
166 167
      if (packagesPath != null)
        'PACKAGE_CONFIG': packagesPath,
168 169
    };
  }
170 171 172 173 174 175 176 177 178
}

/// Information about an Android build to be performed or used.
class AndroidBuildInfo {
  const AndroidBuildInfo(
    this.buildInfo, {
    this.targetArchs = const <AndroidArch>[
      AndroidArch.armeabi_v7a,
      AndroidArch.arm64_v8a,
179
      AndroidArch.x86_64,
180 181
    ],
    this.splitPerAbi = false,
Emmanuel Garcia's avatar
Emmanuel Garcia committed
182
    this.shrink = false,
183
    this.fastStart = false,
184
  });
185

186 187 188 189 190 191 192 193 194 195
  // The build info containing the mode and flavor.
  final BuildInfo buildInfo;

  /// Whether to split the shared library per ABI.
  ///
  /// When this is false, multiple ABIs will be contained within one primary
  /// build artifact. When this is true, multiple build artifacts (one per ABI)
  /// will be produced.
  final bool splitPerAbi;

Emmanuel Garcia's avatar
Emmanuel Garcia committed
196 197
  /// Whether to enable code shrinking on release mode.
  final bool shrink;
198

199 200
  /// The target platforms for the build.
  final Iterable<AndroidArch> targetArchs;
201 202 203

  /// Whether to bootstrap an empty application.
  final bool fastStart;
204 205
}

206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
/// A summary of the compilation strategy used for Dart.
class BuildMode {
  const BuildMode._(this.name);

  factory BuildMode.fromName(String value) {
    switch (value) {
      case 'debug':
        return BuildMode.debug;
      case 'profile':
        return BuildMode.profile;
      case 'release':
        return BuildMode.release;
      case 'jit_release':
        return BuildMode.jitRelease;
    }
    throw ArgumentError('$value is not a supported build mode');
  }

  /// Built in JIT mode with no optimizations, enabled asserts, and an observatory.
  static const BuildMode debug = BuildMode._('debug');

  /// Built in AOT mode with some optimizations and an observatory.
  static const BuildMode profile = BuildMode._('profile');

  /// Built in AOT mode with all optimizations and no observatory.
  static const BuildMode release = BuildMode._('release');

  /// Built in JIT mode with all optimizations and no observatory.
  static const BuildMode jitRelease = BuildMode._('jit_release');

  static const List<BuildMode> values = <BuildMode>[
    debug,
    profile,
    release,
    jitRelease,
  ];
  static const Set<BuildMode> releaseModes = <BuildMode>{
    release,
    jitRelease,
  };
  static const Set<BuildMode> jitModes = <BuildMode>{
    debug,
    jitRelease,
  };

  /// Whether this mode is considered release.
  ///
  /// Useful for determining whether we should enable/disable asserts or
  /// other development features.
  bool get isRelease => releaseModes.contains(this);
256

257
  /// Whether this mode is using the JIT runtime.
258 259 260 261 262 263 264 265 266 267 268
  bool get isJit => jitModes.contains(this);

  /// Whether this mode is using the precompiled runtime.
  bool get isPrecompiled => !isJit;

  /// The name for this build mode.
  final String name;

  @override
  String toString() => name;
}
269 270 271

/// Return the name for the build mode, or "any" if null.
String getNameForBuildMode(BuildMode buildMode) {
272
  return buildMode.name;
273 274 275 276
}

/// Returns the [BuildMode] for a particular `name`.
BuildMode getBuildModeForName(String name) {
277
  return BuildMode.fromName(name);
278 279
}

280
String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String buildNumber, Logger logger) {
281 282 283 284
  if (buildNumber == null) {
    return null;
  }
  if (targetPlatform == TargetPlatform.ios ||
285
      targetPlatform == TargetPlatform.darwin_x64) {
286 287 288
    // See CFBundleVersion at https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
    final RegExp disallowed = RegExp(r'[^\d\.]');
    String tmpBuildNumber = buildNumber.replaceAll(disallowed, '');
289 290 291
    if (tmpBuildNumber.isEmpty) {
      return null;
    }
292 293 294 295 296 297 298 299 300
    final List<String> segments = tmpBuildNumber
        .split('.')
        .where((String segment) => segment.isNotEmpty)
        .toList();
    if (segments.isEmpty) {
      segments.add('0');
    }
    tmpBuildNumber = segments.join('.');
    if (tmpBuildNumber != buildNumber) {
301
      logger.printTrace('Invalid build-number: $buildNumber for iOS/macOS, overridden by $tmpBuildNumber.\n'
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
          'See CFBundleVersion at https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html');
    }
    return tmpBuildNumber;
  }
  if (targetPlatform == TargetPlatform.android_arm ||
      targetPlatform == TargetPlatform.android_arm64 ||
      targetPlatform == TargetPlatform.android_x64 ||
      targetPlatform == TargetPlatform.android_x86) {
    // See versionCode at https://developer.android.com/studio/publish/versioning
    final RegExp disallowed = RegExp(r'[^\d]');
    String tmpBuildNumberStr = buildNumber.replaceAll(disallowed, '');
    int tmpBuildNumberInt = int.tryParse(tmpBuildNumberStr) ?? 0;
    if (tmpBuildNumberInt < 1) {
      tmpBuildNumberInt = 1;
    }
    tmpBuildNumberStr = tmpBuildNumberInt.toString();
    if (tmpBuildNumberStr != buildNumber) {
319
      logger.printTrace('Invalid build-number: $buildNumber for Android, overridden by $tmpBuildNumberStr.\n'
320 321 322 323 324 325 326
          'See versionCode at https://developer.android.com/studio/publish/versioning');
    }
    return tmpBuildNumberStr;
  }
  return buildNumber;
}

327
String validatedBuildNameForPlatform(TargetPlatform targetPlatform, String buildName, Logger logger) {
328 329 330 331
  if (buildName == null) {
    return null;
  }
  if (targetPlatform == TargetPlatform.ios ||
332
      targetPlatform == TargetPlatform.darwin_x64) {
333 334 335
    // See CFBundleShortVersionString at https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
    final RegExp disallowed = RegExp(r'[^\d\.]');
    String tmpBuildName = buildName.replaceAll(disallowed, '');
336 337 338
    if (tmpBuildName.isEmpty) {
      return null;
    }
339 340 341 342 343 344 345 346 347
    final List<String> segments = tmpBuildName
        .split('.')
        .where((String segment) => segment.isNotEmpty)
        .toList();
    while (segments.length < 3) {
      segments.add('0');
    }
    tmpBuildName = segments.join('.');
    if (tmpBuildName != buildName) {
348
      logger.printTrace('Invalid build-name: $buildName for iOS/macOS, overridden by $tmpBuildName.\n'
349 350 351 352
          'See CFBundleShortVersionString at https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html');
    }
    return tmpBuildName;
  }
353 354
  if (targetPlatform == TargetPlatform.android ||
      targetPlatform == TargetPlatform.android_arm ||
355 356 357 358 359 360 361 362 363
      targetPlatform == TargetPlatform.android_arm64 ||
      targetPlatform == TargetPlatform.android_x64 ||
      targetPlatform == TargetPlatform.android_x86) {
    // See versionName at https://developer.android.com/studio/publish/versioning
    return buildName;
  }
  return buildName;
}

364
String getModeName(BuildMode mode) => getEnumName(mode);
365

366 367 368 369
String getFriendlyModeName(BuildMode mode) {
  return snakeCase(getModeName(mode)).replaceAll('_', ' ');
}

370 371 372 373 374
// Returns true if the selected build mode uses ahead-of-time compilation.
bool isAotBuildMode(BuildMode mode) {
  return mode == BuildMode.profile || mode == BuildMode.release;
}

375
// Returns true if the given build mode can be used on emulators / simulators.
376
bool isEmulatorBuildMode(BuildMode mode) {
377
  return mode == BuildMode.debug;
378
}
379

380
enum HostPlatform {
381 382
  darwin_x64,
  linux_x64,
383
  windows_x64,
384 385 386
}

String getNameForHostPlatform(HostPlatform platform) {
387 388
  switch (platform) {
    case HostPlatform.darwin_x64:
389
      return 'darwin-x64';
390
    case HostPlatform.linux_x64:
391
      return 'linux-x64';
392 393
    case HostPlatform.windows_x64:
      return 'windows-x64';
394 395
  }
  assert(false);
pq's avatar
pq committed
396
  return null;
397 398 399
}

enum TargetPlatform {
400
  android,
401
  ios,
402 403 404
  darwin_x64,
  linux_x64,
  windows_x64,
405 406
  fuchsia_arm64,
  fuchsia_x64,
407
  tester,
408
  web_javascript,
409 410 411 412 413 414 415 416
  // The arch specific android target platforms are soft-depreacted.
  // Instead of using TargetPlatform as a combination arch + platform
  // the code will be updated to carry arch information in [DarwinArch]
  // and [AndroidArch].
  android_arm,
  android_arm64,
  android_x64,
  android_x86,
417 418
}

419
/// iOS and macOS target device architecture.
420 421
//
// TODO(cbracken): split TargetPlatform.ios into ios_armv7, ios_arm64.
422
enum DarwinArch {
423 424
  armv7,
  arm64,
425
  x86_64,
426 427
}

428
// TODO(jonahwilliams): replace all android TargetPlatform usage with AndroidArch.
429 430 431 432 433 434 435
enum AndroidArch {
  armeabi_v7a,
  arm64_v8a,
  x86,
  x86_64,
}

436
/// The default set of iOS device architectures to build for.
437 438
const List<DarwinArch> defaultIOSArchs = <DarwinArch>[
  DarwinArch.arm64,
439 440
];

441
String getNameForDarwinArch(DarwinArch arch) {
442
  switch (arch) {
443
    case DarwinArch.armv7:
444
      return 'armv7';
445
    case DarwinArch.arm64:
446
      return 'arm64';
447 448
    case DarwinArch.x86_64:
      return 'x86_64';
449 450 451 452 453
  }
  assert(false);
  return null;
}

454
DarwinArch getIOSArchForName(String arch) {
455 456
  switch (arch) {
    case 'armv7':
457
    case 'armv7f': // iPhone 4S.
458
    case 'armv7s': // iPad 4.
459
      return DarwinArch.armv7;
460
    case 'arm64':
461
    case 'arm64e': // iPhone XS/XS Max/XR and higher. arm64 runs on arm64e devices.
462
      return DarwinArch.arm64;
463 464
    case 'x86_64':
      return DarwinArch.x86_64;
465
  }
466
  throw Exception('Unsupported iOS arch name "$arch"');
467 468
}

469
String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch darwinArch}) {
470 471
  switch (platform) {
    case TargetPlatform.android_arm:
472
      return 'android-arm';
473 474
    case TargetPlatform.android_arm64:
      return 'android-arm64';
475
    case TargetPlatform.android_x64:
476
      return 'android-x64';
477
    case TargetPlatform.android_x86:
478
      return 'android-x86';
479
    case TargetPlatform.ios:
480 481 482
      if (darwinArch != null) {
        return 'ios-${getNameForDarwinArch(darwinArch)}';
      }
483
      return 'ios';
484
    case TargetPlatform.darwin_x64:
485
      return 'darwin-x64';
486
    case TargetPlatform.linux_x64:
487
      return 'linux-x64';
488
    case TargetPlatform.windows_x64:
489
      return 'windows-x64';
490 491 492 493
    case TargetPlatform.fuchsia_arm64:
      return 'fuchsia-arm64';
    case TargetPlatform.fuchsia_x64:
      return 'fuchsia-x64';
494 495
    case TargetPlatform.tester:
      return 'flutter-tester';
496 497
    case TargetPlatform.web_javascript:
      return 'web-javascript';
498 499
    case TargetPlatform.android:
      return 'android';
500 501
  }
  assert(false);
pq's avatar
pq committed
502
  return null;
503 504
}

505 506
TargetPlatform getTargetPlatformForName(String platform) {
  switch (platform) {
507 508
    case 'android':
      return TargetPlatform.android;
509 510
    case 'android-arm':
      return TargetPlatform.android_arm;
511 512
    case 'android-arm64':
      return TargetPlatform.android_arm64;
513 514 515 516
    case 'android-x64':
      return TargetPlatform.android_x64;
    case 'android-x86':
      return TargetPlatform.android_x86;
517 518 519 520
    case 'fuchsia-arm64':
      return TargetPlatform.fuchsia_arm64;
    case 'fuchsia-x64':
      return TargetPlatform.fuchsia_x64;
521 522 523
    case 'ios':
      return TargetPlatform.ios;
    case 'darwin-x64':
524
      return TargetPlatform.darwin_x64;
525
    case 'linux-x64':
526
      return TargetPlatform.linux_x64;
527
    case 'windows-x64':
528
      return TargetPlatform.windows_x64;
529 530
    case 'web-javascript':
      return TargetPlatform.web_javascript;
531
  }
pq's avatar
pq committed
532
  assert(platform != null);
533 534 535
  return null;
}

536 537 538 539 540 541 542 543 544 545 546
AndroidArch getAndroidArchForName(String platform) {
  switch (platform) {
    case 'android-arm':
      return AndroidArch.armeabi_v7a;
    case 'android-arm64':
      return AndroidArch.arm64_v8a;
    case 'android-x64':
      return AndroidArch.x86_64;
    case 'android-x86':
      return AndroidArch.x86;
  }
547
  throw Exception('Unsupported Android arch name "$platform"');
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
}

String getNameForAndroidArch(AndroidArch arch) {
  switch (arch) {
    case AndroidArch.armeabi_v7a:
      return 'armeabi-v7a';
    case AndroidArch.arm64_v8a:
      return 'arm64-v8a';
    case AndroidArch.x86_64:
      return 'x86_64';
    case AndroidArch.x86:
      return 'x86';
  }
  assert(false);
  return null;
}

String getPlatformNameForAndroidArch(AndroidArch arch) {
  switch (arch) {
    case AndroidArch.armeabi_v7a:
      return 'android-arm';
    case AndroidArch.arm64_v8a:
      return 'android-arm64';
    case AndroidArch.x86_64:
      return 'android-x64';
    case AndroidArch.x86:
      return 'android-x86';
  }
  assert(false);
  return null;
}

580 581 582 583 584 585 586 587 588 589 590 591
String fuchsiaArchForTargetPlatform(TargetPlatform targetPlatform) {
  switch (targetPlatform) {
    case TargetPlatform.fuchsia_arm64:
      return 'arm64';
    case TargetPlatform.fuchsia_x64:
      return 'x64';
    default:
      assert(false);
      return null;
  }
}

592
HostPlatform getCurrentHostPlatform() {
593
  if (globals.platform.isMacOS) {
594
    return HostPlatform.darwin_x64;
595
  }
596
  if (globals.platform.isLinux) {
597
    return HostPlatform.linux_x64;
598
  }
599
  if (globals.platform.isWindows) {
600
    return HostPlatform.windows_x64;
601
  }
602

603
  globals.printError('Unsupported host platform, defaulting to Linux');
604 605

  return HostPlatform.linux_x64;
606
}
607 608 609

/// Returns the top-level build output directory.
String getBuildDirectory() {
610 611
  // TODO(johnmccutchan): Stop calling this function as part of setting
  // up command line argument processing.
612
  if (context == null || globals.config == null) {
613
    return 'build';
614
  }
615

616 617
  final String buildDir = globals.config.getValue('build-dir') as String ?? 'build';
  if (globals.fs.path.isAbsolute(buildDir)) {
618
    throw Exception(
619
        'build-dir config setting in ${globals.config.configPath} must be relative');
620 621 622 623 624 625
  }
  return buildDir;
}

/// Returns the Android build output directory.
String getAndroidBuildDirectory() {
626
  // TODO(cbracken): move to android subdir.
627 628 629 630 631
  return getBuildDirectory();
}

/// Returns the AOT build output directory.
String getAotBuildDirectory() {
632
  return globals.fs.path.join(getBuildDirectory(), 'aot');
633 634 635 636
}

/// Returns the asset build output directory.
String getAssetBuildDirectory() {
637
  return globals.fs.path.join(getBuildDirectory(), 'flutter_assets');
638 639 640 641
}

/// Returns the iOS build output directory.
String getIosBuildDirectory() {
642
  return globals.fs.path.join(getBuildDirectory(), 'ios');
643
}
644

645 646
/// Returns the macOS build output directory.
String getMacOSBuildDirectory() {
647
  return globals.fs.path.join(getBuildDirectory(), 'macos');
648 649
}

650 651
/// Returns the web build output directory.
String getWebBuildDirectory() {
652
  return globals.fs.path.join(getBuildDirectory(), 'web');
653 654
}

655
/// Returns the Linux build output directory.
656
String getLinuxBuildDirectory() {
657
  return globals.fs.path.join(getBuildDirectory(), 'linux');
658 659
}

660 661
/// Returns the Windows build output directory.
String getWindowsBuildDirectory() {
662
  return globals.fs.path.join(getBuildDirectory(), 'windows');
663 664
}

665 666
/// Returns the Fuchsia build output directory.
String getFuchsiaBuildDirectory() {
667
  return globals.fs.path.join(getBuildDirectory(), 'fuchsia');
668
}
669 670 671 672 673 674 675 676 677 678 679 680

/// Defines specified via the `--dart-define` command-line option.
///
/// These values are URI-encoded and then combined into a comma-separated string.
const String kDartDefines = 'DartDefines';

/// Encode a List of dart defines in a URI string.
String encodeDartDefines(List<String> defines) {
  return defines.map(Uri.encodeComponent).join(',');
}

/// Dart defines are encoded inside [environmentDefines] as a comma-separated list.
681 682
List<String> decodeDartDefines(Map<String, String> environmentDefines, String key) {
  if (!environmentDefines.containsKey(key) || environmentDefines[key].isEmpty) {
683 684
    return const <String>[];
  }
685
  return environmentDefines[key]
686 687 688 689 690
    .split(',')
    .map<Object>(Uri.decodeComponent)
    .cast<String>()
    .toList();
}