1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-01 19:02:18 +01:00

Run clang-tidy against ESP32 (#2147)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: Otto winter <otto@otto-winter.com>
This commit is contained in:
Oxan van Leeuwen
2021-09-13 18:11:27 +02:00
committed by GitHub
parent a2d2863c72
commit 40c474cd83
74 changed files with 291 additions and 364 deletions

View File

@@ -16,7 +16,7 @@ import click
import pexpect
sys.path.append(os.path.dirname(__file__))
from helpers import shlex_quote, get_output, \
from helpers import shlex_quote, get_output, filter_grep, \
build_all_include, temp_header_file, git_ls_files, filter_changed, load_idedata
@@ -27,13 +27,15 @@ def clang_options(idedata):
# disable built-in include directories from the host
'-nostdinc',
'-nostdinc++',
# pretend we're an Xtensa compiler, which gates some features in the headers
'-D__XTENSA__',
# allow to condition code on the presence of clang-tidy
'-DCLANG_TIDY'
]
# copy compiler flags, except those clang doesn't understand.
cmd.extend(flag for flag in idedata['cxx_flags'].split(' ')
if flag not in ('-free', '-fipa-pta', '-mlongcalls', '-mtext-section-literals'))
if flag not in ('-free', '-fipa-pta', '-fstrict-volatile-bitfields', '-mlongcalls', '-mtext-section-literals'))
# defines
cmd.extend(f'-D{define}' for define in idedata['defines'])
@@ -97,6 +99,8 @@ def main():
parser.add_argument('-j', '--jobs', type=int,
default=multiprocessing.cpu_count(),
help='number of tidy instances to be run in parallel.')
parser.add_argument('-e', '--environment', default='esp8266-tidy',
help='the PlatformIO environment to run against (esp8266-tidy or esp32-tidy)')
parser.add_argument('files', nargs='*', default=[],
help='files to be processed (regex on path)')
parser.add_argument('--fix', action='store_true', help='apply fix-its')
@@ -104,6 +108,7 @@ def main():
help='run clang-tidy in quiet mode')
parser.add_argument('-c', '--changed', action='store_true',
help='only run on changed files')
parser.add_argument('-g', '--grep', help='only run on files containing value')
parser.add_argument('--split-num', type=int, help='split the files into X jobs.',
default=None)
parser.add_argument('--split-at', type=int, help='which split is this? starts at 1',
@@ -126,7 +131,7 @@ def main():
""")
return 1
idedata = load_idedata("esp8266-tidy")
idedata = load_idedata(args.environment)
options = clang_options(idedata)
files = []
@@ -141,6 +146,9 @@ def main():
if args.changed:
files = filter_changed(files)
if args.grep:
files = filter_grep(files, args.grep)
files.sort()
if args.split_num:

View File

@@ -92,6 +92,16 @@ def filter_changed(files):
return files
def filter_grep(files, value):
matched = []
for file in files:
with open(file, "r") as handle:
contents = handle.read()
if value in contents:
matched.append(file)
return matched
def git_ls_files(patterns=None):
command = ["git", "ls-files", "-s"]
if patterns is not None: