From fadcbfdb279278e98a598f5384d2d29ac01fb8d1 Mon Sep 17 00:00:00 2001 From: "mark a. foltz" Date: Thu, 17 Nov 2022 05:44:39 +0000 Subject: [PATCH] [depot_tools] Adds a better error message for copyright header checks. The current message prints a regular expression. This new message prints the correct copyright header which can be copy-pasted into new files. Bug: 1376752 Change-Id: Ifb03924641ad75d2b58158a752e0a62648436edc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4032368 Commit-Queue: Mark Foltz Reviewed-by: Bruce Dawson --- presubmit_canned_checks.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 623eed20f..659bb6cf4 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -730,11 +730,25 @@ def CheckLicense(input_api, output_api, license_re_param=None, bad_files.append(f.LocalPath()) results = [] if bad_new_files: - results.append( - output_api.PresubmitError( - 'License on new files must match:\n%s\n\n' % new_license_re.pattern - + 'Found a bad license header in these new files:', - items=bad_new_files)) + if license_re_param: + error_message = ('License on new files must match:\n\n%s\n' % + license_re_param) + else: + # Verbatim text that can be copy-pasted into new files (possibly adjusting + # the leading comment delimiter). + new_license_text = ('// Copyright %(year)s The %(project)s Authors\n' + '// %(key_line)s\n' + '// found in the LICENSE file.\n') % { + 'year': current_year, + 'project': project_name, + 'key_line': key_line, + } + error_message = ( + 'License on new files must be:\n\n%s\n' % new_license_text + + '(adjusting the comment delimiter accordingly).\n\n') + error_message += 'Found a bad license header in these new files:' + results.append(output_api.PresubmitError(error_message, + items=bad_new_files)) if wrong_year_new_files: # We can't distinguish between new and moved files, so this has to be a # warning rather than an error.