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

Commit 4320453

Browse files
committed
Fix signature logic in license tool
1 parent 42689ea commit 4320453

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

ci/licenses_golden/tool_signature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
Signature: e9bc01b7e51cb2185dc056dffd7ff351
1+
Signature: a32ccfa90d913a0d78945c13cd224278
2+
23

tools/licenses/lib/main.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,20 +1881,22 @@ class _Progress {
18811881
}
18821882
}
18831883

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

18861886
/// Reads the signature from a golden file.
18871887
String? _readSignature(String goldenPath) {
18881888
try {
18891889
final system.File goldenFile = system.File(goldenPath);
18901890
if (!goldenFile.existsSync()) {
1891+
system.stderr.writeln(' Could not find signature file ($goldenPath).');
18911892
return null;
18921893
}
18931894
final String goldenSignature = goldenFile.readAsStringSync();
18941895
final Match? goldenMatch = _signaturePattern.matchAsPrefix(goldenSignature);
18951896
if (goldenMatch != null) {
18961897
return goldenMatch.group(1);
18971898
}
1899+
system.stderr.writeln(' Signature file ($goldenPath) did not match expected pattern.');
18981900
} on system.FileSystemException {
18991901
system.stderr.writeln(' Failed to read signature file ($goldenPath).');
19001902
return null;
@@ -1913,7 +1915,6 @@ void _writeSignature(String signature, system.IOSink sink) {
19131915
//
19141916
// Returns true if changes are detected.
19151917
Future<bool> _computeLicenseToolChanges(_RepositoryDirectory root, { required String goldenSignaturePath, required String outputSignaturePath }) async {
1916-
system.stderr.writeln('Computing signature for license tool');
19171918
final fs.Directory flutterNode = findChildDirectory(root.ioDirectory, 'flutter')!;
19181919
final fs.Directory toolsNode = findChildDirectory(flutterNode, 'tools')!;
19191920
final fs.Directory licenseNode = findChildDirectory(toolsNode, 'licenses')!;
@@ -1933,23 +1934,27 @@ Future<bool> _computeLicenseToolChanges(_RepositoryDirectory root, { required St
19331934
Future<void> _collectLicensesForComponent(_RepositoryDirectory componentRoot, {
19341935
required String inputGoldenPath,
19351936
String? outputGoldenPath,
1936-
bool? writeSignature,
1937+
required bool writeSignature,
19371938
required bool force,
19381939
required bool quiet,
19391940
}) async {
1940-
// Check whether the golden file matches the signature of the current contents of this directory.
1941-
final String? goldenSignature = _readSignature(inputGoldenPath);
19421941
final String signature = await componentRoot.signature;
1943-
if (!force && goldenSignature == signature) {
1944-
system.stderr.writeln(' Skipping this component - no change in signature');
1945-
return;
1942+
if (writeSignature) {
1943+
// Check whether the golden file matches the signature of the current contents of this directory.
1944+
// (We only do this for components where we write the signature, since if there's no signature,
1945+
// there's no point trying to read it...)
1946+
final String? goldenSignature = _readSignature(inputGoldenPath);
1947+
if (!force && goldenSignature == signature) {
1948+
system.stderr.writeln(' Skipping this component - no change in signature');
1949+
return;
1950+
}
19461951
}
19471952

19481953
final _Progress progress = _Progress(componentRoot.fileCount, quiet: quiet);
19491954

19501955
final system.File outFile = system.File(outputGoldenPath!);
19511956
final system.IOSink sink = outFile.openWrite();
1952-
if (writeSignature!) {
1957+
if (writeSignature) {
19531958
_writeSignature(signature, sink);
19541959
}
19551960

0 commit comments

Comments
 (0)