Generate a depfile for assets of a flutter_app. (#8961)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user