Skip to content

Commit

Permalink
Add an option '--depfile' to produce ninja-style depfile for the gene…
Browse files Browse the repository at this point in the history
…rated kernel. (flutter#4704)

* Add an option '--depfile' to produce ninja-style depfile for the generated kernel file.

* Use [program.uriToSource] as a source of dependencies.
  • Loading branch information
aam authored Feb 26, 2018
1 parent 3b4d037 commit 86ec3db
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions frontend_server/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 86ec3db

Please sign in to comment.