From ffea3597f4ac7481121d0cd3abb4e67d7346c775 Mon Sep 17 00:00:00 2001 From: Oxan van Leeuwen Date: Tue, 4 Jan 2022 21:59:34 +0100 Subject: [PATCH] Set correct include_dir in platformio.ini (#2999) --- platformio.ini | 7 ++++++- script/clang-tidy | 14 +++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/platformio.ini b/platformio.ini index d26b3c9c90..1e39254434 100644 --- a/platformio.ini +++ b/platformio.ini @@ -5,8 +5,13 @@ [platformio] default_envs = esp8266, esp32, esp32-idf +; Ideally, we want src_dir to be the root directory of the repository, to mimic the runtime build +; environment as best as possible. Unfortunately, the ESP-IDF toolchain really doesn't like this +; being the root directory. Instead, set esphome/ as the source directory, all our sources are in +; there anyway. Set the root directory as the include_dir, so that the esphome/ directory is on the +; include path. src_dir = esphome -include_dir = +include_dir = . [runtime] ; This are the flags as set by the runtime. diff --git a/script/clang-tidy b/script/clang-tidy index 8ad25a3dbf..e6165ff23b 100755 --- a/script/clang-tidy +++ b/script/clang-tidy @@ -1,7 +1,7 @@ #!/usr/bin/env python3 from helpers import print_error_for_file, get_output, filter_grep, \ - build_all_include, temp_header_file, git_ls_files, filter_changed, load_idedata, basepath + build_all_include, temp_header_file, git_ls_files, filter_changed, load_idedata, root_path, basepath import argparse import click import colorama @@ -58,17 +58,21 @@ def clang_options(idedata): # defines cmd.extend(f'-D{define}' for define in idedata['defines']) - # add toolchain include directories using -isystem + # add toolchain include directories using -isystem to suppress their errors # idedata contains include directories for all toolchains of this platform, only use those from the one in use toolchain_dir = os.path.normpath(f"{idedata['cxx_path']}/../../") for directory in idedata['includes']['toolchain']: if directory.startswith(toolchain_dir): cmd.extend(['-isystem', directory]) - # add include directories, using -isystem for dependencies to suppress their errors + # add library include directories using -isystem to suppress their errors for directory in sorted(set(idedata['includes']['build'])): - dependency = "framework-arduino" in directory or "/libdeps/" in directory - cmd.extend(['-isystem' if dependency else '-I', directory]) + # skip our own directories, we add those later + if not directory.startswith(f"{root_path}/") or directory.startswith(f"{root_path}/.pio/"): + cmd.extend(['-isystem', directory]) + + # add the esphome include directory using -I + cmd.extend(['-I', root_path]) return cmd