forked from firka/flutter
Support specifying a fixed list of assets on the command line (#6857)
This commit is contained in:
@@ -52,9 +52,33 @@ class AssetBundle {
|
|||||||
static const String _kFontSetMaterial = 'material';
|
static const String _kFontSetMaterial = 'material';
|
||||||
static const String _kFontSetRoboto = 'roboto';
|
static const String _kFontSetRoboto = 'roboto';
|
||||||
|
|
||||||
|
bool _fixed = false;
|
||||||
DateTime _lastBuildTimestamp;
|
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}) {
|
bool needsBuild({String manifestPath: defaultManifestPath}) {
|
||||||
|
if (_fixed)
|
||||||
|
return false;
|
||||||
if (_lastBuildTimestamp == null)
|
if (_lastBuildTimestamp == null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|||||||
@@ -63,9 +63,12 @@ class RunCommand extends RunCommandBase {
|
|||||||
argParser.addOption('packages',
|
argParser.addOption('packages',
|
||||||
hide: !verboseHelp,
|
hide: !verboseHelp,
|
||||||
help: 'Specify the path to the .packages file.');
|
help: 'Specify the path to the .packages file.');
|
||||||
argParser.addOption('project_root',
|
argParser.addOption('project-root',
|
||||||
hide: !verboseHelp,
|
hide: !verboseHelp,
|
||||||
help: 'Specify the project root directory.');
|
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',
|
argParser.addFlag('machine',
|
||||||
hide: !verboseHelp,
|
hide: !verboseHelp,
|
||||||
help: 'Handle machine structured JSON command input\n'
|
help: 'Handle machine structured JSON command input\n'
|
||||||
@@ -219,8 +222,9 @@ class RunCommand extends RunCommandBase {
|
|||||||
debuggingOptions: options,
|
debuggingOptions: options,
|
||||||
benchmarkMode: argResults['benchmark'],
|
benchmarkMode: argResults['benchmark'],
|
||||||
applicationBinary: argResults['use-application-binary'],
|
applicationBinary: argResults['use-application-binary'],
|
||||||
projectRootPath: argResults['project_root'],
|
projectRootPath: argResults['project-root'],
|
||||||
packagesFilePath: argResults['packages'],
|
packagesFilePath: argResults['packages'],
|
||||||
|
projectAssets: argResults['project-assets']
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
runner = new RunAndStayResident(
|
runner = new RunAndStayResident(
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ class HotRunner extends ResidentRunner {
|
|||||||
this.applicationBinary,
|
this.applicationBinary,
|
||||||
String projectRootPath,
|
String projectRootPath,
|
||||||
String packagesFilePath,
|
String packagesFilePath,
|
||||||
|
String projectAssets,
|
||||||
}) : super(device,
|
}) : super(device,
|
||||||
target: target,
|
target: target,
|
||||||
debuggingOptions: debuggingOptions,
|
debuggingOptions: debuggingOptions,
|
||||||
@@ -106,6 +107,10 @@ class HotRunner extends ResidentRunner {
|
|||||||
_projectRootPath = projectRootPath ?? Directory.current.path;
|
_projectRootPath = projectRootPath ?? Directory.current.path;
|
||||||
_packagesFilePath =
|
_packagesFilePath =
|
||||||
packagesFilePath ?? path.absolute(PackageMap.globalPackagesPath);
|
packagesFilePath ?? path.absolute(PackageMap.globalPackagesPath);
|
||||||
|
if (projectAssets != null)
|
||||||
|
_bundle = new AssetBundle.fixed(_projectRootPath, projectAssets);
|
||||||
|
else
|
||||||
|
_bundle = new AssetBundle();
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationPackage _package;
|
ApplicationPackage _package;
|
||||||
@@ -116,7 +121,8 @@ class HotRunner extends ResidentRunner {
|
|||||||
bool get prebuiltMode => applicationBinary != null;
|
bool get prebuiltMode => applicationBinary != null;
|
||||||
Set<String> _dartDependencies;
|
Set<String> _dartDependencies;
|
||||||
int _observatoryPort;
|
int _observatoryPort;
|
||||||
final AssetBundle bundle = new AssetBundle();
|
AssetBundle _bundle;
|
||||||
|
AssetBundle get bundle => _bundle;
|
||||||
final bool benchmarkMode;
|
final bool benchmarkMode;
|
||||||
final Map<String, int> benchmarkData = new Map<String, int>();
|
final Map<String, int> benchmarkData = new Map<String, int>();
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import 'analyze_duplicate_names_test.dart' as analyze_duplicate_names_test;
|
|||||||
import 'analyze_test.dart' as analyze_test;
|
import 'analyze_test.dart' as analyze_test;
|
||||||
import 'android_device_test.dart' as android_device_test;
|
import 'android_device_test.dart' as android_device_test;
|
||||||
import 'android_sdk_test.dart' as android_sdk_test;
|
import 'android_sdk_test.dart' as android_sdk_test;
|
||||||
|
import 'asset_bundle_test.dart' as asset_bundle_test;
|
||||||
import 'application_package_test.dart' as application_package_test;
|
import 'application_package_test.dart' as application_package_test;
|
||||||
import 'base_utils_test.dart' as base_utils_test;
|
import 'base_utils_test.dart' as base_utils_test;
|
||||||
import 'channel_test.dart' as channel_test;
|
import 'channel_test.dart' as channel_test;
|
||||||
@@ -49,6 +50,7 @@ void main() {
|
|||||||
android_device_test.main();
|
android_device_test.main();
|
||||||
android_sdk_test.main();
|
android_sdk_test.main();
|
||||||
application_package_test.main();
|
application_package_test.main();
|
||||||
|
asset_bundle_test.main();
|
||||||
base_utils_test.main();
|
base_utils_test.main();
|
||||||
channel_test.main();
|
channel_test.main();
|
||||||
config_test.main();
|
config_test.main();
|
||||||
|
|||||||
60
packages/flutter_tools/test/asset_bundle_test.dart
Normal file
60
packages/flutter_tools/test/asset_bundle_test.dart
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'dart:io';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'package:flutter_tools/src/asset.dart';
|
||||||
|
import 'package:path/path.dart' as path;
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
// Create a temporary directory and write a single file into it.
|
||||||
|
Directory tempDir = Directory.systemTemp.createTempSync();
|
||||||
|
String projectRoot = tempDir.path;
|
||||||
|
String assetPath = 'banana.txt';
|
||||||
|
String assetContents = 'banana';
|
||||||
|
File tempFile = new File(path.join(projectRoot, assetPath));
|
||||||
|
tempFile.parent.createSync(recursive: true);
|
||||||
|
tempFile.writeAsBytesSync(UTF8.encode(assetContents));
|
||||||
|
|
||||||
|
// Fixed asset bundle tests.
|
||||||
|
group('AssetBundle.fixed', () {
|
||||||
|
test('empty strings', () async {
|
||||||
|
expect(new AssetBundle.fixed(null, null), isNotNull);
|
||||||
|
expect(new AssetBundle.fixed('', ''), isNotNull);
|
||||||
|
expect(new AssetBundle.fixed(null, null).entries, isEmpty);
|
||||||
|
});
|
||||||
|
test('does not need a rebuild', () async {
|
||||||
|
expect(new AssetBundle.fixed(null, null).needsBuild(), isFalse);
|
||||||
|
});
|
||||||
|
test('single entry', () async {
|
||||||
|
AssetBundle ab = new AssetBundle.fixed('', 'apple.txt');
|
||||||
|
expect(ab.entries, isNotEmpty);
|
||||||
|
expect(ab.entries.length, 1);
|
||||||
|
AssetBundleEntry entry = ab.entries.first;
|
||||||
|
expect(entry, isNotNull);
|
||||||
|
expect(entry.archivePath, 'apple.txt');
|
||||||
|
});
|
||||||
|
test('two entries', () async {
|
||||||
|
AssetBundle ab = new AssetBundle.fixed('', 'apple.txt,packages/flutter_gallery_assets/shrine/products/heels.png');
|
||||||
|
expect(ab.entries, isNotEmpty);
|
||||||
|
expect(ab.entries.length, 2);
|
||||||
|
AssetBundleEntry firstEntry = ab.entries.first;
|
||||||
|
expect(firstEntry, isNotNull);
|
||||||
|
expect(firstEntry.archivePath, 'apple.txt');
|
||||||
|
AssetBundleEntry lastEntry = ab.entries.last;
|
||||||
|
expect(lastEntry, isNotNull);
|
||||||
|
expect(lastEntry.archivePath, 'packages/flutter_gallery_assets/shrine/products/heels.png');
|
||||||
|
});
|
||||||
|
test('file contents', () async {
|
||||||
|
AssetBundle ab = new AssetBundle.fixed(projectRoot, assetPath);
|
||||||
|
expect(ab.entries, isNotEmpty);
|
||||||
|
expect(ab.entries.length, 1);
|
||||||
|
AssetBundleEntry entry = ab.entries.first;
|
||||||
|
expect(entry, isNotNull);
|
||||||
|
expect(entry.archivePath, assetPath);
|
||||||
|
expect(assetContents, UTF8.decode(entry.contentsAsBytes()));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user