Add support for assets in Fuchsia packages (#14654)

Pull code out of flx.dart:assemble() to make flx.dart:buildAssets
which creates the AssetBundle. This will allow us to create just
this instead of an entire FLX.
This commit is contained in:
Justin
2018-02-14 08:05:05 -08:00
committed by Todd Volkert
parent a448994543
commit ec76c652bd
5 changed files with 181 additions and 38 deletions

View File

@@ -0,0 +1,39 @@
// Copyright 2018 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:async';
import 'package:process/process.dart';
import 'base/config.dart';
import 'base/context.dart';
import 'base/file_system.dart';
import 'base/io.dart';
import 'base/logger.dart';
import 'base/os.dart';
import 'base/platform.dart';
import 'cache.dart';
import 'disabled_usage.dart';
import 'usage.dart';
typedef Future<Null> Runner(List<String> args);
Future<Null> runInContext(List<String> args, Runner runner) {
final AppContext executableContext = new AppContext();
executableContext.setVariable(Logger, new StdoutLogger());
return executableContext.runInZone(() {
// Initialize the context with some defaults.
// This list must be kept in sync with lib/executable.dart.
context.putIfAbsent(Stdio, () => const Stdio());
context.putIfAbsent(Platform, () => const LocalPlatform());
context.putIfAbsent(FileSystem, () => const LocalFileSystem());
context.putIfAbsent(ProcessManager, () => const LocalProcessManager());
context.putIfAbsent(Logger, () => new StdoutLogger());
context.putIfAbsent(Cache, () => new Cache());
context.putIfAbsent(Config, () => new Config());
context.putIfAbsent(OperatingSystemUtils, () => new OperatingSystemUtils());
context.putIfAbsent(Usage, () => new DisabledUsage());
return runner(args);
});
}

View File

@@ -82,34 +82,34 @@ Future<Null> build({
kernelContent = new DevFSFileContent(fs.file(kernelBinaryFilename));
}
return assemble(
final AssetBundle assets = await buildAssets(
manifestPath: manifestPath,
workingDirPath: workingDirPath,
packagesPath: packagesPath,
reportLicensedPackages: reportLicensedPackages,
);
if (assets == null)
throwToolExit('Error building assets for $outputPath', exitCode: 1);
return assemble(
assetBundle: assets,
kernelContent: kernelContent,
snapshotFile: snapshotFile,
outputPath: outputPath,
privateKeyPath: privateKeyPath,
workingDirPath: workingDirPath,
packagesPath: packagesPath,
reportLicensedPackages: reportLicensedPackages
).then((_) => null);
}
Future<List<String>> assemble({
Future<AssetBundle> buildAssets({
String manifestPath,
DevFSContent kernelContent,
File snapshotFile,
File dylibFile,
String outputPath,
String privateKeyPath: defaultPrivateKeyPath,
String workingDirPath,
String packagesPath,
bool includeDefaultFonts: true,
bool reportLicensedPackages: false
}) async {
outputPath ??= defaultFlxOutputPath;
workingDirPath ??= getAssetBuildDirectory();
packagesPath ??= fs.path.absolute(PackageMap.globalPackagesPath);
printTrace('Building $outputPath');
// Build the asset bundle.
final AssetBundle assetBundle = AssetBundleFactory.instance.createBundle();
@@ -121,7 +121,23 @@ Future<List<String>> assemble({
reportLicensedPackages: reportLicensedPackages
);
if (result != 0)
throwToolExit('Error building $outputPath: $result', exitCode: result);
return null;
return assetBundle;
}
Future<List<String>> assemble({
AssetBundle assetBundle,
DevFSContent kernelContent,
File snapshotFile,
File dylibFile,
String outputPath,
String privateKeyPath: defaultPrivateKeyPath,
String workingDirPath,
}) async {
outputPath ??= defaultFlxOutputPath;
workingDirPath ??= getAssetBuildDirectory();
printTrace('Building $outputPath');
final ZipBuilder zipBuilder = new ZipBuilder();