Giter VIP home page Giter VIP logo

clang-tidy-runner's People

Contributors

dobairoland avatar hfudev avatar igrr avatar peterdragun avatar radimkarnis avatar vojtechbartoska avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

clang-tidy-runner's Issues

Minimum IDF version? (RDT-208)

I followed the instructions at

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-clang-tidy.html

but I don't get the new idf.py commands at all. I don't have (or want) the clang toolchain, so I copied run-clang-tidy.py and clang-tidy-diff.py into /usr/local/bin so they're on the path. If I run "idf_clang_tidy ." manually, I just get thousands of errors in the libraries, e.g.:

/home/lee/.espressif/tools/xtensa-clang/12.0.1-d9341b81fc/xtensa-esp32-elf-clang/bin/clang-tidy -header-filter=.*\..* 
-checks=-*,clang-analyzer-core.NullDereference,clang-analyzer-unix.*,bugprone-*,-bugprone-macro-
parentheses,readability-*,performance-*,-readability-magic-numbers,-readability-avoid-const-params-in-decls
-p=/home/lee/work/fw_esp32_all/build /home/lee/esp/v4.4/components/esp_lcd/src/esp_lcd_panel_io.c
/home/lee/esp/v4.4/components/esp_common/include/esp_compiler.h:15:9: warning: declaration uses identifier
'__ESP_COMPILER_H', which is a reserved identifier [bugprone-reserved-identifier]
#define __ESP_COMPILER_H

I'm running Ubuntu 20.04 (soon to upgrade to 22.04), esp-idf release/v4.4.

Does this tool require 4.5? I haven't migrated by codebase yet, so if it does I won't be able to use it. Is there a command-line I can use with "idf_clang_tidy" that will work?

Value error when passing clang-tidy config file in `--run-clang-tidy-options` (RDT-287)

Runner raises a value error when passing "-config-file .clang-tidy" in --run-clang-tidy-options.

Looks like https://github.com/espressif/clang-tidy-runner/blob/master/pyclang/runner.py#L305 is checking for "Enabled checks" in the warning.txt file, but in this case the file is empty.

Here's the shell command and output (I excluded the unrelated build and reconfigure output).

$ idf.py clang-check --run-clang-tidy-py tools/clang-tidy/run-clang-tidy.py --run-clang-tidy-options "-config-file .clang-tidy"
...
run command: /Users/jonathan/.espressif/python_env/idf4.4_py3.10_env/bin/python /Users/jonathan/src/revlytics-firmware/tools/clang-tidy/run-clang-tidy.py .* -config-file .clang-tidy || true
Traceback (most recent call last):
  File "/Users/jonathan/.esp/esp-idf/tools/idf.py", line 816, in <module>
    main()
  File "/Users/jonathan/.esp/esp-idf/tools/idf.py", line 734, in main
    cli(sys.argv[1:], prog_name=PROG, complete_var='_IDF.PY_COMPLETE')
  File "/Users/jonathan/.espressif/python_env/idf4.4_py3.10_env/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/jonathan/.espressif/python_env/idf4.4_py3.10_env/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/jonathan/.espressif/python_env/idf4.4_py3.10_env/lib/python3.10/site-packages/click/core.py", line 1689, in invoke
    return _process_result(rv)
  File "/Users/jonathan/.espressif/python_env/idf4.4_py3.10_env/lib/python3.10/site-packages/click/core.py", line 1626, in _process_result
    value = ctx.invoke(self._result_callback, value, **ctx.params)
  File "/Users/jonathan/.espressif/python_env/idf4.4_py3.10_env/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/jonathan/.esp/esp-idf/tools/idf.py", line 636, in execute_tasks
    task(ctx, global_args, task.action_args)
  File "/Users/jonathan/.esp/esp-idf/tools/idf.py", line 217, in __call__
    self.callback(self.name, context, global_args, **action_args)
  File "/Users/jonathan/.espressif/python_env/idf4.4_py3.10_env/lib/python3.10/site-packages/pyclang/idf_extension.py", line 25, in call_runner
    runner()
  File "/Users/jonathan/.espressif/python_env/idf4.4_py3.10_env/lib/python3.10/site-packages/pyclang/runner.py", line 169, in __call__
    self._run(folder, log_fs, output_dir)
  File "/Users/jonathan/.espressif/python_env/idf4.4_py3.10_env/lib/python3.10/site-packages/pyclang/runner.py", line 140, in _run
    func(folder, log_fs, output_dir)
  File "/Users/jonathan/.espressif/python_env/idf4.4_py3.10_env/lib/python3.10/site-packages/pyclang/runner.py", line 183, in _f
    return func(self, *args, **kwargs)
  File "/Users/jonathan/.espressif/python_env/idf4.4_py3.10_env/lib/python3.10/site-packages/pyclang/runner.py", line 306, in run_clang_tidy
    raise ValueError(first_line)
ValueError

header files not found with esp32s3 target. (RDT-228)

If I run

idf.py set-target esp32s3
idf.py clang-check

I get various errors like this:

/Users/cody/.espressif/tools/xtensa-clang/12.0.1-d9341b81fc/xtensa-esp32-elf-clang/bin/clang-tidy -p=/Users/cody/src/ccutrer-esp32/build /Users/cody/src/ccutrer-esp32/main/main.c
/Users/cody/src/esp-idf/components/esp_common/include/esp_err.h:10:10: error: 'stdio.h' file not found [clang-diagnostic-error]
#include <stdio.h>

But if I then run

idf.py set-target esp32
idf.py clang-check

it works without error.

error: `machine/endian.h` file not found while running clang-tidy against hello-world example (IDFGH-10703)

While using esp-idf release/v5.1 and it's hello-world example project, running idf.py clang-check on it returns the following error.

stdout
/opt/esp/idf/tools/check_python_dependencies.py:12: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
Executing action: clang-check
Running command: "/opt/esp/python_env/idf5.1_py3.8_env/bin/python /opt/esp/idf/tools/idf.py -B build reconfigure"...
Executing action: reconfigure
Running cmake in directory /opt/esp/idf/examples/get-started/hello_world/build
Executing "cmake -G Ninja -DPYTHON_DEPS_CHECKED=1 -DPYTHON=/opt/esp/python_env/idf5.1_py3.8_env/bin/python -DESP_PLATFORM=1 -DCCACHE_ENABLE=1 /opt/esp/idf/examples/get-started/hello_world"...
-- ccache will be used for faster recompilation
-- Building ESP-IDF components for target esp32
-- Project sdkconfig file /opt/esp/idf/examples/get-started/hello_world/sdkconfig
-- App "hello_world" version: v5.1-231-ga7b62bbcaf
-- Adding linker script /opt/esp/idf/examples/get-started/hello_world/build/esp-idf/esp_system/ld/memory.ld
-- Adding linker script /opt/esp/idf/components/esp_system/ld/esp32/sections.ld.in
-- Adding linker script /opt/esp/idf/components/esp_rom/esp32/ld/esp32.rom.ld
-- Adding linker script /opt/esp/idf/components/esp_rom/esp32/ld/esp32.rom.api.ld
-- Adding linker script /opt/esp/idf/components/esp_rom/esp32/ld/esp32.rom.libgcc.ld
-- Adding linker script /opt/esp/idf/components/esp_rom/esp32/ld/esp32.rom.newlib-data.ld
-- Adding linker script /opt/esp/idf/components/esp_rom/esp32/ld/esp32.rom.syscalls.ld
-- Adding linker script /opt/esp/idf/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld
-- Adding linker script /opt/esp/idf/components/soc/esp32/ld/esp32.peripherals.ld
-- Components: app_trace app_update bootloader bootloader_support bt cmock console cxx driver efuse esp-tls esp_adc esp_app_format esp_coex esp_common esp_eth esp_event esp_gdbstub esp_hid esp_http_client esp_http_server esp_https_ota esp_https_server esp_hw_support esp_lcd esp_local_ctrl esp_mm esp_netif esp_netif_stack esp_partition esp_phy esp_pm esp_psram esp_ringbuf esp_rom esp_system esp_timer esp_wifi espcoredump esptool_py fatfs freertos hal heap http_parser idf_test ieee802154 json log lwip main mbedtls mqtt newlib nvs_flash openthread partition_table perfmon protobuf-c protocomm pthread sdmmc soc spi_flash spiffs tcp_transport ulp unity usb vfs wear_levelling wifi_provisioning wpa_supplicant xtensa
-- Component paths: /opt/esp/idf/components/app_trace /opt/esp/idf/components/app_update /opt/esp/idf/components/bootloader /opt/esp/idf/components/bootloader_support /opt/esp/idf/components/bt /opt/esp/idf/components/cmock /opt/esp/idf/components/console /opt/esp/idf/components/cxx /opt/esp/idf/components/driver /opt/esp/idf/components/efuse /opt/esp/idf/components/esp-tls /opt/esp/idf/components/esp_adc /opt/esp/idf/components/esp_app_format /opt/esp/idf/components/esp_coex /opt/esp/idf/components/esp_common /opt/esp/idf/components/esp_eth /opt/esp/idf/components/esp_event /opt/esp/idf/components/esp_gdbstub /opt/esp/idf/components/esp_hid /opt/esp/idf/components/esp_http_client /opt/esp/idf/components/esp_http_server /opt/esp/idf/components/esp_https_ota /opt/esp/idf/components/esp_https_server /opt/esp/idf/components/esp_hw_support /opt/esp/idf/components/esp_lcd /opt/esp/idf/components/esp_local_ctrl /opt/esp/idf/components/esp_mm /opt/esp/idf/components/esp_netif /opt/esp/idf/components/esp_netif_stack /opt/esp/idf/components/esp_partition /opt/esp/idf/components/esp_phy /opt/esp/idf/components/esp_pm /opt/esp/idf/components/esp_psram /opt/esp/idf/components/esp_ringbuf /opt/esp/idf/components/esp_rom /opt/esp/idf/components/esp_system /opt/esp/idf/components/esp_timer /opt/esp/idf/components/esp_wifi /opt/esp/idf/components/espcoredump /opt/esp/idf/components/esptool_py /opt/esp/idf/components/fatfs /opt/esp/idf/components/freertos /opt/esp/idf/components/hal /opt/esp/idf/components/heap /opt/esp/idf/components/http_parser /opt/esp/idf/components/idf_test /opt/esp/idf/components/ieee802154 /opt/esp/idf/components/json /opt/esp/idf/components/log /opt/esp/idf/components/lwip /opt/esp/idf/examples/get-started/hello_world/main /opt/esp/idf/components/mbedtls /opt/esp/idf/components/mqtt /opt/esp/idf/components/newlib /opt/esp/idf/components/nvs_flash /opt/esp/idf/components/openthread /opt/esp/idf/components/partition_table /opt/esp/idf/components/perfmon /opt/esp/idf/components/protobuf-c /opt/esp/idf/components/protocomm /opt/esp/idf/components/pthread /opt/esp/idf/components/sdmmc /opt/esp/idf/components/soc /opt/esp/idf/components/spi_flash /opt/esp/idf/components/spiffs /opt/esp/idf/components/tcp_transport /opt/esp/idf/components/ulp /opt/esp/idf/components/unity /opt/esp/idf/components/usb /opt/esp/idf/components/vfs /opt/esp/idf/components/wear_levelling /opt/esp/idf/components/wifi_provisioning /opt/esp/idf/components/wpa_supplicant /opt/esp/idf/components/xtensa
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/esp/idf/examples/get-started/hello_world/build
command "/opt/esp/python_env/idf5.1_py3.8_env/bin/python /opt/esp/idf/tools/idf.py -B build reconfigure" gives the following warnings with exitcode 0:
/opt/esp/idf/tools/check_python_dependencies.py:12: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
Compiler supported targets: xtensa-esp32-elf


****** Filter files and dirs ******
Files to be analysed:
+ > /opt/esp/idf/examples/get-started/hello_world/main/hello_world_main.c
***********************************
Running command: "/opt/esp/python_env/idf5.1_py3.8_env/bin/python /usr/lib/llvm-10/share/clang/run-clang-tidy.py -p build .*"...
Enabled checks:
    clang-analyzer-apiModeling.StdCLibraryFunctions
    clang-analyzer-apiModeling.TrustNonnull
    clang-analyzer-apiModeling.google.GTest
    clang-analyzer-apiModeling.llvm.CastValue
    clang-analyzer-apiModeling.llvm.ReturnValue
    clang-analyzer-core.CallAndMessage
    clang-analyzer-core.DivideZero
    clang-analyzer-core.DynamicTypePropagation
    clang-analyzer-core.NonNullParamChecker
    clang-analyzer-core.NonnilStringConstants
    clang-analyzer-core.NullDereference
    clang-analyzer-core.StackAddrEscapeBase
    clang-analyzer-core.StackAddressEscape
    clang-analyzer-core.UndefinedBinaryOperatorResult
    clang-analyzer-core.VLASize
    clang-analyzer-core.builtin.BuiltinFunctions
    clang-analyzer-core.builtin.NoReturnFunctions
    clang-analyzer-core.uninitialized.ArraySubscript
    clang-analyzer-core.uninitialized.Assign
    clang-analyzer-core.uninitialized.Branch
    clang-analyzer-core.uninitialized.CapturedBlockVariable
    clang-analyzer-core.uninitialized.UndefReturn
    clang-analyzer-cplusplus.InnerPointer
    clang-analyzer-cplusplus.Move
    clang-analyzer-cplusplus.NewDelete
    clang-analyzer-cplusplus.NewDeleteLeaks
    clang-analyzer-cplusplus.PureVirtualCall
    clang-analyzer-cplusplus.SelfAssignment
    clang-analyzer-cplusplus.SmartPtr
    clang-analyzer-cplusplus.VirtualCallModeling
    clang-analyzer-deadcode.DeadStores
    clang-analyzer-fuchsia.HandleChecker
    clang-analyzer-nullability.NullPassedToNonnull
    clang-analyzer-nullability.NullReturnedFromNonnull
    clang-analyzer-nullability.NullabilityBase
    clang-analyzer-nullability.NullableDereferenced
    clang-analyzer-nullability.NullablePassedToNonnull
    clang-analyzer-nullability.NullableReturnedFromNonnull
    clang-analyzer-optin.cplusplus.UninitializedObject
    clang-analyzer-optin.cplusplus.VirtualCall
    clang-analyzer-optin.mpi.MPI-Checker
    clang-analyzer-optin.osx.OSObjectCStyleCast
    clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
    clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker
    clang-analyzer-optin.performance.GCDAntipattern
    clang-analyzer-optin.performance.Padding
    clang-analyzer-optin.portability.UnixAPI
    clang-analyzer-osx.API
    clang-analyzer-osx.MIG
    clang-analyzer-osx.NSOrCFErrorDerefChecker
    clang-analyzer-osx.NumberObjectConversion
    clang-analyzer-osx.OSObjectRetainCount
    clang-analyzer-osx.ObjCProperty
    clang-analyzer-osx.SecKeychainAPI
    clang-analyzer-osx.cocoa.AtSync
    clang-analyzer-osx.cocoa.AutoreleaseWrite
    clang-analyzer-osx.cocoa.ClassRelease
    clang-analyzer-osx.cocoa.Dealloc
    clang-analyzer-osx.cocoa.IncompatibleMethodTypes
    clang-analyzer-osx.cocoa.Loops
    clang-analyzer-osx.cocoa.MissingSuperCall
    clang-analyzer-osx.cocoa.NSAutoreleasePool
    clang-analyzer-osx.cocoa.NSError
    clang-analyzer-osx.cocoa.NilArg
    clang-analyzer-osx.cocoa.NonNilReturnValue
    clang-analyzer-osx.cocoa.ObjCGenerics
    clang-analyzer-osx.cocoa.RetainCount
    clang-analyzer-osx.cocoa.RetainCountBase
    clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak
    clang-analyzer-osx.cocoa.SelfInit
    clang-analyzer-osx.cocoa.SuperDealloc
    clang-analyzer-osx.cocoa.UnusedIvars
    clang-analyzer-osx.cocoa.VariadicMethodTypes
    clang-analyzer-osx.coreFoundation.CFError
    clang-analyzer-osx.coreFoundation.CFNumber
    clang-analyzer-osx.coreFoundation.CFRetainRelease
    clang-analyzer-osx.coreFoundation.containers.OutOfBounds
    clang-analyzer-osx.coreFoundation.containers.PointerSizedValues
    clang-analyzer-security.FloatLoopCounter
    clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
    clang-analyzer-security.insecureAPI.SecuritySyntaxChecker
    clang-analyzer-security.insecureAPI.UncheckedReturn
    clang-analyzer-security.insecureAPI.bcmp
    clang-analyzer-security.insecureAPI.bcopy
    clang-analyzer-security.insecureAPI.bzero
    clang-analyzer-security.insecureAPI.decodeValueOfObjCType
    clang-analyzer-security.insecureAPI.getpw
    clang-analyzer-security.insecureAPI.gets
    clang-analyzer-security.insecureAPI.mkstemp
    clang-analyzer-security.insecureAPI.mktemp
    clang-analyzer-security.insecureAPI.rand
    clang-analyzer-security.insecureAPI.strcpy
    clang-analyzer-security.insecureAPI.vfork
    clang-analyzer-unix.API
    clang-analyzer-unix.DynamicMemoryModeling
    clang-analyzer-unix.Malloc
    clang-analyzer-unix.MallocSizeof
    clang-analyzer-unix.MismatchedDeallocator
    clang-analyzer-unix.Vfork
    clang-analyzer-unix.cstring.BadSizeArg
    clang-analyzer-unix.cstring.CStringModeling
    clang-analyzer-unix.cstring.NullArg
    clang-analyzer-valist.CopyToSelf
    clang-analyzer-valist.Uninitialized
    clang-analyzer-valist.Unterminated
    clang-analyzer-valist.ValistBase

clang-tidy-10 -p=build /opt/esp/idf/examples/get-started/hello_world/main/hello_world_main.c
/opt/esp/idf/components/newlib/platform_include/endian.h:51:10: error: 'machine/endian.h' file not found [clang-diagnostic-error]
#include <machine/endian.h>
         ^
command "/opt/esp/python_env/idf5.1_py3.8_env/bin/python /usr/lib/llvm-10/share/clang/run-clang-tidy.py -p build .*" gives the following warnings with exitcode 1:
4 warnings and 1 error generated.
Error while processing /opt/esp/idf/examples/get-started/hello_world/main/hello_world_main.c.
Suppressed 4 warnings (4 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).

clang-tidy report generated: /opt/esp/idf/examples/get-started/hello_world/warnings.txt
color outputs in "/opt/esp/idf/examples/get-started/hello_world/warnings.txt" are eliminated.
warning.txt
Enabled checks:
    clang-analyzer-apiModeling.StdCLibraryFunctions
    clang-analyzer-apiModeling.TrustNonnull
    clang-analyzer-apiModeling.google.GTest
    clang-analyzer-apiModeling.llvm.CastValue
    clang-analyzer-apiModeling.llvm.ReturnValue
    clang-analyzer-core.CallAndMessage
    clang-analyzer-core.DivideZero
    clang-analyzer-core.DynamicTypePropagation
    clang-analyzer-core.NonNullParamChecker
    clang-analyzer-core.NonnilStringConstants
    clang-analyzer-core.NullDereference
    clang-analyzer-core.StackAddrEscapeBase
    clang-analyzer-core.StackAddressEscape
    clang-analyzer-core.UndefinedBinaryOperatorResult
    clang-analyzer-core.VLASize
    clang-analyzer-core.builtin.BuiltinFunctions
    clang-analyzer-core.builtin.NoReturnFunctions
    clang-analyzer-core.uninitialized.ArraySubscript
    clang-analyzer-core.uninitialized.Assign
    clang-analyzer-core.uninitialized.Branch
    clang-analyzer-core.uninitialized.CapturedBlockVariable
    clang-analyzer-core.uninitialized.UndefReturn
    clang-analyzer-cplusplus.InnerPointer
    clang-analyzer-cplusplus.Move
    clang-analyzer-cplusplus.NewDelete
    clang-analyzer-cplusplus.NewDeleteLeaks
    clang-analyzer-cplusplus.PureVirtualCall
    clang-analyzer-cplusplus.SelfAssignment
    clang-analyzer-cplusplus.SmartPtr
    clang-analyzer-cplusplus.VirtualCallModeling
    clang-analyzer-deadcode.DeadStores
    clang-analyzer-fuchsia.HandleChecker
    clang-analyzer-nullability.NullPassedToNonnull
    clang-analyzer-nullability.NullReturnedFromNonnull
    clang-analyzer-nullability.NullabilityBase
    clang-analyzer-nullability.NullableDereferenced
    clang-analyzer-nullability.NullablePassedToNonnull
    clang-analyzer-nullability.NullableReturnedFromNonnull
    clang-analyzer-optin.cplusplus.UninitializedObject
    clang-analyzer-optin.cplusplus.VirtualCall
    clang-analyzer-optin.mpi.MPI-Checker
    clang-analyzer-optin.osx.OSObjectCStyleCast
    clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
    clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker
    clang-analyzer-optin.performance.GCDAntipattern
    clang-analyzer-optin.performance.Padding
    clang-analyzer-optin.portability.UnixAPI
    clang-analyzer-osx.API
    clang-analyzer-osx.MIG
    clang-analyzer-osx.NSOrCFErrorDerefChecker
    clang-analyzer-osx.NumberObjectConversion
    clang-analyzer-osx.OSObjectRetainCount
    clang-analyzer-osx.ObjCProperty
    clang-analyzer-osx.SecKeychainAPI
    clang-analyzer-osx.cocoa.AtSync
    clang-analyzer-osx.cocoa.AutoreleaseWrite
    clang-analyzer-osx.cocoa.ClassRelease
    clang-analyzer-osx.cocoa.Dealloc
    clang-analyzer-osx.cocoa.IncompatibleMethodTypes
    clang-analyzer-osx.cocoa.Loops
    clang-analyzer-osx.cocoa.MissingSuperCall
    clang-analyzer-osx.cocoa.NSAutoreleasePool
    clang-analyzer-osx.cocoa.NSError
    clang-analyzer-osx.cocoa.NilArg
    clang-analyzer-osx.cocoa.NonNilReturnValue
    clang-analyzer-osx.cocoa.ObjCGenerics
    clang-analyzer-osx.cocoa.RetainCount
    clang-analyzer-osx.cocoa.RetainCountBase
    clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak
    clang-analyzer-osx.cocoa.SelfInit
    clang-analyzer-osx.cocoa.SuperDealloc
    clang-analyzer-osx.cocoa.UnusedIvars
    clang-analyzer-osx.cocoa.VariadicMethodTypes
    clang-analyzer-osx.coreFoundation.CFError
    clang-analyzer-osx.coreFoundation.CFNumber
    clang-analyzer-osx.coreFoundation.CFRetainRelease
    clang-analyzer-osx.coreFoundation.containers.OutOfBounds
    clang-analyzer-osx.coreFoundation.containers.PointerSizedValues
    clang-analyzer-security.FloatLoopCounter
    clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
    clang-analyzer-security.insecureAPI.SecuritySyntaxChecker
    clang-analyzer-security.insecureAPI.UncheckedReturn
    clang-analyzer-security.insecureAPI.bcmp
    clang-analyzer-security.insecureAPI.bcopy
    clang-analyzer-security.insecureAPI.bzero
    clang-analyzer-security.insecureAPI.decodeValueOfObjCType
    clang-analyzer-security.insecureAPI.getpw
    clang-analyzer-security.insecureAPI.gets
    clang-analyzer-security.insecureAPI.mkstemp
    clang-analyzer-security.insecureAPI.mktemp
    clang-analyzer-security.insecureAPI.rand
    clang-analyzer-security.insecureAPI.strcpy
    clang-analyzer-security.insecureAPI.vfork
    clang-analyzer-unix.API
    clang-analyzer-unix.DynamicMemoryModeling
    clang-analyzer-unix.Malloc
    clang-analyzer-unix.MallocSizeof
    clang-analyzer-unix.MismatchedDeallocator
    clang-analyzer-unix.Vfork
    clang-analyzer-unix.cstring.BadSizeArg
    clang-analyzer-unix.cstring.CStringModeling
    clang-analyzer-unix.cstring.NullArg
    clang-analyzer-valist.CopyToSelf
    clang-analyzer-valist.Uninitialized
    clang-analyzer-valist.Unterminated
    clang-analyzer-valist.ValistBase

clang-tidy-10 -p=build /opt/esp/idf/examples/get-started/hello_world/main/hello_world_main.c
/opt/esp/idf/components/newlib/platform_include/endian.h:51:10: error: 'machine/endian.h' file not found [clang-diagnostic-error]
#include <machine/endian.h>
         ^

clang-tidy did not found library machine/endian.h. Looking at similar github issue IDFGH-5084 it seems that

this issue happens because clang-tidy is using host header files rather than the header files provided by xtensa-esp32-elf GCC based toolchain

While looking for a solution I found that using master branch version of pyclang and run-clang-tidy.py did not fix the issue and is also present in idf release/v5.0

How to reproduce

For better repeatability I used espressif/idf:release-v5.1 docker image. You can run it iteractively with the following command docker run -it --rm espressif/idf:release-v5.1 bash . Once inside the docker container run the following commands:

# Prerequisites
apt update && apt install -y clang-tidy
pip install -U pyclang
idf_tools.py install esp-clang

# Change path to the hello world example project
cd /opt/esp/idf/examples/get-started/hello_world/

# Initialize the project
idf.py set-target esp32

# Run clang-tidy (find an error)
idf.py clang-check --run-clang-tidy-py=/usr/lib/llvm-10/share/clang/run-clang-tidy.py

# Run build (work fine)
idf.py build

idf.py clang-check --run-clang-tidy-py throughs error on windows idf version 4.4.3 (RDT-401)

I am try to do static analysis using clung-check.
I am following below step on windows.

I am getting below error, can any one guide me how to resolve this error.

C:\workspace\project\EVSE\enphase\gateway-esp32>idf.py clang-check --run-clang-tidy-py "python C:\workspace\project\EVSE\enphase\llvm-project\clang-tools-extra\clang-tidy\tool\run-clang-tidy.py"
Executing action: clang-check
Running command: "C:\Espressif\python_env\idf4.4_py3.8_env\Scripts\python.exe C:\Espressif\tools\idf-exe\1.0.3\idf.py.EXE -B build reconfigure"...
File "C:\Espressif\tools\idf-exe\1.0.3\idf.py.EXE", line 1
SyntaxError: Non-UTF-8 code starting with '\x90' in file C:\Espressif\tools\idf-exe\1.0.3\idf.py.EXE on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Traceback (most recent call last):
File "C:\Espressif\frameworks\esp-idf-v4.4.3\tools\idf.py", line 816, in
main()
File "C:\Espressif\frameworks\esp-idf-v4.4.3\tools\idf.py", line 734, in main
cli(sys.argv[1:], prog_name=PROG, complete_var='_IDF.PY_COMPLETE')
File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\click\core.py", line 1128, in call
return self.main(*args, **kwargs)
File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\click\core.py", line 1053, in main
rv = self.invoke(ctx)
File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\click\core.py", line 1691, in invoke
return _process_result(rv)
File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\click\core.py", line 1628, in _process_result
value = ctx.invoke(self._result_callback, value, **ctx.params)
File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\click\core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "C:\Espressif\frameworks\esp-idf-v4.4.3\tools\idf.py", line 636, in execute_tasks
task(ctx, global_args, task.action_args)
File "C:\Espressif\frameworks\esp-idf-v4.4.3\tools\idf.py", line 217, in call
self.callback(self.name, context, global_args, **action_args)
File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\pyclang\idf_extension.py", line 25, in call_runner
runner()
File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\pyclang\runner.py", line 187, in call
self._run(folder, log_fs, output_dir)
File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\pyclang\runner.py", line 158, in _run
func(folder, log_fs, output_dir)
File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\pyclang\runner.py", line 201, in _f
return func(self, *args, **kwargs)
File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\pyclang\runner.py", line 226, in idf_reconfigure
run_cmd(
File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\pyclang\utils.py", line 56, in run_cmd
raise RuntimeError(f'command "{cmd_str}" failed with exitcode {returncode}')
RuntimeError: command "C:\Espressif\python_env\idf4.4_py3.8_env\Scripts\python.exe C:\Espressif\tools\idf-exe\1.0.3\idf.py.EXE -B build reconfigure" failed with exitcode 1

`idf.py clang-check` Cannot find intentional memory leak error (IDFGH-11244)

IDF version.

v4.4.4

Espressif SoC revision.

ESP32-D0WD-V3 (revision 3)

Operating System used.

MacOS

How did you build your project?

Command line with idf.py

IDE being used

VS Code IDE

Build System

CMake

Development Kit.

ESP32 WROVER-IE on Custom Board

The error I intentionally made on esp-idf's own sample project in the directory I specified is as follows;
/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/main/simple_client.cpp

    void *x = malloc(2);
    x = 0;

I have attached the warning.txt file generated when I run the project by idf.py clang-check.

warnings.txt

Logging is as follows;

command "/Users/Inthecask/.espressif/python_env/idf4.4_py3.11_env/bin/python /usr/local/bin/run-clang-tidy.py -p build .*" gives the following warnings with exitcode 1:
5 warnings and 1 error generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_primitives_freertos.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 1 error generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_vfs_uart_creator.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 1 error generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_vfs_socket_creator.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_term_fs.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 1 error generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_dce.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_modules.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 13 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_dte.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 1 error generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_term_uart.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 2 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_netif.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_uart.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
7 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/main/simple_client.cpp.
Suppressed 7 warnings (7 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
7 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_factory.cpp.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
6 warnings and 20 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_command_library.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
6 warnings and 6 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_api.cpp.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
7 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/main/simple_mqtt_client.cpp.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
6 warnings and 5 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_c_api.cpp.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
6 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_cmux.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).

clang-tidy report generated: /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/warnings.txt
color outputs in "/Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/warnings.txt" are eliminated.

The situation I noticed is thatIDF Clang-Tidy does not do a bad job between 30-40 LOC. But it doesn't notice memory leaks, which I would expect it to notice in slightly more complex projects. Is this some kind of bug? How can it be used more effectively? Please correct me if I'm wrong, I intend to use any static code analyzer to alert me to bugs I'm not noticing and areas where I need to be careful. If it can't do its job, there is no point in using it. You mentioned earlier that IDF Clang-Tidy is still under development. I appreciate your efforts, but as a user, can we conclude that it is not ready for use yet?

main.zip

Tool doesn't work on esp32c3 risc-v cpu's (RDT-113)

When running idf.py clang-check on a project using the esp32c3 you get the following output in warnings.txt repeated:

error: unknown target CPU 'rv32imc' [clang-diagnostic-error]
note: valid target CPU values are: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, cor
ei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake,
 cooperlake, cannonlake, icelake-client, icelake-server, tigerlake, sapphirerapids, alderlake, knl, knm, k8, athlon64, athlon-fx, optero
n, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, znver3, x8
6-64, x86-64-v2, x86-64-v3, x86-64-v4
Error while processing /home/robert/Programs/esp-idf/components/openssl/platform/ssl_port.c.
Suppressed 4 warnings (4 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).

versions of all the components used:

$ clang --version
clang version 12.0.1 (https://github.com/espressif/llvm-project.git d9341b81fc589c0483d629155bc88e6e85e3db34)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: .espressif/tools/xtensa-clang/12.0.1-d9341b81fc/xtensa-esp32-elf-clang/bin
$ clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 12.0.1
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: skylake
$ which run-clang-tidy.py
.espressif/tools/xtensa-clang/12.0.1-d9341b81fc/xtensa-esp32-elf-clang/bin/run-clang-tidy.py
$ idf.py --version
ESP-IDF v5.0-dev-1462-g3441dd1e98

OSError: [WinError 193] %1 is not a valid Win32 application (RDT-381)

I'm following the steps in https://docs.espressif.com/projects/esp-idf/en/v4.4.2/esp32/api-guides/tools/idf-clang-tidy.html in a Windows 10, using vscode esp-idf extension terminal, when I try to run 'idf.py clang-check' i get this error:

Executing action: clang-check
Running command: "idf.py -B build reconfigure"...
Traceback (most recent call last):
File "c:\esp\esp-idf\tools\idf.py", line 816, in
main()
File "c:\esp\esp-idf\tools\idf.py", line 734, in main
cli(sys.argv[1:], prog_name=PROG, complete_var='_IDF.PY_COMPLETE')
File "c:\esp\tools\python_env\idf4.4_py3.8_env\lib\site-packages\click\core.py", line 1130, in call
return self.main(*args, **kwargs)
File "c:\esp\tools\python_env\idf4.4_py3.8_env\lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
File "c:\esp\tools\python_env\idf4.4_py3.8_env\lib\site-packages\click\core.py", line 1689, in invoke
return _process_result(rv)
File "c:\esp\tools\python_env\idf4.4_py3.8_env\lib\site-packages\click\core.py", line 1626, in _process_result
value = ctx.invoke(self._result_callback, value, **ctx.params)
File "c:\esp\tools\python_env\idf4.4_py3.8_env\lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "c:\esp\esp-idf\tools\idf.py", line 636, in execute_tasks
task(ctx, global_args, task.action_args)
File "c:\esp\esp-idf\tools\idf.py", line 217, in call
self.callback(self.name, context, global_args, **action_args)
File "c:\esp\tools\python_env\idf4.4_py3.8_env\lib\site-packages\pyclang\idf_extension.py", line 25, in call_runner
runner()
File "c:\esp\tools\python_env\idf4.4_py3.8_env\lib\site-packages\pyclang\runner.py", line 184, in call
self._run(folder, log_fs, output_dir)
File "c:\esp\tools\python_env\idf4.4_py3.8_env\lib\site-packages\pyclang\runner.py", line 155, in _run
func(folder, log_fs, output_dir)
File "c:\esp\tools\python_env\idf4.4_py3.8_env\lib\site-packages\pyclang\runner.py", line 198, in _f
return func(self, *args, **kwargs)
File "c:\esp\tools\python_env\idf4.4_py3.8_env\lib\site-packages\pyclang\runner.py", line 223, in idf_reconfigure
run_cmd(
File "c:\esp\tools\python_env\idf4.4_py3.8_env\lib\site-packages\pyclang\utils.py", line 37, in run_cmd
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
File "subprocess.py", line 854, in init
File "subprocess.py", line 1307, in _execute_child
OSError: [WinError 193] %1 não é um aplicativo Win32 válido

Propagate clang-tidy output to stdout or stderr (RDT-109)

Currently when we run idf.py clang-check, there is no console output while scanning is in progress. On a large project, scanning may take several minutes to complete, making it appear as if the tool has hung up.
It would be nice to indicate that something is happening e.g. by forwarding the warnings produced by clang-tidy to console, with a --quiet option to inhibit this.

ERROR: unknown tool name: xtensa-clang (RDT-280)

I have finished the 1st and 2nd step " 1. Run the export scripts (export.sh / export.bat / … ) to set up the environment variables.

  1. Run pip install --upgrade pyclang to install this plugin. The extra commands would be activated in idf.py automatically."
    And when I use the 3rd step command "Run idf_tools.py install xtensa-clang to install the clang-tidy required binaries" I got this
    ERROR: unknown tool name: xtensa-clang. How can I fix this ERROR.

Add an option to generate SARIF and/or SAST output (RDT-110)

  • SARIF is a JSON based format for representing code scanning results, currently used by Github (see docs.)
  • SAST is another JSON based format, used by Gitlab (see schema.)

When we run clang-tidy, we get a warnings.txt file as output. It would be nice to add functionality to parse the warnings.txt file and output SARIF or SAST JSON files which can then be fed into Github or Gitlab.

For reference, there is a clang-tidy-sarif tool which performs this kind of conversion, written in Rust: https://github.com/psastras/sarif-rs/tree/main/clang-tidy-sarif.

Failure to run IDF Clang Tidy for C files (IDFGH-11206)

IDF version.

v4.4.4

Espressif SoC revision.

ESP32-D0WD-V3 (revision 3)

Operating System used.

MacOS

How did you build your project?

Command line with idf.py

IDE being used

VS Code IDE

Build System

CMake

Development Kit.

ESP32 WROVER-IE on Custom Board

I have C and C++ source files in my project. When I ran the idf.py clang-check command, I got C++ build errors in warning.txtfile. How can I avoid the errors I get for my .c files? How can I go about using a static code analyzer optimized for my project? How do you advise me to proceed?

In addition, I read the Prerequisites and the conditions to run command idf.py clang-check. As a 2-year ESP-IDF user, I found it a bit complicated. I wish there was a clearer path. It was not clear what commands I could use other than this command. I also could not get it to work properly on a different machine with idf v5.0 installed too. Thank you for your efforts and contributions anyway.

fail ValueError (RDT-262)

IDF: v4.4.2
macOS: 12.5

We are looking to replace our complex clang-tidy wrapper with idf.py clang-check but our initial findings testing is not running. Happy to help support this effort.

command: idf.py clang-check --run-clang-tidy-py ./scripts/ci/run-clang-tidy.py --exclude-paths managed_components

run command: /Users/ash/dev/iot-module-fw/scripts/ci/run-clang-tidy.py .*  || true
Traceback (most recent call last):
  File "/Users/ash/dev/esp/esp-idf-latest-release/tools/idf.py", line 816, in <module>
    main()
  File "/Users/ash/dev/esp/esp-idf-latest-release/tools/idf.py", line 734, in main
    cli(sys.argv[1:], prog_name=PROG, complete_var='_IDF.PY_COMPLETE')
  File "/Users/ash/.espressif/python_env/idf4.4_py3.9_env/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/ash/.espressif/python_env/idf4.4_py3.9_env/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/ash/.espressif/python_env/idf4.4_py3.9_env/lib/python3.9/site-packages/click/core.py", line 1689, in invoke
    return _process_result(rv)
  File "/Users/ash/.espressif/python_env/idf4.4_py3.9_env/lib/python3.9/site-packages/click/core.py", line 1626, in _process_result
    value = ctx.invoke(self._result_callback, value, **ctx.params)
  File "/Users/ash/.espressif/python_env/idf4.4_py3.9_env/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/ash/dev/esp/esp-idf-latest-release/tools/idf.py", line 636, in execute_tasks
    task(ctx, global_args, task.action_args)
  File "/Users/ash/dev/esp/esp-idf-latest-release/tools/idf.py", line 217, in __call__
    self.callback(self.name, context, global_args, **action_args)
  File "/Users/ash/.espressif/python_env/idf4.4_py3.9_env/lib/python3.9/site-packages/pyclang/idf_extension.py", line 25, in call_runner
    runner()
  File "/Users/ash/.espressif/python_env/idf4.4_py3.9_env/lib/python3.9/site-packages/pyclang/runner.py", line 169, in __call__
    self._run(folder, log_fs, output_dir)
  File "/Users/ash/.espressif/python_env/idf4.4_py3.9_env/lib/python3.9/site-packages/pyclang/runner.py", line 140, in _run
    func(folder, log_fs, output_dir)
  File "/Users/ash/.espressif/python_env/idf4.4_py3.9_env/lib/python3.9/site-packages/pyclang/runner.py", line 183, in _f
    return func(self, *args, **kwargs)
  File "/Users/ash/.espressif/python_env/idf4.4_py3.9_env/lib/python3.9/site-packages/pyclang/runner.py", line 306, in run_clang_tidy
    raise ValueError(first_line)
ValueError

Cannot find c++ `std` library headers (RDT-426)

For example:

/Users/johnboiles/Developer/repos/sindarin-inc/embedded-app/src/Sensors/LightingController.hpp:3:10: error: 'functional' file not found [clang-diagnostic-error]
#include <functional>
/Users/johnboiles/Developer/repos/sindarin-inc/embedded-app/src/Inputs/RemoteInput.hpp:4:10: error: 'cstdint' file not found [clang-diagnostic-error]
#include <cstdint>

It looks like the generated clang-tidy command from the log output is very simplistic and doesn't include anything about include paths or anything like that:

/Users/johnboiles/.espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/clang-tidy -p=build --config-file=.clang-tidy /Users/johnboiles/Developer/repos/sindarin-inc/embedded-app/src/Misc/PlatformESP32.cpp

Seems like the stock run-clang-tidy.py script mentioned in the docs only uses the "file" key in compile_commands.json and doesn't use the "command" key, so all of the build flags are missing.

So how do we use this when using the c++ stdlib?

Add support for multiple sdk configs (RDT-313)

Currently idf.py clang-check calls reconfigure, this will clear any existing config. This is problematic if you have feature flags enabled by multiple sdkconfigs.

We created a CI config and usually run CI builds as follows.

idf.py reconfigure -DSDKCONFIG_DEFAULTS="sdkconfig.defaults;configs/sdkconfig.ci"'
idf.py app

Exit code from `run-clang-tidy.py` not preserved with `idf.py clang-check` (IDFGH-10534)

When running run-clang-tidy.py and there are files that have errors, run-clang-tidy.py will return a non-zero exit code. However, idf.py clang-check seems to swallow up that exit code and return a 0 exit code.

This make it difficult to know if there were errors in the clang-tidy run. For example, it is difficult to fail a check in CI if clang-tidy was unable to run successfully.

`idf.py clang-check` opens `run-clang-tidy.py` instead of running it (RDT-244)

On Windows, the command idf.py clang-check opens run-clang-tidy.py instead of running it. This is because it appears to execute the command directly instead of passing it through a Python interpreter.

The documentation at https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-clang-tidy.html does not specify any required platform, and seems to indicate that Windows should be supported.

It correctly runs run-clang-tidy.py if I specify that it should use python to run the script:

idf.py clang-check --run-clang-tidy-py "python $HOME\esp\esp-idf\tools\run-clang-tidy.py"

Tell IDF build system that clang toolchain is in use (RDT-111)

Normally when we run idf.py reconfigure, that uses the GCC based toolchain. IDF build system adds various command line options specific to GCC, and clang doesn't recognize them. This results in unknown argument warnings reported by clang-tidy.

Since IDF 5.0, there is initial support for compiling ESP-IDF with clang based toolchain. It is activated by setting IDF_TOOLCHAIN=clang in the environment or in CMake cache, before configuring the project.

IDF_TOOLCHAIN=clang idf.py clang-tidy-check behaves better and doesn't report the unknown argument warnings.

Not sure if this is something we should fix in the idf.py action extension or simply mention this in the docs. Leaving this as an open issue for now.

doesn't match supported version (RDT-269)

ESP_IDF=4.4.2
macOS=12.5.1


Add clang tool chain to the path:
PATH="/Users/ash/.espressif/tools/xtensa-clang/12.0.1-d9341b81fc/xtensa-esp32-elf-clang/bin:$PATH"

ash@ash-mb-pro-work iot-module-fw % clang --version
clang version 12.0.1 (https://github.com/espressif/llvm-project.git d9341b81fc589c0483d629155bc88e6e85e3db34)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Users/ash/.espressif/tools/xtensa-clang/12.0.1-d9341b81fc/xtensa-esp32-elf-clang/bin

run-clang-tidy-py and exclude-paths options appears to be have now been removed.

Our run command is as follows:

idf.py clang-check

CMake Error at /Users/ash/dev/esp/esp-idf-latest-release/tools/cmake/crosstool_version_check.cmake:37 (message):


  Toolchain:
  /Users/ash/.espressif/tools/xtensa-clang/12.0.1-d9341b81fc/xtensa-esp32-elf-clang/bin/xtensa-esp32-elf-gcc,
  crosstool-ng version esp-2021r1 doesn't match supported version
  esp-2021r2-patch3

Not sure where is esp-2021r1 is coming from as my machine only has the latest esp-idf-4.4.2 installed.

`clang-check` fails on windows: attempts to open tempfile twice (RDT-245)

Running idf.py clang-check errors with a traceback:

$ idf.py clang-check --run-clang-tidy-py "python $HOME\esp\esp-idf\tools\run-clang-tidy.py"
...
Traceback (most recent call last):
  File "C:\Users\Sean\esp\esp-idf\tools\idf.py", line 800, in <module>
    main()
  File "C:\Users\Sean\esp\esp-idf\tools\idf.py", line 735, in main
    cli(sys.argv[1:], prog_name=PROG, complete_var=SHELL_COMPLETE_VAR)
  File "C:\Users\Sean\.espressif\python_env\idf5.0_py3.10_env\lib\site-packages\click\core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\Sean\.espressif\python_env\idf5.0_py3.10_env\lib\site-packages\click\core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "C:\Users\Sean\.espressif\python_env\idf5.0_py3.10_env\lib\site-packages\click\core.py", line 1691, in invoke
    return _process_result(rv)
  File "C:\Users\Sean\.espressif\python_env\idf5.0_py3.10_env\lib\site-packages\click\core.py", line 1628, in _process_result
    value = ctx.invoke(self._result_callback, value, **ctx.params)
  File "C:\Users\Sean\.espressif\python_env\idf5.0_py3.10_env\lib\site-packages\click\core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\Sean\esp\esp-idf\tools\idf.py", line 629, in execute_tasks
    task(ctx, global_args, task.action_args)
  File "C:\Users\Sean\esp\esp-idf\tools\idf.py", line 216, in __call__
    self.callback(self.name, context, global_args, **action_args)
  File "C:\Users\Sean\.espressif\python_env\idf5.0_py3.10_env\lib\site-packages\pyclang\idf_extension.py", line 25, in call_runner
    runner()
  File "C:\Users\Sean\.espressif\python_env\idf5.0_py3.10_env\lib\site-packages\pyclang\runner.py", line 169, in __call__
    self._run(folder, log_fs, output_dir)
  File "C:\Users\Sean\.espressif\python_env\idf5.0_py3.10_env\lib\site-packages\pyclang\runner.py", line 140, in _run
    func(folder, log_fs, output_dir)
  File "C:\Users\Sean\.espressif\python_env\idf5.0_py3.10_env\lib\site-packages\pyclang\runner.py", line 183, in _f
    return func(self, *args, **kwargs)
  File "C:\Users\Sean\.espressif\python_env\idf5.0_py3.10_env\lib\site-packages\pyclang\runner.py", line 296, in run_clang_tidy
    run_cmd(
  File "C:\Users\Sean\.espressif\python_env\idf5.0_py3.10_env\lib\site-packages\pyclang\utils.py", line 46, in run_cmd
    with open(fw.name, 'rb') as fr:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Sean\\AppData\\Local\\Temp\\tmpmhuxs4ss'

This is due to a bug in pyclang.

It attempts to open a file using with tempfile.NamedTemporaryFile() as fw:, which opens the file. However, it then attempts to open the file a second time, which is an undefined operation.

This results in a permissions error on Windows, since tempfiles are exclusive access.

The following patch to Lib/site-packages/pyclang/utils.py fixes the problem:

diff --git a/utils.py b/utils.py
index 59a1713..091a146 100644
--- a/utils.py
+++ b/utils.py
@@ -43,8 +43,7 @@ def run_cmd(

         return_code = p.wait()
         if return_code:
-            with open(fw.name, 'rb') as fr:
-                raw_stderr = to_str(fr.read())
+            raw_stderr = to_str(fw.read())
             if ignore_error and ignore_error in raw_stderr:
                 return KnownIssue()  # nothing happens
             if raw_stderr:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.