Refactor BuildMode into class, add jit_release configuration (#42476)

This commit is contained in:
Jonah Williams 2019-10-28 09:37:29 -07:00 committed by GitHub
parent 84299aeb16
commit ab260bacd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 22 deletions

View file

@ -113,35 +113,78 @@ class AndroidBuildInfo {
final Iterable<AndroidArch> targetArchs;
}
/// The type of build.
enum BuildMode {
debug,
profile,
release,
}
/// A summary of the compilation strategy used for Dart.
class BuildMode {
const BuildMode._(this.name);
const List<String> _kBuildModes = <String>[
'debug',
'profile',
'release',
];
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);
/// Whether this mode is using the jit runtime.
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;
}
/// Return the name for the build mode, or "any" if null.
String getNameForBuildMode(BuildMode buildMode) {
return _kBuildModes[buildMode.index];
return buildMode.name;
}
/// Returns the [BuildMode] for a particular `name`.
BuildMode getBuildModeForName(String name) {
switch (name) {
case 'debug':
return BuildMode.debug;
case 'profile':
return BuildMode.profile;
case 'release':
return BuildMode.release;
}
return null;
return BuildMode.fromName(name);
}
String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String buildNumber) {

View file

@ -232,7 +232,6 @@ class KernelSnapshot extends Target {
}
}
/// Supports compiling a dart kernel file to an ELF binary.
abstract class AotElfBase extends Target {
const AotElfBase();

View file

@ -53,5 +53,29 @@ void main() {
buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, 'abc+-');
expect(buildName, 'abc+-');
});
test('build mode configuration is correct', () {
expect(BuildMode.debug.isRelease, false);
expect(BuildMode.debug.isPrecompiled, false);
expect(BuildMode.debug.isJit, true);
expect(BuildMode.profile.isRelease, false);
expect(BuildMode.profile.isPrecompiled, true);
expect(BuildMode.profile.isJit, false);
expect(BuildMode.release.isRelease, true);
expect(BuildMode.release.isPrecompiled, true);
expect(BuildMode.release.isJit, false);
expect(BuildMode.jitRelease.isRelease, true);
expect(BuildMode.jitRelease.isPrecompiled, false);
expect(BuildMode.jitRelease.isJit, true);
expect(BuildMode.fromName('debug'), BuildMode.debug);
expect(BuildMode.fromName('profile'), BuildMode.profile);
expect(BuildMode.fromName('jit_release'), BuildMode.jitRelease);
expect(BuildMode.fromName('release'), BuildMode.release);
expect(() => BuildMode.fromName('foo'), throwsA(isInstanceOf<ArgumentError>()));
});
});
}