mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +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())
|
bad_files.append(f.LocalPath())
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
# Don't report errors when on the presubmit --all bot or when testing with
|
# Fail on CQ when checking diffs.
|
||||||
# presubmit --files.
|
# Warn locally or when checking the whole tree (due to legacy headers).
|
||||||
if input_api.no_diffs:
|
if input_api.is_committing and not input_api.no_diffs:
|
||||||
report_type = output_api.PresubmitPromptWarning
|
|
||||||
else:
|
|
||||||
report_type = output_api.PresubmitError
|
report_type = output_api.PresubmitError
|
||||||
|
else:
|
||||||
|
report_type = output_api.PresubmitPromptWarning
|
||||||
|
|
||||||
if bad_new_files:
|
if bad_new_files:
|
||||||
if license_re_param:
|
if license_re_param:
|
||||||
|
|||||||
@@ -2801,7 +2801,7 @@ the current line as well!
|
|||||||
presubmit.OutputApi.PresubmitError,
|
presubmit.OutputApi.PresubmitError,
|
||||||
description=description)
|
description=description)
|
||||||
|
|
||||||
def testCheckLicenseFailUpload(self):
|
def testCheckLicenseWarnUpload(self):
|
||||||
text = ("#!/bin/python\n"
|
text = ("#!/bin/python\n"
|
||||||
"# Copyright (c) 2037 Nobody.\n"
|
"# Copyright (c) 2037 Nobody.\n"
|
||||||
"# All Rights Reserved.\n"
|
"# All Rights Reserved.\n"
|
||||||
@@ -2809,7 +2809,7 @@ the current line as well!
|
|||||||
license_text = (r".*? Copyright \(c\) 0007 Nobody.\n"
|
license_text = (r".*? Copyright \(c\) 0007 Nobody.\n"
|
||||||
r".*? All Rights Reserved\.\n")
|
r".*? All Rights Reserved\.\n")
|
||||||
self._LicenseCheck(text, license_text, False,
|
self._LicenseCheck(text, license_text, False,
|
||||||
presubmit.OutputApi.PresubmitError)
|
presubmit.OutputApi.PresubmitPromptWarning)
|
||||||
|
|
||||||
def testCheckLicenseEmptySuccess(self):
|
def testCheckLicenseEmptySuccess(self):
|
||||||
text = ''
|
text = ''
|
||||||
@@ -2826,8 +2826,8 @@ the current line as well!
|
|||||||
license_text = None
|
license_text = None
|
||||||
self._LicenseCheck(text, license_text, False, None, new_file=True)
|
self._LicenseCheck(text, license_text, False, None, new_file=True)
|
||||||
|
|
||||||
def testCheckLicenseNewFileFail(self):
|
def testCheckLicenseNewFileWarnUpload(self):
|
||||||
# Check that we fail on new files with the (c) symbol.
|
# Check that we warn on uploading new files with the (c) symbol.
|
||||||
current_year = int(time.strftime('%Y'))
|
current_year = int(time.strftime('%Y'))
|
||||||
text = (
|
text = (
|
||||||
"#!/bin/python\n"
|
"#!/bin/python\n"
|
||||||
@@ -2840,6 +2840,23 @@ the current line as well!
|
|||||||
self._LicenseCheck(text,
|
self._LicenseCheck(text,
|
||||||
license_text,
|
license_text,
|
||||||
False,
|
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,
|
presubmit.OutputApi.PresubmitError,
|
||||||
new_file=True)
|
new_file=True)
|
||||||
|
|
||||||
@@ -2852,14 +2869,25 @@ the current line as well!
|
|||||||
"# found in the LICENSE file.\n"
|
"# found in the LICENSE file.\n"
|
||||||
"print('foo')\n" % current_year)
|
"print('foo')\n" % current_year)
|
||||||
|
|
||||||
def testCheckLicenseNewFileError(self):
|
def testCheckLicenseNewFileWarnWrongYear(self):
|
||||||
# Check that we error on new files with wrong year. Test with first
|
# Check that we warn on uploading new files with wrong year. Test with
|
||||||
# allowed year.
|
# first allowed year.
|
||||||
text = self._GetLicenseText(2006)
|
text = self._GetLicenseText(2006)
|
||||||
license_text = None
|
license_text = None
|
||||||
self._LicenseCheck(text,
|
self._LicenseCheck(text,
|
||||||
license_text,
|
license_text,
|
||||||
False,
|
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,
|
presubmit.OutputApi.PresubmitError,
|
||||||
new_file=True)
|
new_file=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user