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

Fix signature logic in license tool #38363

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/licenses_golden/tool_signature
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Signature: e9bc01b7e51cb2185dc056dffd7ff351
Signature: 00d569c39c5ea2c3160c0e500196dd7e

27 changes: 15 additions & 12 deletions tools/licenses/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -1881,20 +1879,22 @@ 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();
final Match? goldenMatch = _signaturePattern.matchAsPrefix(goldenSignature);
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;
Expand All @@ -1913,7 +1913,6 @@ void _writeSignature(String signature, system.IOSink sink) {
//
// Returns true if changes are detected.
Future<bool> _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')!;
Expand All @@ -1933,23 +1932,27 @@ Future<bool> _computeLicenseToolChanges(_RepositoryDirectory root, { required St
Future<void> _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);
}

Expand Down