Commit d356b2d7 authored by P.Y. Laligand's avatar P.Y. Laligand Committed by GitHub

Generate a depfile for assets of a flutter_app. (#8961)

parent 38e4e48d
......@@ -25,13 +25,17 @@ const String _kOptionOutput = 'output-file';
const String _kOptionHeader = 'header';
const String _kOptionSnapshot = 'snapshot';
const String _kOptionWorking = 'working-dir';
const String _kOptionsManifest = 'manifest';
const String _kOptionManifest = 'manifest';
const String _kOptionDepFile = 'depfile';
const String _kOptionBuildRoot = 'build-root';
const List<String> _kRequiredOptions = const <String>[
_kOptionPackages,
_kOptionOutput,
_kOptionHeader,
_kOptionSnapshot,
_kOptionWorking,
_kOptionDepFile,
_kOptionBuildRoot,
];
Future<Null> main(List<String> args) async {
......@@ -59,23 +63,36 @@ Future<Null> run(List<String> args) async {
..addOption(_kOptionSnapshot, help: 'The generated snapshot file')
..addOption(_kOptionWorking,
help: 'The directory where to put temporary files')
..addOption(_kOptionsManifest, help: 'The manifest file');
..addOption(_kOptionManifest, help: 'The manifest file')
..addOption(_kOptionDepFile, help: 'The generated depfile')
..addOption(_kOptionBuildRoot, help: 'The build\'s root directory');
final ArgResults argResults = parser.parse(args);
if (_kRequiredOptions.any((String option) => !argResults.options.contains(option))) {
if (_kRequiredOptions
.any((String option) => !argResults.options.contains(option))) {
printError('Missing option! All options must be specified.');
exit(1);
}
Cache.flutterRoot = platform.environment['FLUTTER_ROOT'];
final String outputPath = argResults[_kOptionOutput];
try {
await assemble(
final List<String> dependencies = await assemble(
outputPath: outputPath,
snapshotFile: fs.file(argResults[_kOptionSnapshot]),
workingDirPath: argResults[_kOptionWorking],
packagesPath: argResults[_kOptionPackages],
manifestPath: argResults[_kOptionsManifest] ?? defaultManifestPath,
manifestPath: argResults[_kOptionManifest] ?? defaultManifestPath,
includeDefaultFonts: false,
);
final String depFilePath = argResults[_kOptionDepFile];
final int depFileResult = _createDepfile(
depFilePath,
fs.path.relative(argResults[_kOptionOutput],
from: argResults[_kOptionBuildRoot]),
dependencies);
if (depFileResult != 0) {
printError('Error creating depfile $depFilePath: $depFileResult.');
exit(depFileResult);
}
} on ToolExit catch (e) {
printError(e.message);
exit(e.exitCode);
......@@ -87,6 +104,17 @@ Future<Null> run(List<String> args) async {
exit(headerResult);
}
int _createDepfile(
String depFilePath, String target, List<String> dependencies) {
try {
final File depFile = fs.file(depFilePath);
depFile.writeAsStringSync('$target: ${dependencies.join(' ')}\n');
return 0;
} catch (_) {
return 1;
}
}
int _addHeader(String outputPath, String header) {
try {
final File outputFile = fs.file(outputPath);
......
......@@ -42,6 +42,9 @@ abstract class DevFSContent {
Stream<List<int>> contentsAsCompressedStream() {
return contentsAsStream().transform(GZIP.encoder);
}
/// Return the list of files this content depends on.
List<String> get fileDependencies => <String>[];
}
// File content to be copied to the device.
......@@ -82,6 +85,9 @@ class DevFSFileContent extends DevFSContent {
}
}
@override
List<String> get fileDependencies => <String>[_getFile().path];
@override
bool get isModified {
final FileStat _oldFileStat = _fileStat;
......
......@@ -107,10 +107,10 @@ Future<Null> build({
packagesPath: packagesPath,
includeRobotoFonts: includeRobotoFonts,
reportLicensedPackages: reportLicensedPackages
);
).then((_) => null);
}
Future<Null> assemble({
Future<List<String>> assemble({
String manifestPath,
DevFSContent kernelContent,
File snapshotFile,
......@@ -145,6 +145,10 @@ Future<Null> assemble({
// Add all entries from the asset bundle.
zipBuilder.entries.addAll(assetBundle.entries);
final List<String> fileDependencies = assetBundle.entries.values
.expand((DevFSContent content) => content.fileDependencies)
.toList();
if (kernelContent != null)
zipBuilder.entries[_kKernelKey] = kernelContent;
if (snapshotFile != null)
......@@ -156,4 +160,6 @@ Future<Null> assemble({
await zipBuilder.createZip(fs.file(outputPath), fs.directory(workingDirPath));
printTrace('Built $outputPath.');
return fileDependencies;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment