From 330dc5a9b1a8f2674da26c58f749f8c6e7aac7b3 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Fri, 16 Dec 2022 15:49:23 -0800 Subject: [PATCH] Fix signature logic in license tool --- ci/licenses_golden/tool_signature | 2 +- tools/licenses/lib/main.dart | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ci/licenses_golden/tool_signature b/ci/licenses_golden/tool_signature index 446be9279d9b5..595d34e913347 100644 --- a/ci/licenses_golden/tool_signature +++ b/ci/licenses_golden/tool_signature @@ -1,2 +1,2 @@ -Signature: e9bc01b7e51cb2185dc056dffd7ff351 +Signature: 00d569c39c5ea2c3160c0e500196dd7e diff --git a/tools/licenses/lib/main.dart b/tools/licenses/lib/main.dart index 6e4badf43f42b..c3f5f3161f34a 100644 --- a/tools/licenses/lib/main.dart +++ b/tools/licenses/lib/main.dart @@ -1854,9 +1854,7 @@ class _Progress { void update({bool flush = false}) { if (_lastUpdate == null || _lastUpdate!.elapsedMilliseconds >= millisecondsBetweenUpdates || flush) { _lastUpdate ??= Stopwatch(); - if (quiet) { - system.stderr.write('.'); - } else { + if (!quiet) { final String line = toString(); system.stderr.write('\r$line'); if (_lastLength > line.length) { @@ -1881,13 +1879,14 @@ class _Progress { } } -final RegExp _signaturePattern = RegExp(r'^Signature: (\w+)$', expectNoMatch: true); +final RegExp _signaturePattern = RegExp(r'^Signature: (\w+)$', multiLine: true, expectNoMatch: true); /// Reads the signature from a golden file. String? _readSignature(String goldenPath) { try { final system.File goldenFile = system.File(goldenPath); if (!goldenFile.existsSync()) { + system.stderr.writeln(' Could not find signature file ($goldenPath).'); return null; } final String goldenSignature = goldenFile.readAsStringSync(); @@ -1895,6 +1894,7 @@ String? _readSignature(String goldenPath) { if (goldenMatch != null) { return goldenMatch.group(1); } + system.stderr.writeln(' Signature file ($goldenPath) did not match expected pattern.'); } on system.FileSystemException { system.stderr.writeln(' Failed to read signature file ($goldenPath).'); return null; @@ -1913,7 +1913,6 @@ void _writeSignature(String signature, system.IOSink sink) { // // Returns true if changes are detected. Future _computeLicenseToolChanges(_RepositoryDirectory root, { required String goldenSignaturePath, required String outputSignaturePath }) async { - system.stderr.writeln('Computing signature for license tool'); final fs.Directory flutterNode = findChildDirectory(root.ioDirectory, 'flutter')!; final fs.Directory toolsNode = findChildDirectory(flutterNode, 'tools')!; final fs.Directory licenseNode = findChildDirectory(toolsNode, 'licenses')!; @@ -1933,23 +1932,27 @@ Future _computeLicenseToolChanges(_RepositoryDirectory root, { required St Future _collectLicensesForComponent(_RepositoryDirectory componentRoot, { required String inputGoldenPath, String? outputGoldenPath, - bool? writeSignature, + required bool writeSignature, required bool force, required bool quiet, }) async { - // Check whether the golden file matches the signature of the current contents of this directory. - final String? goldenSignature = _readSignature(inputGoldenPath); final String signature = await componentRoot.signature; - if (!force && goldenSignature == signature) { - system.stderr.writeln(' Skipping this component - no change in signature'); - return; + if (writeSignature) { + // Check whether the golden file matches the signature of the current contents of this directory. + // (We only do this for components where we write the signature, since if there's no signature, + // there's no point trying to read it...) + final String? goldenSignature = _readSignature(inputGoldenPath); + if (!force && goldenSignature == signature) { + system.stderr.writeln(' Skipping this component - no change in signature'); + return; + } } final _Progress progress = _Progress(componentRoot.fileCount, quiet: quiet); final system.File outFile = system.File(outputGoldenPath!); final system.IOSink sink = outFile.openWrite(); - if (writeSignature!) { + if (writeSignature) { _writeSignature(signature, sink); }