Support specifying a fixed list of assets on the command line (#6857)

This commit is contained in:
John McCutchan
2016-11-15 07:01:00 -08:00
committed by GitHub
parent fd5a08941e
commit d54bed45f3
5 changed files with 99 additions and 3 deletions

View File

@@ -52,9 +52,33 @@ class AssetBundle {
static const String _kFontSetMaterial = 'material';
static const String _kFontSetRoboto = 'roboto';
bool _fixed = false;
DateTime _lastBuildTimestamp;
/// Constructs an [AssetBundle] that gathers the set of assets from the
/// flutter.yaml manifest.
AssetBundle();
/// Constructs an [AssetBundle] with a fixed set of assets.
/// [projectRoot] The absolute path to the project root.
/// [projectAssets] comma separated list of assets.
AssetBundle.fixed(String projectRoot, String projectAssets) {
_fixed = true;
if ((projectRoot == null) || (projectAssets == null))
return;
List<String> assets = projectAssets.split(',');
for (String asset in assets) {
final String assetPath = path.join(projectRoot, asset);
final String archivePath = asset;
entries.add(
new AssetBundleEntry.fromFile(archivePath, new File(assetPath)));
}
}
bool needsBuild({String manifestPath: defaultManifestPath}) {
if (_fixed)
return false;
if (_lastBuildTimestamp == null)
return true;

View File

@@ -63,9 +63,12 @@ class RunCommand extends RunCommandBase {
argParser.addOption('packages',
hide: !verboseHelp,
help: 'Specify the path to the .packages file.');
argParser.addOption('project_root',
argParser.addOption('project-root',
hide: !verboseHelp,
help: 'Specify the project root directory.');
argParser.addOption('project-assets',
hide: !verboseHelp,
help: 'Specify the project assets relative to the root directory.');
argParser.addFlag('machine',
hide: !verboseHelp,
help: 'Handle machine structured JSON command input\n'
@@ -219,8 +222,9 @@ class RunCommand extends RunCommandBase {
debuggingOptions: options,
benchmarkMode: argResults['benchmark'],
applicationBinary: argResults['use-application-binary'],
projectRootPath: argResults['project_root'],
projectRootPath: argResults['project-root'],
packagesFilePath: argResults['packages'],
projectAssets: argResults['project-assets']
);
} else {
runner = new RunAndStayResident(

View File

@@ -99,6 +99,7 @@ class HotRunner extends ResidentRunner {
this.applicationBinary,
String projectRootPath,
String packagesFilePath,
String projectAssets,
}) : super(device,
target: target,
debuggingOptions: debuggingOptions,
@@ -106,6 +107,10 @@ class HotRunner extends ResidentRunner {
_projectRootPath = projectRootPath ?? Directory.current.path;
_packagesFilePath =
packagesFilePath ?? path.absolute(PackageMap.globalPackagesPath);
if (projectAssets != null)
_bundle = new AssetBundle.fixed(_projectRootPath, projectAssets);
else
_bundle = new AssetBundle();
}
ApplicationPackage _package;
@@ -116,7 +121,8 @@ class HotRunner extends ResidentRunner {
bool get prebuiltMode => applicationBinary != null;
Set<String> _dartDependencies;
int _observatoryPort;
final AssetBundle bundle = new AssetBundle();
AssetBundle _bundle;
AssetBundle get bundle => _bundle;
final bool benchmarkMode;
final Map<String, int> benchmarkData = new Map<String, int>();