blob: fefa80c9ff70231313f61f716a252e325e2684cd [file] [log] [blame]
Adam Barthbdd20662015-10-11 19:42:50 -07001// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
John McCutchan0b737ac2016-11-29 07:54:20 -08005import 'base/context.dart';
Michael Goderbauer5e54fd52017-02-13 17:45:50 -08006import 'base/file_system.dart';
Todd Volkert417c2f22017-01-25 16:06:41 -08007import 'base/platform.dart';
Devon Carewf132aca2016-04-15 21:08:03 -07008import 'base/utils.dart';
Devon Carewd5a6fce2016-02-17 00:59:56 -08009import 'globals.dart';
Adam Barth94b472f2015-10-30 22:57:39 -070010
Mikkel Nygaard Ravn9496e6d2017-08-23 10:55:35 +020011/// Information about a build to be performed or used.
12class BuildInfo {
Alexandre Ardhuinbfa1d252019-03-23 00:02:21 +010013 const BuildInfo(
14 this.mode,
15 this.flavor, {
Alexandre Ardhuin09276be2018-06-05 08:50:40 +020016 this.trackWidgetCreation = false,
Yegor905f9ac2018-03-02 15:45:55 -080017 this.extraFrontEndOptions,
18 this.extraGenSnapshotOptions,
Alexander Aprelev43284d72018-03-17 12:47:40 -070019 this.fileSystemRoots,
20 this.fileSystemScheme,
Ralph Bergmann89570732018-03-29 14:58:31 +020021 this.buildNumber,
22 this.buildName,
Yegor905f9ac2018-03-02 15:45:55 -080023 });
Mikkel Nygaard Ravn9496e6d2017-08-23 10:55:35 +020024
25 final BuildMode mode;
Yegor905f9ac2018-03-02 15:45:55 -080026
Mikkel Nygaard Ravn9496e6d2017-08-23 10:55:35 +020027 /// Represents a custom Android product flavor or an Xcode scheme, null for
28 /// using the default.
29 ///
30 /// If not null, the Gradle build task will be `assembleFlavorMode` (e.g.
31 /// `assemblePaidRelease`), and the Xcode build configuration will be
32 /// Mode-Flavor (e.g. Release-Paid).
33 final String flavor;
34
Alexander Aprelev43284d72018-03-17 12:47:40 -070035 final List<String> fileSystemRoots;
36 final String fileSystemScheme;
37
Jacob Richman2c05eca2018-02-12 10:44:31 -080038 /// Whether the build should track widget creation locations.
39 final bool trackWidgetCreation;
40
Alexander Markov7153dea2017-10-03 12:55:53 -070041 /// Extra command-line options for front-end.
42 final String extraFrontEndOptions;
43
44 /// Extra command-line options for gen_snapshot.
45 final String extraGenSnapshotOptions;
46
Ralph Bergmann89570732018-03-29 14:58:31 +020047 /// Internal version number (not displayed to users).
48 /// Each build must have a unique number to differentiate it from previous builds.
49 /// It is used to determine whether one build is more recent than another, with higher numbers indicating more recent build.
50 /// On Android it is used as versionCode.
51 /// On Xcode builds it is used as CFBundleVersion.
KyleWong4b4a94002019-02-13 23:48:03 +080052 final String buildNumber;
Ralph Bergmann89570732018-03-29 14:58:31 +020053
54 /// A "x.y.z" string used as the version number shown to users.
55 /// For each new version of your app, you will provide a version number to differentiate it from previous versions.
56 /// On Android it is used as versionName.
57 /// On Xcode builds it is used as CFBundleShortVersionString,
58 final String buildName;
59
Alexandre Ardhuineda03e22018-08-02 12:02:32 +020060 static const BuildInfo debug = BuildInfo(BuildMode.debug, null);
61 static const BuildInfo profile = BuildInfo(BuildMode.profile, null);
62 static const BuildInfo release = BuildInfo(BuildMode.release, null);
Mikkel Nygaard Ravn9496e6d2017-08-23 10:55:35 +020063
64 /// Returns whether a debug build is requested.
65 ///
66 /// Exactly one of [isDebug], [isProfile], or [isRelease] is true.
67 bool get isDebug => mode == BuildMode.debug;
68
69 /// Returns whether a profile build is requested.
70 ///
71 /// Exactly one of [isDebug], [isProfile], or [isRelease] is true.
Jonah Williams73330e12019-06-18 15:22:04 -070072 bool get isProfile => mode == BuildMode.profile;
Mikkel Nygaard Ravn9496e6d2017-08-23 10:55:35 +020073
74 /// Returns whether a release build is requested.
75 ///
76 /// Exactly one of [isDebug], [isProfile], or [isRelease] is true.
Jonah Williams73330e12019-06-18 15:22:04 -070077 bool get isRelease => mode == BuildMode.release;
Stanislav Baranov55f3da72018-12-19 16:27:47 -080078
Mikkel Nygaard Ravn9496e6d2017-08-23 10:55:35 +020079 bool get usesAot => isAotBuildMode(mode);
80 bool get supportsEmulator => isEmulatorBuildMode(mode);
81 bool get supportsSimulator => isEmulatorBuildMode(mode);
82 String get modeName => getModeName(mode);
Stanislav Baranov585e2312019-01-10 16:07:50 -080083 String get friendlyModeName => getFriendlyModeName(mode);
Emmanuel Garcia8627ff42019-06-10 13:16:09 -070084}
Jason Simmonsd5149d42018-02-01 15:14:48 -080085
Emmanuel Garcia8627ff42019-06-10 13:16:09 -070086/// Information about an Android build to be performed or used.
87class AndroidBuildInfo {
88 const AndroidBuildInfo(
89 this.buildInfo, {
90 this.targetArchs = const <AndroidArch>[
91 AndroidArch.armeabi_v7a,
92 AndroidArch.arm64_v8a,
93 ],
94 this.splitPerAbi = false,
Emmanuel Garcia2c857b92019-09-13 19:06:40 -070095 this.shrink = false,
Emmanuel Garcia8627ff42019-06-10 13:16:09 -070096 });
97
98 // The build info containing the mode and flavor.
99 final BuildInfo buildInfo;
100
101 /// Whether to split the shared library per ABI.
102 ///
103 /// When this is false, multiple ABIs will be contained within one primary
104 /// build artifact. When this is true, multiple build artifacts (one per ABI)
105 /// will be produced.
106 final bool splitPerAbi;
107
Emmanuel Garcia2c857b92019-09-13 19:06:40 -0700108 /// Whether to enable code shrinking on release mode.
109 final bool shrink;
Emmanuel Garciaf098de12019-09-10 17:22:55 -0700110
Emmanuel Garcia8627ff42019-06-10 13:16:09 -0700111 /// The target platforms for the build.
112 final Iterable<AndroidArch> targetArchs;
Adam Barthbdd20662015-10-11 19:42:50 -0700113}
114
Stanislav Baranov393f9272018-08-16 08:43:41 -0700115/// The type of build.
Devon Carew1c0a9662016-04-18 16:41:15 -0700116enum BuildMode {
117 debug,
Jason Simmons07951ee2016-04-25 13:36:31 -0700118 profile,
Stanislav Baranov393f9272018-08-16 08:43:41 -0700119 release,
Devon Carew8849cd62016-04-12 09:21:17 -0700120}
121
Jonah Williamse91b98a2019-07-11 16:53:17 -0700122const List<String> _kBuildModes = <String>[
123 'debug',
124 'profile',
125 'release',
Jonah Williamse91b98a2019-07-11 16:53:17 -0700126];
127
128/// Return the name for the build mode, or "any" if null.
129String getNameForBuildMode(BuildMode buildMode) {
130 return _kBuildModes[buildMode.index];
131}
132
133/// Returns the [BuildMode] for a particular `name`.
134BuildMode getBuildModeForName(String name) {
135 switch (name) {
136 case 'debug':
137 return BuildMode.debug;
138 case 'profile':
139 return BuildMode.profile;
140 case 'release':
141 return BuildMode.release;
142 }
143 return null;
144}
145
KyleWong4b4a94002019-02-13 23:48:03 +0800146String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String buildNumber) {
147 if (buildNumber == null) {
148 return null;
149 }
150 if (targetPlatform == TargetPlatform.ios ||
151 targetPlatform == TargetPlatform.darwin_x64) {
152 // See CFBundleVersion at https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
153 final RegExp disallowed = RegExp(r'[^\d\.]');
154 String tmpBuildNumber = buildNumber.replaceAll(disallowed, '');
Jenn Magder9a68b0d2019-09-17 17:07:41 -0700155 if (tmpBuildNumber.isEmpty) {
156 return null;
157 }
KyleWong4b4a94002019-02-13 23:48:03 +0800158 final List<String> segments = tmpBuildNumber
159 .split('.')
160 .where((String segment) => segment.isNotEmpty)
161 .toList();
162 if (segments.isEmpty) {
163 segments.add('0');
164 }
165 tmpBuildNumber = segments.join('.');
166 if (tmpBuildNumber != buildNumber) {
167 printTrace('Invalid build-number: $buildNumber for iOS/macOS, overridden by $tmpBuildNumber.\n'
168 'See CFBundleVersion at https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html');
169 }
170 return tmpBuildNumber;
171 }
172 if (targetPlatform == TargetPlatform.android_arm ||
173 targetPlatform == TargetPlatform.android_arm64 ||
174 targetPlatform == TargetPlatform.android_x64 ||
175 targetPlatform == TargetPlatform.android_x86) {
176 // See versionCode at https://developer.android.com/studio/publish/versioning
177 final RegExp disallowed = RegExp(r'[^\d]');
178 String tmpBuildNumberStr = buildNumber.replaceAll(disallowed, '');
179 int tmpBuildNumberInt = int.tryParse(tmpBuildNumberStr) ?? 0;
180 if (tmpBuildNumberInt < 1) {
181 tmpBuildNumberInt = 1;
182 }
183 tmpBuildNumberStr = tmpBuildNumberInt.toString();
184 if (tmpBuildNumberStr != buildNumber) {
185 printTrace('Invalid build-number: $buildNumber for Android, overridden by $tmpBuildNumberStr.\n'
186 'See versionCode at https://developer.android.com/studio/publish/versioning');
187 }
188 return tmpBuildNumberStr;
189 }
190 return buildNumber;
191}
192
193String validatedBuildNameForPlatform(TargetPlatform targetPlatform, String buildName) {
194 if (buildName == null) {
195 return null;
196 }
197 if (targetPlatform == TargetPlatform.ios ||
198 targetPlatform == TargetPlatform.darwin_x64) {
199 // See CFBundleShortVersionString at https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
200 final RegExp disallowed = RegExp(r'[^\d\.]');
201 String tmpBuildName = buildName.replaceAll(disallowed, '');
Jenn Magder9a68b0d2019-09-17 17:07:41 -0700202 if (tmpBuildName.isEmpty) {
203 return null;
204 }
KyleWong4b4a94002019-02-13 23:48:03 +0800205 final List<String> segments = tmpBuildName
206 .split('.')
207 .where((String segment) => segment.isNotEmpty)
208 .toList();
209 while (segments.length < 3) {
210 segments.add('0');
211 }
212 tmpBuildName = segments.join('.');
213 if (tmpBuildName != buildName) {
214 printTrace('Invalid build-name: $buildName for iOS/macOS, overridden by $tmpBuildName.\n'
215 'See CFBundleShortVersionString at https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html');
216 }
217 return tmpBuildName;
218 }
219 if (targetPlatform == TargetPlatform.android_arm ||
220 targetPlatform == TargetPlatform.android_arm64 ||
221 targetPlatform == TargetPlatform.android_x64 ||
222 targetPlatform == TargetPlatform.android_x86) {
223 // See versionName at https://developer.android.com/studio/publish/versioning
224 return buildName;
225 }
226 return buildName;
227}
228
Devon Carew1c0a9662016-04-18 16:41:15 -0700229String getModeName(BuildMode mode) => getEnumName(mode);
Devon Carew8849cd62016-04-12 09:21:17 -0700230
Stanislav Baranov585e2312019-01-10 16:07:50 -0800231String getFriendlyModeName(BuildMode mode) {
232 return snakeCase(getModeName(mode)).replaceAll('_', ' ');
233}
234
Jason Simmonsf161f232016-05-02 11:40:32 -0700235// Returns true if the selected build mode uses ahead-of-time compilation.
236bool isAotBuildMode(BuildMode mode) {
237 return mode == BuildMode.profile || mode == BuildMode.release;
238}
239
Devon Carew9cfa9662016-05-26 09:14:51 -0700240// Returns true if the given build mode can be used on emulators / simulators.
Stanislav Baranoveb8219e2019-01-17 14:21:35 -0800241bool isEmulatorBuildMode(BuildMode mode) {
Jonah Williams73330e12019-06-18 15:22:04 -0700242 return mode == BuildMode.debug;
Stanislav Baranoveb8219e2019-01-17 14:21:35 -0800243}
Devon Carew9cfa9662016-05-26 09:14:51 -0700244
Adam Barth94b472f2015-10-30 22:57:39 -0700245enum HostPlatform {
Devon Carewf132aca2016-04-15 21:08:03 -0700246 darwin_x64,
247 linux_x64,
Michael Goderbauer9f28b4f2017-01-26 17:04:53 -0800248 windows_x64,
Devon Carewf132aca2016-04-15 21:08:03 -0700249}
250
251String getNameForHostPlatform(HostPlatform platform) {
Chinmay Garde29b8c802016-05-11 14:54:51 -0700252 switch (platform) {
253 case HostPlatform.darwin_x64:
Chinmay Gardea21dedc2016-05-13 17:03:03 -0700254 return 'darwin-x64';
Chinmay Garde29b8c802016-05-11 14:54:51 -0700255 case HostPlatform.linux_x64:
Chinmay Gardea21dedc2016-05-13 17:03:03 -0700256 return 'linux-x64';
Michael Goderbauer9f28b4f2017-01-26 17:04:53 -0800257 case HostPlatform.windows_x64:
258 return 'windows-x64';
Chinmay Garde29b8c802016-05-11 14:54:51 -0700259 }
260 assert(false);
pq7a955482016-06-14 12:13:56 -0700261 return null;
Adam Barthbdd20662015-10-11 19:42:50 -0700262}
263
Adam Barth94b472f2015-10-30 22:57:39 -0700264enum TargetPlatform {
Devon Carewe939b152016-03-12 11:08:21 -0800265 android_arm,
Jason Simmonsd5149d42018-02-01 15:14:48 -0800266 android_arm64,
Devon Carew1311ae62016-04-08 14:04:46 -0700267 android_x64,
Jason Simmons4d0e6982016-05-05 16:04:22 -0700268 android_x86,
Chinmay Gardec8377d72016-03-21 14:41:26 -0700269 ios,
Devon Carewe939b152016-03-12 11:08:21 -0800270 darwin_x64,
Michael Goderbauerd579d582017-03-02 10:57:27 -0800271 linux_x64,
Zachary Andersonb6ba37d2017-03-14 11:12:19 -0700272 windows_x64,
273 fuchsia,
Konstantin Scheglov38970f52018-04-10 09:37:16 -0700274 tester,
Jonah Williams83986ac2019-06-03 23:19:42 -0700275 web_javascript,
Adam Barth94b472f2015-10-30 22:57:39 -0700276}
277
Jonah Williams1df165e2019-08-15 17:38:35 -0700278/// iOS and macOS target device architecture.
Chris Bracken849676f2018-05-06 18:43:07 -0700279//
280// TODO(cbracken): split TargetPlatform.ios into ios_armv7, ios_arm64.
Jonah Williams1df165e2019-08-15 17:38:35 -0700281enum DarwinArch {
Chris Bracken849676f2018-05-06 18:43:07 -0700282 armv7,
283 arm64,
Jonah Williams1df165e2019-08-15 17:38:35 -0700284 x86_64,
Chris Bracken849676f2018-05-06 18:43:07 -0700285}
286
Emmanuel Garcia8627ff42019-06-10 13:16:09 -0700287enum AndroidArch {
288 armeabi_v7a,
289 arm64_v8a,
290 x86,
291 x86_64,
292}
293
Chris Bracken849676f2018-05-06 18:43:07 -0700294/// The default set of iOS device architectures to build for.
Jonah Williams1df165e2019-08-15 17:38:35 -0700295const List<DarwinArch> defaultIOSArchs = <DarwinArch>[
296 DarwinArch.arm64,
Chris Bracken849676f2018-05-06 18:43:07 -0700297];
298
Jonah Williams1df165e2019-08-15 17:38:35 -0700299String getNameForDarwinArch(DarwinArch arch) {
Chris Bracken849676f2018-05-06 18:43:07 -0700300 switch (arch) {
Jonah Williams1df165e2019-08-15 17:38:35 -0700301 case DarwinArch.armv7:
Chris Bracken849676f2018-05-06 18:43:07 -0700302 return 'armv7';
Jonah Williams1df165e2019-08-15 17:38:35 -0700303 case DarwinArch.arm64:
Chris Bracken849676f2018-05-06 18:43:07 -0700304 return 'arm64';
Jonah Williams1df165e2019-08-15 17:38:35 -0700305 case DarwinArch.x86_64:
306 return 'x86_64';
Chris Bracken849676f2018-05-06 18:43:07 -0700307 }
308 assert(false);
309 return null;
310}
311
Jonah Williams1df165e2019-08-15 17:38:35 -0700312DarwinArch getIOSArchForName(String arch) {
Chris Bracken849676f2018-05-06 18:43:07 -0700313 switch (arch) {
314 case 'armv7':
Jonah Williams1df165e2019-08-15 17:38:35 -0700315 return DarwinArch.armv7;
Chris Bracken849676f2018-05-06 18:43:07 -0700316 case 'arm64':
Jonah Williams1df165e2019-08-15 17:38:35 -0700317 return DarwinArch.arm64;
Chris Bracken849676f2018-05-06 18:43:07 -0700318 }
319 assert(false);
320 return null;
321}
322
Devon Carewf132aca2016-04-15 21:08:03 -0700323String getNameForTargetPlatform(TargetPlatform platform) {
Chinmay Garde29b8c802016-05-11 14:54:51 -0700324 switch (platform) {
325 case TargetPlatform.android_arm:
Chinmay Gardea21dedc2016-05-13 17:03:03 -0700326 return 'android-arm';
Jason Simmonsd5149d42018-02-01 15:14:48 -0800327 case TargetPlatform.android_arm64:
328 return 'android-arm64';
Chinmay Garde29b8c802016-05-11 14:54:51 -0700329 case TargetPlatform.android_x64:
Chinmay Gardea21dedc2016-05-13 17:03:03 -0700330 return 'android-x64';
Chinmay Garde29b8c802016-05-11 14:54:51 -0700331 case TargetPlatform.android_x86:
Chinmay Gardea21dedc2016-05-13 17:03:03 -0700332 return 'android-x86';
Chinmay Garde29b8c802016-05-11 14:54:51 -0700333 case TargetPlatform.ios:
Chinmay Garde66fee3a2016-05-23 12:58:42 -0700334 return 'ios';
Chinmay Garde29b8c802016-05-11 14:54:51 -0700335 case TargetPlatform.darwin_x64:
Chinmay Gardea21dedc2016-05-13 17:03:03 -0700336 return 'darwin-x64';
Chinmay Garde29b8c802016-05-11 14:54:51 -0700337 case TargetPlatform.linux_x64:
Chinmay Gardea21dedc2016-05-13 17:03:03 -0700338 return 'linux-x64';
Michael Goderbauerd579d582017-03-02 10:57:27 -0800339 case TargetPlatform.windows_x64:
340 return 'windows-x64';
Zachary Andersonb6ba37d2017-03-14 11:12:19 -0700341 case TargetPlatform.fuchsia:
342 return 'fuchsia';
Konstantin Scheglov38970f52018-04-10 09:37:16 -0700343 case TargetPlatform.tester:
344 return 'flutter-tester';
Jonah Williams83986ac2019-06-03 23:19:42 -0700345 case TargetPlatform.web_javascript:
346 return 'web-javascript';
Chinmay Garde29b8c802016-05-11 14:54:51 -0700347 }
348 assert(false);
pq7a955482016-06-14 12:13:56 -0700349 return null;
Devon Carewf132aca2016-04-15 21:08:03 -0700350}
351
Adam Barthcb7a6902016-05-24 11:21:07 -0700352TargetPlatform getTargetPlatformForName(String platform) {
353 switch (platform) {
354 case 'android-arm':
355 return TargetPlatform.android_arm;
Jason Simmonsd5149d42018-02-01 15:14:48 -0800356 case 'android-arm64':
357 return TargetPlatform.android_arm64;
Adam Barthcb7a6902016-05-24 11:21:07 -0700358 case 'android-x64':
359 return TargetPlatform.android_x64;
360 case 'android-x86':
361 return TargetPlatform.android_x86;
362 case 'ios':
363 return TargetPlatform.ios;
364 case 'darwin-x64':
365 return TargetPlatform.darwin_x64;
366 case 'linux-x64':
367 return TargetPlatform.linux_x64;
stuartmorgan4e1bfca2019-05-15 19:32:47 -0400368 case 'windows-x64':
369 return TargetPlatform.windows_x64;
Jonah Williams83986ac2019-06-03 23:19:42 -0700370 case 'web-javascript':
371 return TargetPlatform.web_javascript;
Adam Barthcb7a6902016-05-24 11:21:07 -0700372 }
pqf5a4e632016-06-14 15:19:14 -0700373 assert(platform != null);
Adam Barthcb7a6902016-05-24 11:21:07 -0700374 return null;
375}
376
Emmanuel Garcia8627ff42019-06-10 13:16:09 -0700377AndroidArch getAndroidArchForName(String platform) {
378 switch (platform) {
379 case 'android-arm':
380 return AndroidArch.armeabi_v7a;
381 case 'android-arm64':
382 return AndroidArch.arm64_v8a;
383 case 'android-x64':
384 return AndroidArch.x86_64;
385 case 'android-x86':
386 return AndroidArch.x86;
387 }
388 assert(false);
389 return null;
390}
391
392String getNameForAndroidArch(AndroidArch arch) {
393 switch (arch) {
394 case AndroidArch.armeabi_v7a:
395 return 'armeabi-v7a';
396 case AndroidArch.arm64_v8a:
397 return 'arm64-v8a';
398 case AndroidArch.x86_64:
399 return 'x86_64';
400 case AndroidArch.x86:
401 return 'x86';
402 }
403 assert(false);
404 return null;
405}
406
407String getPlatformNameForAndroidArch(AndroidArch arch) {
408 switch (arch) {
409 case AndroidArch.armeabi_v7a:
410 return 'android-arm';
411 case AndroidArch.arm64_v8a:
412 return 'android-arm64';
413 case AndroidArch.x86_64:
414 return 'android-x64';
415 case AndroidArch.x86:
416 return 'android-x86';
417 }
418 assert(false);
419 return null;
420}
421
Adam Barth94b472f2015-10-30 22:57:39 -0700422HostPlatform getCurrentHostPlatform() {
Zachary Andersone2340c62019-09-13 14:51:35 -0700423 if (platform.isMacOS) {
Devon Carewf132aca2016-04-15 21:08:03 -0700424 return HostPlatform.darwin_x64;
Zachary Andersone2340c62019-09-13 14:51:35 -0700425 }
426 if (platform.isLinux) {
Devon Carewf132aca2016-04-15 21:08:03 -0700427 return HostPlatform.linux_x64;
Zachary Andersone2340c62019-09-13 14:51:35 -0700428 }
429 if (platform.isWindows) {
Michael Goderbauer9f28b4f2017-01-26 17:04:53 -0800430 return HostPlatform.windows_x64;
Zachary Andersone2340c62019-09-13 14:51:35 -0700431 }
Devon Carewf132aca2016-04-15 21:08:03 -0700432
Devon Carewd7fbf532016-01-27 22:38:57 -0800433 printError('Unsupported host platform, defaulting to Linux');
Devon Carewf132aca2016-04-15 21:08:03 -0700434
435 return HostPlatform.linux_x64;
Adam Barth94b472f2015-10-30 22:57:39 -0700436}
Chris Brackenb5f763b2016-08-25 16:38:19 -0700437
438/// Returns the top-level build output directory.
439String getBuildDirectory() {
John McCutchan0b737ac2016-11-29 07:54:20 -0800440 // TODO(johnmccutchan): Stop calling this function as part of setting
441 // up command line argument processing.
Zachary Andersone2340c62019-09-13 14:51:35 -0700442 if (context == null || config == null) {
John McCutchan0b737ac2016-11-29 07:54:20 -0800443 return 'build';
Zachary Andersone2340c62019-09-13 14:51:35 -0700444 }
John McCutchan0b737ac2016-11-29 07:54:20 -0800445
Chris Bracken7a093162017-03-03 17:50:46 -0800446 final String buildDir = config.getValue('build-dir') ?? 'build';
Michael Goderbauer5e54fd52017-02-13 17:45:50 -0800447 if (fs.path.isAbsolute(buildDir)) {
Alexandre Ardhuind927c932018-09-12 08:29:29 +0200448 throw Exception(
Chris Brackenb5f763b2016-08-25 16:38:19 -0700449 'build-dir config setting in ${config.configPath} must be relative');
450 }
451 return buildDir;
452}
453
454/// Returns the Android build output directory.
455String getAndroidBuildDirectory() {
Ian Hicksonb7261582018-08-21 14:02:11 -0700456 // TODO(cbracken): move to android subdir.
Chris Brackenb5f763b2016-08-25 16:38:19 -0700457 return getBuildDirectory();
458}
459
460/// Returns the AOT build output directory.
461String getAotBuildDirectory() {
Michael Goderbauer5e54fd52017-02-13 17:45:50 -0800462 return fs.path.join(getBuildDirectory(), 'aot');
Chris Brackenb5f763b2016-08-25 16:38:19 -0700463}
464
465/// Returns the asset build output directory.
466String getAssetBuildDirectory() {
Sarah Zakarias5e18c072017-12-14 17:27:25 +0100467 return fs.path.join(getBuildDirectory(), 'flutter_assets');
Chris Brackenb5f763b2016-08-25 16:38:19 -0700468}
469
470/// Returns the iOS build output directory.
471String getIosBuildDirectory() {
Michael Goderbauer5e54fd52017-02-13 17:45:50 -0800472 return fs.path.join(getBuildDirectory(), 'ios');
Chris Brackenb5f763b2016-08-25 16:38:19 -0700473}
Alexander Aprelev9ae893b2017-11-10 10:09:37 -0800474
Jonah Williams7f959d82019-04-22 13:51:00 -0700475/// Returns the macOS build output directory.
476String getMacOSBuildDirectory() {
477 return fs.path.join(getBuildDirectory(), 'macos');
478}
479
Jonah Williams9bc56562019-02-14 22:42:30 -0800480/// Returns the web build output directory.
481String getWebBuildDirectory() {
482 return fs.path.join(getBuildDirectory(), 'web');
483}
484
Zachary Anderson8841afe2019-05-14 10:59:23 -0700485/// Returns the Linux build output directory.
Jonah Williams37c73e72019-04-24 13:34:56 -0700486String getLinuxBuildDirectory() {
487 return fs.path.join(getBuildDirectory(), 'linux');
488}
489
stuartmorgan4e1bfca2019-05-15 19:32:47 -0400490/// Returns the Windows build output directory.
491String getWindowsBuildDirectory() {
492 return fs.path.join(getBuildDirectory(), 'windows');
493}
494
Zachary Anderson8841afe2019-05-14 10:59:23 -0700495/// Returns the Fuchsia build output directory.
496String getFuchsiaBuildDirectory() {
497 return fs.path.join(getBuildDirectory(), 'fuchsia');
498}