mirror of
https://github.com/encounter/engine.git
synced 2026-03-30 11:09:55 -07:00
Add an option '--depfile' to produce ninja-style depfile for the generated kernel. (#4704)
* Add an option '--depfile' to produce ninja-style depfile for the generated kernel file. * Use [program.uriToSource] as a source of dependencies.
This commit is contained in:
committed by
GitHub
parent
3b4d0378f3
commit
86ec3db218
@@ -57,6 +57,8 @@ ArgParser _argParser = new ArgParser(allowTrailingOptions: true)
|
||||
..addOption('output-incremental-dill',
|
||||
help: 'Output path for the generated incremental dill',
|
||||
defaultsTo: null)
|
||||
..addOption('depfile',
|
||||
help: 'Path to output Ninja depfile. Only used in batch mode.')
|
||||
..addOption('packages',
|
||||
help: '.packages file to use for compilation',
|
||||
defaultsTo: null)
|
||||
@@ -209,6 +211,12 @@ class _FrontendCompiler implements CompilerInterface {
|
||||
printer.writeProgramFile(program);
|
||||
await sink.close();
|
||||
_outputStream.writeln('$boundaryKey $_kernelBinaryFilename');
|
||||
|
||||
final String depfile = options['depfile'];
|
||||
if (depfile != null) {
|
||||
await _writeDepfile(program, _kernelBinaryFilename, depfile);
|
||||
}
|
||||
|
||||
_kernelBinaryFilename = _kernelBinaryFilenameIncremental;
|
||||
} else
|
||||
_outputStream.writeln(boundaryKey);
|
||||
@@ -324,6 +332,23 @@ class _FrontendCompiler implements CompilerInterface {
|
||||
}
|
||||
}
|
||||
|
||||
String _escapePath(String path) {
|
||||
return path.replaceAll(r'\', r'\\').replaceAll(r' ', r'\ ');
|
||||
}
|
||||
|
||||
// https://ninja-build.org/manual.html#_depfile
|
||||
Future<void> _writeDepfile(Program program, String output, String depfile) async {
|
||||
final IOSink file = new File(depfile).openWrite();
|
||||
file.write(_escapePath(output));
|
||||
file.write(':');
|
||||
for (Uri dep in program.uriToSource.keys) {
|
||||
file.write(' ');
|
||||
file.write(_escapePath(dep.toFilePath()));
|
||||
}
|
||||
file.write('\n');
|
||||
await file.close();
|
||||
}
|
||||
|
||||
/// Entry point for this module, that creates `_FrontendCompiler` instance and
|
||||
/// processes user input.
|
||||
/// `compiler` is an optional parameter so it can be replaced with mocked
|
||||
|
||||
Reference in New Issue
Block a user