mirror of
https://github.com/esphome/esphome.git
synced 2025-09-01 19:02:18 +01:00
Lint
This commit is contained in:
@@ -7,6 +7,7 @@ import sys
|
||||
|
||||
root_path = os.path.abspath(os.path.normpath(os.path.join(__file__, '..', '..')))
|
||||
basepath = os.path.join(root_path, 'esphome')
|
||||
temp_header_file = os.path.join(root_path, '.temp-clang-tidy.cpp')
|
||||
|
||||
|
||||
def walk_files(path):
|
||||
@@ -24,6 +25,24 @@ def shlex_quote(s):
|
||||
return u"'" + s.replace(u"'", u"'\"'\"'") + u"'"
|
||||
|
||||
|
||||
def build_all_include():
|
||||
# Build a cpp file that includes all header files in this repo.
|
||||
# Otherwise header-only integrations would not be tested by clang-tidy
|
||||
headers = []
|
||||
for path in walk_files(basepath):
|
||||
filetypes = ('.h',)
|
||||
ext = os.path.splitext(path)[1]
|
||||
if ext in filetypes:
|
||||
path = os.path.relpath(path, root_path)
|
||||
include_p = path.replace(os.path.sep, '/')
|
||||
headers.append('#include "{}"'.format(include_p))
|
||||
headers.sort()
|
||||
headers.append('')
|
||||
content = '\n'.join(headers)
|
||||
with codecs.open(temp_header_file, 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
|
||||
|
||||
def build_compile_commands():
|
||||
gcc_flags_json = os.path.join(root_path, '.gcc-flags.json')
|
||||
if not os.path.isfile(gcc_flags_json):
|
||||
@@ -52,6 +71,7 @@ def build_compile_commands():
|
||||
ext = os.path.splitext(path)[1]
|
||||
if ext in filetypes:
|
||||
source_files.append(os.path.abspath(path))
|
||||
source_files.append(temp_header_file)
|
||||
source_files.sort()
|
||||
compile_commands = [{
|
||||
'directory': root_path,
|
||||
@@ -71,6 +91,7 @@ def build_compile_commands():
|
||||
|
||||
|
||||
def main():
|
||||
build_all_include()
|
||||
build_compile_commands()
|
||||
print("Done.")
|
||||
|
||||
|
@@ -264,8 +264,6 @@ def main():
|
||||
print('Ctrl-C detected, goodbye.')
|
||||
if tmpdir:
|
||||
shutil.rmtree(tmpdir)
|
||||
if os.path.exists(temp_header_file):
|
||||
os.remove(temp_header_file)
|
||||
os.kill(0, 9)
|
||||
|
||||
if args.fix and failed_files:
|
||||
@@ -274,12 +272,8 @@ def main():
|
||||
subprocess.call(['clang-apply-replacements-7', tmpdir])
|
||||
except:
|
||||
print('Error applying fixes.\n', file=sys.stderr)
|
||||
if os.path.exists(temp_header_file):
|
||||
os.remove(temp_header_file)
|
||||
raise
|
||||
|
||||
if os.path.exists(temp_header_file):
|
||||
os.remove(temp_header_file)
|
||||
sys.exit(return_code)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user