Skip to content

Commit 327019e

Browse files
thefourtheyejoelostrowski
authored andcommitted
tools: rewrite check-install.sh in python
As it is, check-install.sh does not show more helpful error messages, and supporting various shells could be a problem. This patch rewrites the same in Python. This patch also enables check-imports.py in the linting process PR-URL: nodejs#6105 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 20f68c2 commit 327019e

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
639639

640640
cpplint:
641641
@$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
642+
@$(PYTHON) tools/check-imports.py
642643

643644
ifneq ("","$(wildcard tools/eslint/bin/eslint.js)")
644645
lint: jslint cpplint

tools/check-imports.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
import glob
5+
import re
6+
import sys
7+
8+
9+
def do_exist(file_name, lines, imported):
10+
if not any(not re.match('using \w+::{0};'.format(imported), line) and
11+
re.search(imported, line) for line in lines):
12+
print('File "{0}" does not use "{1}"'.format(file_name, imported))
13+
return False
14+
return True
15+
16+
17+
def is_valid(file_name):
18+
with open(file_name) as source_file:
19+
lines = [line.strip() for line in source_file]
20+
21+
usings, importeds, line_numbers, valid = [], [], [], True
22+
for idx, line in enumerate(lines, 1):
23+
matches = re.search(r'^using (\w+::(\w+));$', line)
24+
if matches:
25+
line_numbers.append(idx)
26+
usings.append(matches.group(1))
27+
importeds.append(matches.group(2))
28+
29+
valid = all([do_exist(file_name, lines, imported) for imported in importeds])
30+
31+
sorted_usings = sorted(usings, key=lambda x: x.lower())
32+
if sorted_usings != usings:
33+
print("using statements aren't sorted in '{0}'.".format(file_name))
34+
for num, actual, expected in zip(line_numbers, usings, sorted_usings):
35+
if actual != expected:
36+
print('\tLine {0}: Actual: {1}, Expected: {2}'
37+
.format(num, actual, expected))
38+
return False
39+
else:
40+
return valid
41+
42+
sys.exit(0 if all(map(is_valid, glob.iglob('src/*.cc'))) else 1)

tools/check-imports.sh

-36
This file was deleted.

0 commit comments

Comments
 (0)