Clang-tidy check different outputs

Hello community!

I have been testing the styling checks with integrated clang-tidy on PIO. Every seemed to be working just fine and implemented a github action to run the check on CI. To my surprise the outputs are different.

My .ini for checks:

check_tool = clangtidy
check_skip_packages = yes
check_flags =
  clangtidy: --config-file=.clang-tidy
check_src_filters =
  +<./main/*>
  +<./include/*>
  -<*/network_tasks>
  -<*/networking>

On action, ubuntu 20.04:

Run pio check --fail-on-defect=high --fail-on-defect=medium
********************************************************************************
If you like PlatformIO, please:
- star it on GitHub > https://github.com/platformio/platformio-core
- follow us on LinkedIn to stay up-to-date on the latest project news > https://www.linkedin.com/company/platformio/
- try PlatformIO IDE for embedded development > https://platformio.org/platformio-ide
********************************************************************************

Checking pico32 > clangtidy (platform: espressif32@4.4.0; board: pico32; framework: espidf)
--------------------------------------------------------------------------------
Tool Manager: Installing platformio/tool-clangtidy @ ~1.150005.0
Downloading 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Unpacking 0% 10% 20%
Tool Manager: tool-clangtidy@1.150005.0 has been installed!
main/main.c:89: [medium:warning] invalid case style for variable 'prevTime'  [readability-identifier-naming]
========================== [FAILED] Took 5.07 seconds ==========================

Component     HIGH    MEDIUM    LOW
-----------  ------  --------  -----
main           0        1        0

Total          0        1        0

Environment    Tool       Status    Duration
-------------  ---------  --------  ------------
pico32         clangtidy  FAILED    00:00:05.069
==================== 1 failed, 0 succeeded in 00:00:05.069 ====================

On local machines, windows 10 and osx:

platformio check --environment pico32 
Checking pico32 > clangtidy (platform: espressif32@4.4.0; board: pico32; framework: espidf)
----------------------------------------------------------------------------------------------------------------------------------------------------
No defects found
============================================================ [PASSED] Took 0.23 seconds ============================================================

Environment    Tool       Status    Duration
-------------  ---------  --------  ------------
pico32         clangtidy  PASSED    00:00:00.227
=========================================================== 1 succeeded in 00:00:00.227 ===========================================================
 *  Terminal will be reused by tasks, press any key to close it. 

Same .clang-tidy file in both cases. I have tried running manually both commands and no changes on presented outputs.

Any insights?

By default, the PlatformIO core decides the used tool-clangtidy package version per

and so if you code-check the same project (even with fixed platform versions) with PlatformIO core X, you might get different results compared to core Y. You’d have to pin the PlatformIO core version too.

An alternative to that might be pininng the used clangtidy version per platform_packages with one of the avialable versions. So, try adding

; force usage of clang-tidy 15.0.5
platform_packages =
   tool-clangtidy@~1.150005.0

to the platformio.ini and recheck on both computers.

And of course, they will be equal after doing a pio upgrade --dev (CLI) on both computers.

I have tested enforcing the clang-tidy version and pio upgrade --dev and still have the same issue…

Can you file a bug with a minimal reproducable project at https://github.com/platformio/platformio-core/issues/?

Max, I have noticed that in fact the check on the CI detects warnings not detected on local, in particular any variable defined inside a function (static function or any kind) with same .clang-tidy file. I will be summiting the issue soon too.

#include "stdint.h"
int prevTime = 0;
void app_main() {
    int64_t Test = 0;
}
Checking pico32 > clangtidy (platform: espressif32; board: pico32; framework: espidf)       
--------------------------------------------------------------------------------------------main\main.c:4: [medium:warning] invalid case style for variable 'prevTime'  [readability-identifier-naming]
================================ [PASSED] Took 0.13 seconds ================================

Component     HIGH    MEDIUM    LOW
-----------  ------  --------  -----
main           0        1        0

Total          0        1        0

Environment    Tool       Status    Duration
-------------  ---------  --------  ------------
pico32         clangtidy  PASSED    00:00:00.126
=============================== 1 succeeded in 00:00:00.126 =============================== 

But on CI:

Tool Manager: Installing platformio/tool-clangtidy @ ~1.150005.0
Downloading 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Unpacking 0% 10% 20%
Tool Manager: tool-clangtidy@1.150005.0 has been installed!
main/main.c:4: [medium:warning] invalid case style for variable 'prevTime'  [readability-identifier-naming]
main/main.c:6: [medium:warning] invalid case style for variable 'Test'  [readability-identifier-naming]
========================== [FAILED] Took 3.70 seconds ==========================
Component     HIGH    MEDIUM    LOW
-----------  ------  --------  -----
main           0        2        0
Total          0        2        0
Environment    Tool       Status    Duration
-------------  ---------  --------  ------------
pico32         clangtidy  FAILED    00:00:03.698
==================== 1 failed, 0 succeeded in 00:00:03.698 ====================

clang-tidy inconsistent outputs between local and ci · Issue #4698 · platformio/platformio-core (github.com)

1 Like