Clang-tidy tries to analyze an STM32 assembly file located in compile_commands.json (original) (raw)
August 22, 2024, 12:59pm 1
I have an STM32 project which is compiled using CMake and generates a compile_commands.json STM32CubeMX generates an assembly file (i.e. startup_stm32f103xb.s) and adds it to the compilation database.
Whenever I run use-clang-tidy.py, it attempts to analyse that file and returns an error:
D:\git\leany\Core\startup_stm32f103xb.s:28:3: error: expected identifier or '(' [clang-diagnostic-error]
28 | .syntax unified
| ^
I’m not surprised by the error as clang tries to compile an ASM file as C, but I’m wondering if it would be possible to just ignore this file or any asm file altogether. Also, I would very much like to keep clang-tidy as a part of my CI/CD procedures, as I want to keep my own code (located in Components/) as clean as possible. Also, I cannot touch the files generated by STM32CubeMX, neither can I touch the CMake files it creates.
Here is the codebase : Github
I’ve tried to create a .clang-tidy file at the root of the project with the mention ‘Checks: “-*”’, but it just cancels all checks altogether, including the ones located in Components/
I’ve also tried adding HeaderFileExtensions
and ImplementationFileExtensions
sections in it to consider only *.h and *.c files, but this doesn’t change anything
nicovank August 22, 2024, 4:47pm 2
Seems like you are using the run-clang-tidy-14 script to run it on everything in the compilation database. There’s been some updates since clang-tidy-14
but you should be able to use the files
argument to make a regular expression of files to match. It uses Python regular expressions so it supports negative lookahead/lookbehind.
Adding something like .*(?<!\.s)$
to your invocation should ignore any .s
files for example. Or you could match files only ending in .c
/.cpp
.
That completely fixed the issue! Thanks
From the documentation, I did not understand [files …] was an actual argument.
nicovank August 22, 2024, 7:49pm 4
Great!
I agree it’s not very clear, what it really is is a list of regular expressions used to filter the filenames present in the compile_commands.json
. In the current version of the script there is a (redundant but maybe better named) -source-filter
argument that can be used the achieve the same thing.
I’m using it in a Github Action which installs it via aptitude and runs it via commandline. I don’t have any say in which version is installed. Good to know, however
5chmidti August 29, 2024, 4:56pm 6