runDartCompiler method
void
runDartCompiler(
- DartScript script, {
- required String pathToExe,
- Progress? progress,
- String? workingDirectory,
Run the 'dart compiler' command.
script
is the path to the dcli script we are compiling.
pathToExe
is the path (including the filename) to write the
compiled ex to .
If workingDirectory
is not passed then the current working directory is
used. The workingDirectory
should contain the pubspec.yaml that is used
to compile the script.
Implementation
void runDartCompiler(
DartScript script, {
required String pathToExe,
Progress? progress,
String? workingDirectory,
}) {
final runArgs = <String>[];
workingDirectory ??= script.pathToScriptDirectory;
RunnableProcess process;
if (useDartCommand) {
/// use dart compile exe
runArgs
..add('compile')
..add('exe')
..add(script.pathToScript)
..add('--output=$pathToExe');
process = RunnableProcess.fromCommandArgs(
dartExeName,
runArgs,
workingDirectory: script.pathToScriptDirectory,
);
} else {
if (pathToDartToNativeExe == null) {
throw DCliException(
'Unable to compile as the dart2native executable '
'not found on your path.',
);
}
/// use old dart2native
runArgs
..add(script.pathToScript)
..add('--output=$pathToExe');
process = RunnableProcess.fromCommandArgs(
pathToDartToNativeExe!,
runArgs,
workingDirectory: workingDirectory,
);
}
process
..start(extensionSearch: false)
..processUntilExit(progress, nothrow: false);
}