This makes the about page show the licenses of all the Dart packages that a Flutter app uses.

Issues that this does not yet resolve:
- I'm still working on getting the full list of licenses for the sky_engine package.
- Some of the licenses don't print very readably.
- There's no scrollbar on the license page.

I'll provide fixes for the first two in the coming days, but this should unblock anyone who is wanting to see something here, even if it's not quite complete. :-)

----

The patch makes the following changes: 

- The license registry is now asynchronous, since the data comes from disk.
- I moved the default license collector from the foundation package to the services package since it uses the default asset bundle now.
- The FLX builder now includes the LICENSE files of each Dart package mentioned in the `.packages` file.
This commit is contained in:
Ian Hickson
2016-07-21 09:09:48 -07:00
committed by GitHub
parent 79559d396e
commit 69d78325ec
8 changed files with 135 additions and 69 deletions

View File

@@ -28,8 +28,7 @@ class PackageMap {
final String packagesPath;
Map<String, Uri> get map {
if (_map == null)
_map = _parse(packagesPath);
_map ??= _parse(packagesPath);
return _map;
}
Map<String, Uri> _map;

View File

@@ -66,7 +66,7 @@ class _Asset {
/// The entry to list in the generated asset manifest.
String get assetEntry => _assetEntry ?? relativePath;
/// Where the resource is on disk realtive to [base].
/// Where the resource is on disk relative to [base].
final String relativePath;
final String source;
@@ -200,6 +200,34 @@ Map<_Asset, List<_Asset>> _parseAssets(
return result;
}
final String _licenseSeparator = '\n' + ('-' * 80) + '\n';
/// Returns a ZipEntry representing the license file.
ZipEntry _obtainLicenses(
PackageMap packageMap,
String assetBase
) {
// Read the LICENSE file from each package in the .packages file,
// splitting each one into each component license (so that we can
// de-dupe if possible).
final Set<String> packageLicenses = new Set<String>();
final List<Uri> packages = packageMap.map.values;
for (Uri package in packages) {
if (package != null && package.scheme == 'file') {
final File file = new File.fromUri(package.resolve('../LICENSE'));
if (file.existsSync())
packageLicenses.addAll(file.readAsStringSync().split(_licenseSeparator));
}
}
final List<String> combinedLicensesList = packageLicenses.toList();
combinedLicensesList.sort();
final String combinedLicenses = combinedLicensesList.join(_licenseSeparator);
return new ZipEntry.fromString('LICENSE', combinedLicenses);
}
_Asset _resolveAsset(
PackageMap packageMap,
String assetBase,
@@ -362,13 +390,13 @@ Future<int> build({
}
return assemble(
manifestDescriptor: manifestDescriptor,
snapshotFile: snapshotFile,
assetBasePath: assetBasePath,
outputPath: outputPath,
privateKeyPath: privateKeyPath,
workingDirPath: workingDirPath,
includeRobotoFonts: includeRobotoFonts
manifestDescriptor: manifestDescriptor,
snapshotFile: snapshotFile,
assetBasePath: assetBasePath,
outputPath: outputPath,
privateKeyPath: privateKeyPath,
workingDirPath: workingDirPath,
includeRobotoFonts: includeRobotoFonts
);
}
@@ -383,8 +411,10 @@ Future<int> assemble({
}) async {
printTrace('Building $outputPath');
final PackageMap packageMap = new PackageMap(path.join(assetBasePath, '.packages'));
Map<_Asset, List<_Asset>> assetVariants = _parseAssets(
new PackageMap(path.join(assetBasePath, '.packages')),
packageMap,
manifestDescriptor,
assetBasePath,
excludeDirs: <String>[workingDirPath, path.join(assetBasePath, 'build')]
@@ -434,6 +464,8 @@ Future<int> assemble({
if (fontManifest != null)
zipBuilder.addEntry(fontManifest);
zipBuilder.addEntry(_obtainLicenses(packageMap, assetBasePath));
ensureDirectoryExists(outputPath);
printTrace('Encoding zip file to $outputPath');