mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
Make CheckLicense warn locally
Only emit errors on standard CQ runs. Keep as warning for local runs to reduce friction, and for full-tree CI checks to avoid breakage from legacy files. Bug: 454681814 Change-Id: I621ecc75cf5df40e4fd33ff439bfdc4f4c62e4fa Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7092462 Reviewed-by: Scott Lee <ddoman@chromium.org> Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
@@ -847,12 +847,12 @@ def CheckLicense(input_api,
|
||||
bad_files.append(f.LocalPath())
|
||||
results = []
|
||||
|
||||
# Don't report errors when on the presubmit --all bot or when testing with
|
||||
# presubmit --files.
|
||||
if input_api.no_diffs:
|
||||
report_type = output_api.PresubmitPromptWarning
|
||||
else:
|
||||
# Fail on CQ when checking diffs.
|
||||
# Warn locally or when checking the whole tree (due to legacy headers).
|
||||
if input_api.is_committing and not input_api.no_diffs:
|
||||
report_type = output_api.PresubmitError
|
||||
else:
|
||||
report_type = output_api.PresubmitPromptWarning
|
||||
|
||||
if bad_new_files:
|
||||
if license_re_param:
|
||||
|
||||
@@ -2801,7 +2801,7 @@ the current line as well!
|
||||
presubmit.OutputApi.PresubmitError,
|
||||
description=description)
|
||||
|
||||
def testCheckLicenseFailUpload(self):
|
||||
def testCheckLicenseWarnUpload(self):
|
||||
text = ("#!/bin/python\n"
|
||||
"# Copyright (c) 2037 Nobody.\n"
|
||||
"# All Rights Reserved.\n"
|
||||
@@ -2809,7 +2809,7 @@ the current line as well!
|
||||
license_text = (r".*? Copyright \(c\) 0007 Nobody.\n"
|
||||
r".*? All Rights Reserved\.\n")
|
||||
self._LicenseCheck(text, license_text, False,
|
||||
presubmit.OutputApi.PresubmitError)
|
||||
presubmit.OutputApi.PresubmitPromptWarning)
|
||||
|
||||
def testCheckLicenseEmptySuccess(self):
|
||||
text = ''
|
||||
@@ -2826,8 +2826,8 @@ the current line as well!
|
||||
license_text = None
|
||||
self._LicenseCheck(text, license_text, False, None, new_file=True)
|
||||
|
||||
def testCheckLicenseNewFileFail(self):
|
||||
# Check that we fail on new files with the (c) symbol.
|
||||
def testCheckLicenseNewFileWarnUpload(self):
|
||||
# Check that we warn on uploading new files with the (c) symbol.
|
||||
current_year = int(time.strftime('%Y'))
|
||||
text = (
|
||||
"#!/bin/python\n"
|
||||
@@ -2840,6 +2840,23 @@ the current line as well!
|
||||
self._LicenseCheck(text,
|
||||
license_text,
|
||||
False,
|
||||
presubmit.OutputApi.PresubmitPromptWarning,
|
||||
new_file=True)
|
||||
|
||||
def testCheckLicenseNewFileFailCommit(self):
|
||||
# Check that we fail on committing new files with the (c) symbol.
|
||||
current_year = int(time.strftime('%Y'))
|
||||
text = (
|
||||
"#!/bin/python\n"
|
||||
"# Copyright (c) %d The Chromium Authors\n"
|
||||
"# Use of this source code is governed by a BSD-style license that can "
|
||||
"be\n"
|
||||
"# found in the LICENSE file.\n"
|
||||
"print('foo')\n" % current_year)
|
||||
license_text = None
|
||||
self._LicenseCheck(text,
|
||||
license_text,
|
||||
True,
|
||||
presubmit.OutputApi.PresubmitError,
|
||||
new_file=True)
|
||||
|
||||
@@ -2852,14 +2869,25 @@ the current line as well!
|
||||
"# found in the LICENSE file.\n"
|
||||
"print('foo')\n" % current_year)
|
||||
|
||||
def testCheckLicenseNewFileError(self):
|
||||
# Check that we error on new files with wrong year. Test with first
|
||||
# allowed year.
|
||||
def testCheckLicenseNewFileWarnWrongYear(self):
|
||||
# Check that we warn on uploading new files with wrong year. Test with
|
||||
# first allowed year.
|
||||
text = self._GetLicenseText(2006)
|
||||
license_text = None
|
||||
self._LicenseCheck(text,
|
||||
license_text,
|
||||
False,
|
||||
presubmit.OutputApi.PresubmitPromptWarning,
|
||||
new_file=True)
|
||||
|
||||
def testCheckLicenseNewFileErrorCommit(self):
|
||||
# Check that we error on committing new files with wrong year. Test with
|
||||
# first allowed year.
|
||||
text = self._GetLicenseText(2006)
|
||||
license_text = None
|
||||
self._LicenseCheck(text,
|
||||
license_text,
|
||||
True,
|
||||
presubmit.OutputApi.PresubmitError,
|
||||
new_file=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user