Skip to Content.
Sympa Menu

sphenix-software-l - [Sphenix-software-l] clang-tidy check in jenkins

sphenix-software-l AT lists.bnl.gov

Subject: sPHENIX discussion of software

List archive

Chronological Thread  
  • From: pinkenburg <pinkenburg AT bnl.gov>
  • To: "sphenix-software-l AT lists.bnl.gov" <sphenix-software-l AT lists.bnl.gov>
  • Subject: [Sphenix-software-l] clang-tidy check in jenkins
  • Date: Fri, 9 Feb 2024 10:48:41 -0500

Hi folks,

those of you who submitted a PR recently likely got it handed back with a clang-tidy failure. It is another tool based on clang which looks for subtle issues (e.g. did you know that sqrt(..) is different than std::sqrt() for data types other than doubles). And it actually found a bug in our code (can't recall which one though) which is the reason we added this check to jenkins.

It also helps enforcing our code formatting conventions (our seemingly favorite one that one line if/for/... statements have to be surrounded by {}) and modernize our code (use range based loops instead of the old for (iter = bla.begin(); ...)).

The really nifty feature of it is that it can apply most fixes automatically if asked to.

If you want to run it yourself (over all .cc sources in the current dir), use this lengthy command line (after sourcing our setup script):

clang-tidy *.cc -- -Wall -Werror -Wshadow -Wno-deprecated-declarations -std=c++17 -I$OFFLINE_MAIN/include -isystem$ROOTSYS/include -I$G4_MAIN/include -I$G4_MAIN/include/Geant4 -I$OPT_SPHENIX/include

If there are no errors, you can use

clang-tidy *.cc --fix  -- -Wall -Werror -Wshadow -Wno-deprecated-declarations -std=c++17 -I$OFFLINE_MAIN/include -isystem$ROOTSYS/include -I$G4_MAIN/include -I$G4_MAIN/include/Geant4 -I$OPT_SPHENIX/include

which will then "fix" your code (add curly brackets, change old for loops by rangebased loops and add std:: to math function where necessary). If there are compilation errors clang-tidy will decline to apply fixes (can be overridden by a flag).  Sadly the formatting is slightly off afterwards, so run a

clang-format -style=file -i *.cc

afterwards to get our default formatting back

We are still working on the checks - if your PR fails with clang-tidy in code which wasn't modified by your PR - it is not your problem and the PR will be okay'ed.

Chris

--
*************************************************************

Christopher H. Pinkenburg ; pinkenburg AT bnl.gov
; http://www.phenix.bnl.gov/~pinkenbu

Brookhaven National Laboratory ; phone: (631) 344-5692
Physics Department Bldg 510 C ; fax: (631) 344-3253
Upton, NY 11973-5000

*************************************************************




  • [Sphenix-software-l] clang-tidy check in jenkins, pinkenburg, 02/09/2024

Archive powered by MHonArc 2.6.24.

Top of Page