|
@@ -590,7 +590,8 @@ class InputApi(object):
|
|
|
)
|
|
|
|
|
|
def __init__(self, change, presubmit_path, is_committing,
|
|
|
- verbose, gerrit_obj, dry_run=None, thread_pool=None, parallel=False):
|
|
|
+ verbose, gerrit_obj, dry_run=None, thread_pool=None, parallel=False,
|
|
|
+ no_diffs=False):
|
|
|
"""Builds an InputApi object.
|
|
|
|
|
|
Args:
|
|
@@ -601,6 +602,8 @@ class InputApi(object):
|
|
|
dry_run: if true, some Checks will be skipped.
|
|
|
parallel: if true, all tests reported via input_api.RunTests for all
|
|
|
PRESUBMIT files will be run in parallel.
|
|
|
+ no_diffs: if true, implies that --files or --all was specified so some
|
|
|
+ checks can be skipped, and some errors will be messages.
|
|
|
"""
|
|
|
# Version number of the presubmit_support script.
|
|
|
self.version = [int(x) for x in __version__.split('.')]
|
|
@@ -608,6 +611,7 @@ class InputApi(object):
|
|
|
self.is_committing = is_committing
|
|
|
self.gerrit = gerrit_obj
|
|
|
self.dry_run = dry_run
|
|
|
+ self.no_diffs = no_diffs
|
|
|
|
|
|
self.parallel = parallel
|
|
|
self.thread_pool = thread_pool or ThreadPool()
|
|
@@ -1493,7 +1497,8 @@ def DoPostUploadExecuter(change, gerrit_obj, verbose, use_python3=False):
|
|
|
|
|
|
class PresubmitExecuter(object):
|
|
|
def __init__(self, change, committing, verbose, gerrit_obj, dry_run=None,
|
|
|
- thread_pool=None, parallel=False, use_python3=False):
|
|
|
+ thread_pool=None, parallel=False, use_python3=False,
|
|
|
+ no_diffs=False):
|
|
|
"""
|
|
|
Args:
|
|
|
change: The Change object.
|
|
@@ -1504,6 +1509,8 @@ class PresubmitExecuter(object):
|
|
|
PRESUBMIT files will be run in parallel.
|
|
|
use_python3: if true, will use python3 instead of python2 by default
|
|
|
if USE_PYTHON3 is not specified.
|
|
|
+ no_diffs: if true, implies that --files or --all was specified so some
|
|
|
+ checks can be skipped, and some errors will be messages.
|
|
|
"""
|
|
|
self.change = change
|
|
|
self.committing = committing
|
|
@@ -1514,6 +1521,7 @@ class PresubmitExecuter(object):
|
|
|
self.thread_pool = thread_pool
|
|
|
self.parallel = parallel
|
|
|
self.use_python3 = use_python3
|
|
|
+ self.no_diffs = no_diffs
|
|
|
|
|
|
def ExecPresubmitScript(self, script_text, presubmit_path):
|
|
|
"""Executes a single presubmit script.
|
|
@@ -1537,7 +1545,7 @@ class PresubmitExecuter(object):
|
|
|
input_api = InputApi(self.change, presubmit_path, self.committing,
|
|
|
self.verbose, gerrit_obj=self.gerrit,
|
|
|
dry_run=self.dry_run, thread_pool=self.thread_pool,
|
|
|
- parallel=self.parallel)
|
|
|
+ parallel=self.parallel, no_diffs=self.no_diffs)
|
|
|
output_api = OutputApi(self.committing)
|
|
|
context = {}
|
|
|
|
|
@@ -1671,7 +1679,8 @@ def DoPresubmitChecks(change,
|
|
|
dry_run=None,
|
|
|
parallel=False,
|
|
|
json_output=None,
|
|
|
- use_python3=False):
|
|
|
+ use_python3=False,
|
|
|
+ no_diffs=False):
|
|
|
"""Runs all presubmit checks that apply to the files in the change.
|
|
|
|
|
|
This finds all PRESUBMIT.py files in directories enclosing the files in the
|
|
@@ -1694,6 +1703,8 @@ def DoPresubmitChecks(change,
|
|
|
PRESUBMIT files will be run in parallel.
|
|
|
use_python3: if true, default to using Python3 for presubmit checks
|
|
|
rather than Python2.
|
|
|
+ no_diffs: if true, implies that --files or --all was specified so some
|
|
|
+ checks can be skipped, and some errors will be messages.
|
|
|
Return:
|
|
|
1 if presubmit checks failed or 0 otherwise.
|
|
|
"""
|
|
@@ -1718,7 +1729,8 @@ def DoPresubmitChecks(change,
|
|
|
results = []
|
|
|
thread_pool = ThreadPool()
|
|
|
executer = PresubmitExecuter(change, committing, verbose, gerrit_obj,
|
|
|
- dry_run, thread_pool, parallel, use_python3)
|
|
|
+ dry_run, thread_pool, parallel, use_python3,
|
|
|
+ no_diffs)
|
|
|
skipped_count = 0;
|
|
|
if default_presubmit:
|
|
|
if verbose:
|
|
@@ -1989,6 +2001,7 @@ def main(argv=None):
|
|
|
help='Write presubmit errors to json output.')
|
|
|
parser.add_argument('--all_files', action='store_true',
|
|
|
help='Mark all files under source control as modified.')
|
|
|
+
|
|
|
parser.add_argument('files', nargs='*',
|
|
|
help='List of files to be marked as modified when '
|
|
|
'executing presubmit or post-upload hooks. fnmatch '
|
|
@@ -1997,6 +2010,8 @@ def main(argv=None):
|
|
|
help='Constrain \'files\' to those in source control.')
|
|
|
parser.add_argument('--use-python3', action='store_true',
|
|
|
help='Use python3 for presubmit checks by default')
|
|
|
+ parser.add_argument('--no_diffs', action='store_true',
|
|
|
+ help='Assume that all "modified" files have no diffs.')
|
|
|
options = parser.parse_args(argv)
|
|
|
|
|
|
log_level = logging.ERROR
|
|
@@ -2028,7 +2043,8 @@ def main(argv=None):
|
|
|
options.dry_run,
|
|
|
options.parallel,
|
|
|
options.json_output,
|
|
|
- options.use_python3)
|
|
|
+ options.use_python3,
|
|
|
+ options.no_diffs)
|
|
|
except PresubmitFailure as e:
|
|
|
import utils
|
|
|
print(e, file=sys.stderr)
|