planRun function
The steps that compile (if needed) and run the Dart program script on
target, one of runTargets, passing it arguments.
Compiled files go to outputDir. Programs compiled for the web get no
command-line arguments, so js and wasm pass arguments as the
microbench.args define, which runMain reads.
Throws:
- ArgumentError for an unknown
target.
Implementation
List<RunStep> planRun(
String script,
String target, {
List<String> arguments = const [],
String outputDir = 'build/microbench',
}) {
final dart = Platform.resolvedExecutable;
var name = script.split(RegExp(r'[\\/]')).last;
if (name.endsWith('.dart')) name = name.substring(0, name.length - 5);
final base = '$outputDir/$name';
final define = '-Dmicrobench.args=${jsonEncode(arguments)}';
switch (target) {
case 'jit':
return [
RunStep(dart, ['run', script, ...arguments])
];
case 'aot':
final exe = Platform.isWindows ? '$base.exe' : base;
return [
RunStep(dart, ['compile', 'exe', script, '-o', exe]),
RunStep(File(exe).absolute.path, arguments),
];
case 'js':
return [
RunStep(
dart, ['compile', 'js', '-O2', define, '-o', '$base.js', script]),
RunStep('node', ['$base.js']),
];
case 'wasm':
return [
RunStep.write('$base.run.mjs', _wasmRunner(name)),
RunStep(dart,
['compile', 'wasm', '-O2', define, '-o', '$base.wasm', script]),
RunStep('node', ['$base.run.mjs']),
];
}
throw ArgumentError.value(target, 'target', 'not one of $runTargets');
}