Ensure that the license script does not mix state among components (flutter/engine#3514)

The script keeps state in the objects representing the repository files,
and it also maintains a cache of licenses.  This state should be freshly
recreated for each component so data from previous components does not
leak through.
This commit is contained in:
Jason Simmons
2017-03-24 15:28:29 -07:00
committed by GitHub
parent e9635a42c5
commit 46f0f0b89e
2 changed files with 22 additions and 2 deletions

View File

@@ -400,6 +400,10 @@ abstract class License implements Comparable<License> {
final Map<String, License> _registry = <String, License>{};
void clearLicenseRegistry() {
_registry.clear();
}
final License missingLicense = new UniqueLicense._('<missing>', LicenseType.unknown);
String _reformat(String body) {

View File

@@ -2304,7 +2304,8 @@ Future<Null> main(List<String> arguments) async {
try {
system.stderr.writeln('Finding files...');
final RepositoryDirectory root = new RepositoryRoot(new fs.FileSystemDirectory.fromPath(argResults['src']));
fs.FileSystemDirectory rootDirectory = new fs.FileSystemDirectory.fromPath(argResults['src']);
final RepositoryDirectory root = new RepositoryRoot(rootDirectory);
if (releaseMode) {
system.stderr.writeln('Collecting licenses...');
@@ -2323,6 +2324,7 @@ Future<Null> main(List<String> arguments) async {
} else {
RegExp signaturePattern = new RegExp(r'Signature: (\w+)');
bool isFirstComponent = true;
for (RepositoryDirectory component in root.subdirectories) {
system.stderr.writeln('Collecting licenses for ${component.io.name}');
@@ -2357,8 +2359,22 @@ Future<Null> main(List<String> arguments) async {
if (signature != null)
sink.writeln('Signature: $signature\n');
RepositoryDirectory componentRoot;
if (isFirstComponent) {
// For the first component, we can use the results of the initial
// repository crawl.
isFirstComponent = false;
componentRoot = component;
} else {
// For other components, we need a clean repository that does not
// contain any state left over from previous components.
clearLicenseRegistry();
componentRoot = new RepositoryRoot(rootDirectory).subdirectories.firstWhere(
(RepositoryDirectory dir) => dir.io.name == component.io.name
);
}
List<License> licenses = new Set<License>.from(
component.getLicenses(progress).toList()).toList();
componentRoot.getLicenses(progress).toList()).toList();
sink.writeln('UNUSED LICENSES:\n');
List<String> unusedLicenses = licenses