blob: 77a637619c2a26a3bfe5bfce4fb6272e9ebd7503 [file] [log] [blame]
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// All the Dart compilers supported by the test runner.
class Compiler {
/// The production Dart to Javascript compiler (whole world, optimizing).
static const Compiler dart2js = Compiler._('Dart2Js', 'dart2js');
/// Experimental Dart to Wasm compiler.
static const Compiler dart2wasm = Compiler._('Dart2WASM', 'dart2wasm');
/// Compiles dart code to a native executable.
static const Compiler exe = Compiler._('Exe', 'exe');
/// The standard compiler for vm tests, compiles tests to kernel before
/// running them on the VM.
static const Compiler kernel = Compiler._('Kernel', 'kernel');
/// Runs tests directly from source, with no precompilation.
static const Compiler source = Compiler._('Source', 'source');
/// The compilers that are supported by the test runner by default.
static const List<Compiler> builtIn = [
Compiler.dart2js,
Compiler.dart2wasm,
Compiler.exe,
Compiler.kernel,
Compiler.source,
];
/// The human-friendly name of the compiler.
final String name;
/// The identifier used to look up the compiler.
final String identifier;
const Compiler._(this.name, this.identifier);
/// Converts a JSON-safe representation generated by [serialize] back into a
/// [Compiler].
///
/// Note that custom [Compiler] implementations are not supported.
factory Compiler.deserialize(Object serialized) => builtIn
.firstWhere((compiler) => compiler.identifier == serialized as String);
/// Converts [this] into a JSON-safe object that can be converted back to a
/// [Compiler] using [Compiler.deserialize].
Object serialize() => identifier;
@override
String toString() => name;
}