From ee0b5cb5954e9ea90536d32b84d126a660349eb7 Mon Sep 17 00:00:00 2001 From: Filip Filmar Date: Fri, 20 Nov 2020 11:18:03 -0800 Subject: [PATCH] Add and use --quiet flag on the license checker (#22485) --- ci/licenses.sh | 13 +++++++++++-- ci/licenses_golden/tool_signature | 2 +- tools/licenses/lib/main.dart | 26 ++++++++++++++++++-------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/ci/licenses.sh b/ci/licenses.sh index 48843bf58d7..2ebbd6f8af6 100755 --- a/ci/licenses.sh +++ b/ci/licenses.sh @@ -33,6 +33,14 @@ SRC_DIR="$(cd "$SCRIPT_DIR/../.."; pwd -P)" DART_BIN="$SRC_DIR/third_party/dart/tools/sdks/dart-sdk/bin" PATH="$DART_BIN:$PATH" +# Use: +# env VERBOSE=1 ./ci/licenses.sh +# to turn on verbose progress report printing. +QUIET="--quiet" +if [[ "${VERBOSE}" == "1" ]]; then + QUIET="" +fi + echo "Verifying license script is still happy..." echo "Using pub from $(command -v pub), dart from $(command -v dart)" @@ -58,7 +66,8 @@ function collect_licenses() ( dart --enable-asserts lib/main.dart \ --src ../../.. \ --out ../../../out/license_script_output \ - --golden ../../ci/licenses_golden + --golden ../../ci/licenses_golden \ + "${QUIET}" ) # Verifies the licenses in the repo. @@ -137,4 +146,4 @@ function verify_licenses() ( return $exitStatus ) -verify_licenses \ No newline at end of file +verify_licenses diff --git a/ci/licenses_golden/tool_signature b/ci/licenses_golden/tool_signature index 7852eee05bf..3b3f9eea6e4 100644 --- a/ci/licenses_golden/tool_signature +++ b/ci/licenses_golden/tool_signature @@ -1,2 +1,2 @@ -Signature: 1f9d73861a9bb353a12cfa2ba38f6a12 +Signature: 164585dad7317491c0f98b96519f87c7 diff --git a/tools/licenses/lib/main.dart b/tools/licenses/lib/main.dart index dea6bf14ae5..e760f2c65a8 100644 --- a/tools/licenses/lib/main.dart +++ b/tools/licenses/lib/main.dart @@ -2319,7 +2319,7 @@ class _RepositoryRoot extends _RepositoryDirectory { class _Progress { - _Progress(this.max) { + _Progress(this.max, {bool quiet = false}) : _quiet = quiet { // This may happen when a git client contains left-over empty component // directories after DEPS file changes. if (max <= 0) @@ -2327,6 +2327,7 @@ class _Progress { } final int max; + final bool _quiet; int get withLicense => _withLicense; int _withLicense = 0; int get withoutLicense => _withoutLicense; @@ -2354,11 +2355,15 @@ class _Progress { void update({bool flush = false}) { if (_lastUpdate == null || _lastUpdate.elapsedMilliseconds > 90 || flush) { _lastUpdate ??= Stopwatch(); - final String line = toString(); - system.stderr.write('\r$line'); - if (_lastLength > line.length) - system.stderr.write(' ' * (_lastLength - line.length)); - _lastLength = line.length; + if (_quiet) { + system.stderr.write('.'); + } else { + final String line = toString(); + system.stderr.write('\r$line'); + if (_lastLength > line.length) + system.stderr.write(' ' * (_lastLength - line.length)); + _lastLength = line.length; + } _lastUpdate.reset(); _lastUpdate.start(); } @@ -2423,6 +2428,7 @@ Future _collectLicensesForComponent(_RepositoryDirectory componentRoot, { String outputGoldenPath, bool writeSignature, bool force, + bool quiet, }) async { // Check whether the golden file matches the signature of the current contents of this directory. final String goldenSignature = await _readSignature(inputGoldenPath); @@ -2432,7 +2438,7 @@ Future _collectLicensesForComponent(_RepositoryDirectory componentRoot, { return; } - final _Progress progress = _Progress(componentRoot.fileCount); + final _Progress progress = _Progress(componentRoot.fileCount, quiet: quiet); final system.File outFile = system.File(outputGoldenPath); final system.IOSink sink = outFile.openWrite(); @@ -2506,9 +2512,11 @@ Future main(List arguments) async { ..addOption('src', help: 'The root of the engine source') ..addOption('out', help: 'The directory where output is written') ..addOption('golden', help: 'The directory containing golden results') + ..addFlag('quiet', help: 'If set, the diagnostic output is much less verbose') ..addFlag('release', help: 'Print output in the format used for product releases'); final ArgResults argResults = parser.parse(arguments); + final bool quiet = argResults['quiet']; final bool releaseMode = argResults['release']; if (argResults['src'] == null) { print('Flutter license script: Must provide --src directory'); @@ -2538,7 +2546,8 @@ Future main(List arguments) async { if (releaseMode) { system.stderr.writeln('Collecting licenses...'); - final _Progress progress = _Progress(root.fileCount); + system.stderr.writeln('quiet: $quiet'); + final _Progress progress = _Progress(root.fileCount, quiet: quiet); final List licenses = Set.from(root.getLicenses(progress).toList()).toList(); if (progress.hadErrors) throw 'Had failures while collecting licenses.'; @@ -2596,6 +2605,7 @@ Future main(List arguments) async { outputGoldenPath: path.join(argResults['out'], goldenFileName), writeSignature: component.io.name != 'flutter', force: forceRunAll || component.io.name == 'flutter', + quiet: quiet, ); usedGoldens.add(goldenFileName); }