Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 955a35a

Browse files
authored
Fix signature logic in license tool (#38363)
1 parent 3431669 commit 955a35a

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

ci/licenses_golden/tool_signature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Signature: e9bc01b7e51cb2185dc056dffd7ff351
1+
Signature: 00d569c39c5ea2c3160c0e500196dd7e
22

tools/licenses/lib/main.dart

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,9 +1854,7 @@ class _Progress {
18541854
void update({bool flush = false}) {
18551855
if (_lastUpdate == null || _lastUpdate!.elapsedMilliseconds >= millisecondsBetweenUpdates || flush) {
18561856
_lastUpdate ??= Stopwatch();
1857-
if (quiet) {
1858-
system.stderr.write('.');
1859-
} else {
1857+
if (!quiet) {
18601858
final String line = toString();
18611859
system.stderr.write('\r$line');
18621860
if (_lastLength > line.length) {
@@ -1881,20 +1879,22 @@ class _Progress {
18811879
}
18821880
}
18831881

1884-
final RegExp _signaturePattern = RegExp(r'^Signature: (\w+)$', expectNoMatch: true);
1882+
final RegExp _signaturePattern = RegExp(r'^Signature: (\w+)$', multiLine: true, expectNoMatch: true);
18851883

18861884
/// Reads the signature from a golden file.
18871885
String? _readSignature(String goldenPath) {
18881886
try {
18891887
final system.File goldenFile = system.File(goldenPath);
18901888
if (!goldenFile.existsSync()) {
1889+
system.stderr.writeln(' Could not find signature file ($goldenPath).');
18911890
return null;
18921891
}
18931892
final String goldenSignature = goldenFile.readAsStringSync();
18941893
final Match? goldenMatch = _signaturePattern.matchAsPrefix(goldenSignature);
18951894
if (goldenMatch != null) {
18961895
return goldenMatch.group(1);
18971896
}
1897+
system.stderr.writeln(' Signature file ($goldenPath) did not match expected pattern.');
18981898
} on system.FileSystemException {
18991899
system.stderr.writeln(' Failed to read signature file ($goldenPath).');
19001900
return null;
@@ -1913,7 +1913,6 @@ void _writeSignature(String signature, system.IOSink sink) {
19131913
//
19141914
// Returns true if changes are detected.
19151915
Future<bool> _computeLicenseToolChanges(_RepositoryDirectory root, { required String goldenSignaturePath, required String outputSignaturePath }) async {
1916-
system.stderr.writeln('Computing signature for license tool');
19171916
final fs.Directory flutterNode = findChildDirectory(root.ioDirectory, 'flutter')!;
19181917
final fs.Directory toolsNode = findChildDirectory(flutterNode, 'tools')!;
19191918
final fs.Directory licenseNode = findChildDirectory(toolsNode, 'licenses')!;
@@ -1933,23 +1932,27 @@ Future<bool> _computeLicenseToolChanges(_RepositoryDirectory root, { required St
19331932
Future<void> _collectLicensesForComponent(_RepositoryDirectory componentRoot, {
19341933
required String inputGoldenPath,
19351934
String? outputGoldenPath,
1936-
bool? writeSignature,
1935+
required bool writeSignature,
19371936
required bool force,
19381937
required bool quiet,
19391938
}) async {
1940-
// Check whether the golden file matches the signature of the current contents of this directory.
1941-
final String? goldenSignature = _readSignature(inputGoldenPath);
19421939
final String signature = await componentRoot.signature;
1943-
if (!force && goldenSignature == signature) {
1944-
system.stderr.writeln(' Skipping this component - no change in signature');
1945-
return;
1940+
if (writeSignature) {
1941+
// Check whether the golden file matches the signature of the current contents of this directory.
1942+
// (We only do this for components where we write the signature, since if there's no signature,
1943+
// there's no point trying to read it...)
1944+
final String? goldenSignature = _readSignature(inputGoldenPath);
1945+
if (!force && goldenSignature == signature) {
1946+
system.stderr.writeln(' Skipping this component - no change in signature');
1947+
return;
1948+
}
19461949
}
19471950

19481951
final _Progress progress = _Progress(componentRoot.fileCount, quiet: quiet);
19491952

19501953
final system.File outFile = system.File(outputGoldenPath!);
19511954
final system.IOSink sink = outFile.openWrite();
1952-
if (writeSignature!) {
1955+
if (writeSignature) {
19531956
_writeSignature(signature, sink);
19541957
}
19551958

0 commit comments

Comments
 (0)