I have built a code analysis tool using Clang that is intended to perform various checks on the first-party code in our ESP project (variable naming based on the type, function naming, etc.). In order for this tool to work correctly, it needs to be given the include directories for all of the ESP-IDF components so that it is able to resolve any necessary includes to these files in the code.
I have had a look at the ESP-IDF build system, and can see that it determines the component include directories using cmake and CMakeLists files. Is there something I can run using cmake to determine all of the component include directories and maybe output them to a file so that I can use that to run my tool? Note that I don't want my tool to be run as part of the build process, I just need to determine the component include directories that ESP-IDF uses when it builds projects.
Thanks.
How to determine all ESP-IDF component include directories for running a code analysis tool
-
- Posts: 9
- Joined: Wed Jul 27, 2022 7:43 am
Re: How to determine all ESP-IDF component include directories for running a code analysis tool
Hi steaky1212,
This can be done using CMake generator expressions.
I don't have a standalone example, but here is a line from the component i was reviewing the other day:
https://github.com/espressif/idf-extra- ... 807c677R10
(Here "eigen" should be replaced with the name of the component.)
As a result, "includes" variable will contain a CMake generator expression. You can't print it using "message", but you can, for example, output it to a file using file(GENERATE ...) CMake command.
This all doesn't require building the project, just doing the CMake configuration step (i.e. "idf.py reconfigure") is enough.
This can be done using CMake generator expressions.
I don't have a standalone example, but here is a line from the component i was reviewing the other day:
https://github.com/espressif/idf-extra- ... 807c677R10
Code: Select all
set(idf_include_directories $<TARGET_PROPERTY:idf::eigen,INCLUDE_DIRECTORIES>)
set(includes "-I$<JOIN:${idf_include_directories}, -I>")
As a result, "includes" variable will contain a CMake generator expression. You can't print it using "message", but you can, for example, output it to a file using file(GENERATE ...) CMake command.
This all doesn't require building the project, just doing the CMake configuration step (i.e. "idf.py reconfigure") is enough.
Re: How to determine all ESP-IDF component include directories for running a code analysis tool
I don't know how your analysis tool works so I'm not sure if this will help you but 'idf.py reconfigure' also produces a compile_commands.json file in the build directory which you can use with clangd. There's also an xtensa-clang package you can install that has a clangd updated for the xtensa platform. To install it, run './install.sh xtensa-clang' in your esp-idf directory.
Re: How to determine all ESP-IDF component include directories for running a code analysis tool
Good point gtjoseph, pulling the list of include directories from compile_commands.json is also a nice way to do this!
-
- Posts: 9
- Joined: Wed Jul 27, 2022 7:43 am
Re: How to determine all ESP-IDF component include directories for running a code analysis tool
Apologies for the late reply, just getting around to this now.
Thanks both for your suggestions, my tool works with both of them. However, there is an include of a "../hal.h" file in one of the IDF source files which cannot be resolved and thus causes an error to be produced in my tool. I've searched in the IDF directory and there is no file called hal.h that would be reachable from a subfolder, so I'm not sure how to fix this issue. Any ideas? The full error is below:
Thanks both for your suggestions, my tool works with both of them. However, there is an include of a "../hal.h" file in one of the IDF source files which cannot be resolved and thus causes an error to be produced in my tool. I've searched in the IDF directory and there is no file called hal.h that would be reachable from a subfolder, so I'm not sure how to fix this issue. Any ideas? The full error is below:
Code: Select all
In file included from C:\Users\Henry\Documents\EspressifIDE\Project\main.c:15:
In file included from C:/Tools/Espressif/frameworks/esp-idf-v4.4.2/components/freertos/include\freertos/FreeRTOS.h:57:
In file included from C:/Tools/Espressif/frameworks/esp-idf-v4.4.2/components/freertos/include/esp_additions/freertos\FreeRTOSConfig.h:79:
In file included from C:/Tools/Espressif/frameworks/esp-idf-v4.4.2/components/freertos/port/xtensa/include\freertos/FreeRTOSConfig_arch.h:103:
In file included from C:/Tools/Espressif/frameworks/esp-idf-v4.4.2/components/freertos/port/xtensa/include\freertos/xtensa_config.h:41:
C:/Tools/Espressif/frameworks/esp-idf-v4.4.2/components/xtensa/esp32s3/include\xtensa/config/core.h:44:10: fatal error: '../hal.h' file not found
#include "../hal.h"
Re: How to determine all ESP-IDF component include directories for running a code analysis tool
At first I was thinking "Hey wait, there are suspicious backslashes in the paths!". Then I realized: Windows
If you look in ./components/xtensa/esp32s3/include/xtensa/config/core.h you'll notice that hal.h is only referenced as "../hal.h" when __XTENSA__ is NOT defined otherwise it's referenced as "<xtensa/hal.h>". Are you using the generic c-preprocessor (cpp) by any chance? If so, you should use the xtensa-specific one installed by the esp-idf. Under Linux it'd look something like...
or if you have the xtensa-clang tools installed...
Not sure under Windows.
BTW, you can't use the generic cpp just by defining -D__XTENSA__. There's a lot more to it.
If you look in ./components/xtensa/esp32s3/include/xtensa/config/core.h you'll notice that hal.h is only referenced as "../hal.h" when __XTENSA__ is NOT defined otherwise it's referenced as "<xtensa/hal.h>". Are you using the generic c-preprocessor (cpp) by any chance? If so, you should use the xtensa-specific one installed by the esp-idf. Under Linux it'd look something like...
Code: Select all
/home/<user>/.espressif/tools/xtensa-esp32s3-elf/esp-2022r1-11.2.0/xtensa-esp32s3-elf/bin/xtensa-esp32s3-elf-cpp
Code: Select all
/home/<user>/.espressif/tools/xtensa-esp32s3-elf/esp-2022r1-11.2.0/xtensa-esp32s3-elf/bin/xtensa-esp32s3-elf-cpp
BTW, you can't use the generic cpp just by defining -D__XTENSA__. There's a lot more to it.
-
- Posts: 9
- Joined: Wed Jul 27, 2022 7:43 am
Re: How to determine all ESP-IDF component include directories for running a code analysis tool
Thanks gtjoseph. Do you know how I can call the standard GCC executable (I'm using Clang but that's just a drop-in-replacement for GCC so should be the same) and tell it to use this ESP-specific preprocessor executable? From what I can see I'm supposed to be using the -no-integrated-cpp and -B flags but I haven't had any success getting it to work.
Who is online
Users browsing this forum: Baidu [Spider] and 157 guests