Skip to content

Commit d4d44db

Browse files
authored
Merge pull request diffblue#648 from NathanJPhillips/bugfix/lint-work-across-repos
Bugfix/lint infrastructure improvements
2 parents a7663cb + 36dee83 commit d4d44db

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

scripts/cpplint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ def RepositoryName(self):
11451145
os.path.exists(os.path.join(current_dir, ".hg")) or
11461146
os.path.exists(os.path.join(current_dir, ".svn"))):
11471147
root_dir = current_dir
1148+
break;
11481149
current_dir = os.path.dirname(current_dir)
11491150

11501151
if (os.path.exists(os.path.join(root_dir, ".git")) or

scripts/filter_lint_by_diff.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
print >>sys.stderr, "Usage: filter_lint_by_diff.py diff.patch repository_root_directory < cpplint_warnings.txt"
99
sys.exit(1)
1010

11-
added_lines = set()
1211
repository_root = sys.argv[2]
1312

14-
diff = unidiff.PatchSet.from_filename(sys.argv[1])
15-
for diff_file in diff:
13+
# Create a set of all the files and the specific lines within that file that are in the diff
14+
added_lines = set()
15+
for diff_file in unidiff.PatchSet.from_filename(sys.argv[1]):
1616
filename = diff_file.target_file
1717
# Skip files deleted in the tip (b side of the diff):
1818
if filename == "/dev/null":
@@ -25,11 +25,12 @@
2525
if diff_line.line_type == "+":
2626
added_lines.add((filename, diff_line.target_line_no))
2727

28-
for l in sys.stdin:
29-
bits = l.split(":")
30-
if len(bits) < 3:
28+
# Print the lines that are in the set
29+
for line in sys.stdin:
30+
line_parts = line.split(":")
31+
if len(line_parts) < 3:
3132
continue
32-
filename = os.path.join(repository_root, bits[0])
33-
linenum = int(bits[1])
33+
filename = os.path.join(repository_root, line_parts[0])
34+
linenum = int(line_parts[1])
3435
if (filename, linenum) in added_lines:
35-
sys.stdout.write(l)
36+
sys.stdout.write(line)

scripts/run_lint.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
script_folder=`dirname $0`
6-
absolute_repository_root=`readlink -f $script_folder/..`
6+
absolute_repository_root=`git rev-parse --show-toplevel`
77

88
if [[ "$#" -gt 2 ]]
99
then
@@ -20,6 +20,13 @@ then
2020
exit 1
2121
fi
2222

23+
if ! [[ -e $script_folder/filter_lint_by_diff.py ]]
24+
then
25+
echo "Lint filter script could not be found in the $script_folder directory"
26+
echo "Ensure filter_lint_by_diff.py is inside the $script_folder directory then run again"
27+
exit 1
28+
fi
29+
2330
if [[ "$#" -gt 0 ]]
2431
then
2532
git_start=$1
@@ -62,7 +69,7 @@ for file in $diff_files; do
6269

6370
# Run the linting script and filter:
6471
# The errors from the linter go to STDERR so must be redirected to STDOUT
65-
result=`$script_folder/cpplint.py $file 2>&1 | $script_folder/filter_lint_by_diff.py $diff_file $absolute_repository_root`
72+
result=`$script_folder/cpplint.py $file 2>&1 >/dev/null | $script_folder/filter_lint_by_diff.py $diff_file $absolute_repository_root`
6673

6774
# Providing some errors were relevant we print them out
6875
if [ "$result" ]

0 commit comments

Comments
 (0)