From 46f0f0b89e0a3a196669bcc6cc58b6c36d06889b Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Fri, 24 Mar 2017 15:28:29 -0700 Subject: [PATCH] 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. --- .../flutter/tools/licenses/lib/licenses.dart | 4 ++++ .../src/flutter/tools/licenses/lib/main.dart | 20 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/tools/licenses/lib/licenses.dart b/engine/src/flutter/tools/licenses/lib/licenses.dart index 3dadcb1598..7ba9184524 100644 --- a/engine/src/flutter/tools/licenses/lib/licenses.dart +++ b/engine/src/flutter/tools/licenses/lib/licenses.dart @@ -400,6 +400,10 @@ abstract class License implements Comparable { final Map _registry = {}; +void clearLicenseRegistry() { + _registry.clear(); +} + final License missingLicense = new UniqueLicense._('', LicenseType.unknown); String _reformat(String body) { diff --git a/engine/src/flutter/tools/licenses/lib/main.dart b/engine/src/flutter/tools/licenses/lib/main.dart index 551e5eb9cd..94dca227ff 100644 --- a/engine/src/flutter/tools/licenses/lib/main.dart +++ b/engine/src/flutter/tools/licenses/lib/main.dart @@ -2304,7 +2304,8 @@ Future main(List 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 main(List 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 main(List 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 licenses = new Set.from( - component.getLicenses(progress).toList()).toList(); + componentRoot.getLicenses(progress).toList()).toList(); sink.writeln('UNUSED LICENSES:\n'); List unusedLicenses = licenses