mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
3fdff8880a
Summary: we weren't matching this pattern: ``` $ ./scripts/lint.py +++ /data/users/wez/facebook-hg-rpms/fb-hgext/tests/test-check-code-hg.t.err @@ -37,6 +37,8 @@ Skipping fastmanifest/tree_copy_test.c it has no-che?k-code (glob) Skipping fastmanifest/tree_diff.c it has no-che?k-code (glob) Skipping fastmanifest/tree_diff_test.c it has no-che?k-code (glob) + Skipping fastmanifest/tree_disk.c it has no-che?k-code (glob) + Skipping fastmanifest/tree_disk_test.c it has no-che?k-code (glob) Skipping fastmanifest/tree_iterate_rt.c it has no-che?k-code (glob) Skipping fastmanifest/tree_iterator.c it has no-che?k-code (glob) Skipping fastmanifest/tree_iterator.h it has no-che?k-code (glob) ERROR: test-check-code-hg.t output changed ! Failed test-check-code-hg.t: output changed # Ran 1 tests, 0 skipped, 0 warned, 1 failed. python hash seed: 583073521 ``` Due to the way that arc lint works, we have to associate the linter issue with the files that changed in the diff, but we don't have an easy way to figure out the line number where the `no-check-code` line was added, so we just use line number 0. Test Plan: `arc patch D3236640` and `arc lint`: ``` $ arc lint --everything >>> Lint for fastmanifest/tree_disk.c: Error (S&RX) CheckCode Update tests/test-check-code-hg.t to add Skipping fastmanifest/tree_disk.c it has no-che?k-code (glob) >>> 1 // Copyright 2016-present Facebook. All Rights Reserved. 2 // 3 // tree_disk.c: methods to persist to and restore from disk. 4 // >>> Lint for fastmanifest/tree_disk_test.c: Error (S&RX) CheckCode Update tests/test-check-code-hg.t to add Skipping fastmanifest/tree_disk_test.c it has no-che?k-code (glob) >>> 1 // Copyright 2016-present Facebook. All Rights Reserved. 2 // 3 // tree_disk_test.c: tests to verify tree_disk 4 // ``` Reviewers: #sourcecontrol, ttung, lcharignon Reviewed By: lcharignon Subscribers: lcharignon, mjpieters Differential Revision: https://phabricator.intern.facebook.com/D3237054 Signature: t1:3237054:1461949072:ac7cc29fcee9dbc00a4019088f3adb50de9625bf
90 lines
2.6 KiB
Python
Executable File
90 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python
|
|
import errno
|
|
import os
|
|
import subprocess
|
|
import re
|
|
import sys
|
|
|
|
""" Convert mercurial check-code errors into a format
|
|
that plays nicely with arc lint """
|
|
|
|
runner = os.environ.get('MERCURIALRUNTEST', 'run-tests.py')
|
|
|
|
if not os.path.exists(runner):
|
|
# If it looks like we're in facebook-hg-rpms, let's try
|
|
# running against the associated hg-crew tests
|
|
# otherwise, Popen will search for run-tests.py in the PATH
|
|
default_runner = os.path.relpath('../hg-crew/tests/run-tests.py')
|
|
if os.path.exists(default_runner):
|
|
runner = os.path.abspath(default_runner)
|
|
|
|
# Normalize the list of files that we should report on
|
|
wanted = set()
|
|
for path in sys.argv[1:]:
|
|
wanted.add(os.path.relpath(path))
|
|
|
|
try:
|
|
args = [runner, '-j8', '-l', 'test-check-code-hg.t']
|
|
|
|
# Check lz4revlog requirement
|
|
reporoot = os.path.join(os.path.dirname(os.path.dirname(__file__)), '.hg')
|
|
with open(os.path.join(reporoot, 'requires'), 'r') as f:
|
|
if 'lz4revlog\n' in f:
|
|
args.append('--extra-config-opt=extensions.lz4revlog=')
|
|
|
|
proc = subprocess.Popen(args, stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE, cwd='tests')
|
|
except OSError as ex:
|
|
if ex.errno == errno.ENOENT:
|
|
print 'lint.py:1: ERROR:ENVIRON: Please either set ' + \
|
|
'MERCURIALRUNTEST var to the full path to run-tests.py, ' + \
|
|
'or add the containing directory to your $PATH'
|
|
else:
|
|
print 'lint.py:1: ERROR:OSError: %s: %s' % (runner, str(ex))
|
|
sys.exit(0)
|
|
|
|
output, error = proc.communicate()
|
|
|
|
context_file = None
|
|
lines = error.split('\n')
|
|
# We expect a run of 3 lines to describe the error, with the first
|
|
# of those to look like a filename and line number location
|
|
while lines:
|
|
line = lines[0]
|
|
lines.pop(0)
|
|
|
|
if re.match('^--- (.*)$', line):
|
|
context_file = os.path.relpath(line[4:])
|
|
continue
|
|
|
|
m = re.match('^\+ (Skipping (.*) it has no.*)$', line)
|
|
if m:
|
|
filename = m.group(2)
|
|
if filename in wanted:
|
|
print '%s:0: ERROR:CheckCode: Update %s to add %s' % (
|
|
filename, context_file, m.group(1))
|
|
continue
|
|
|
|
if not re.match('^\+ +[a-zA-Z0-9_./-]+:\d+:$', line):
|
|
continue
|
|
|
|
if len(lines) < 2:
|
|
continue
|
|
|
|
location = line
|
|
context = lines.pop(0) # we ignore this
|
|
why = lines.pop(0)
|
|
|
|
location = location[1:].strip() # strip off the "+ " bit
|
|
location = location.rstrip(':')
|
|
filename, lineno = location.split(':')
|
|
|
|
if filename not in wanted:
|
|
# lint doesn't care about this file.
|
|
continue
|
|
|
|
why = why[1:].strip()
|
|
|
|
print '%s: ERROR:CheckCode: %s' % (location, why)
|
|
|