premake / premake/premake-core

Enable clang-tidy checks for clang gmake2

Open
#2,245 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C
Stars
3.6k
Forks
654
Avg merge
1d 1h
Merged PRs (30d)
13

Description

Some time ago, I added build-time code checking for MSVC (#2190) and static analysis via clang-tidy (#2187). I also wanted to add this for the gmake2 generator, specifically for the clang toolset.

However, having read through the code, there are multiple different ways to achieve this, and I am not sure what to do. I am happy to add this feature myself if I can get some guidance from people familiar with the codebase:

  1. How can I limit enabling clang-tidy to just clang?
  2. What changes should be made in the gmake2 generator to make this happen?

To mimic cmake, should I add a second build command here, protected by a conditional:

	function cpp.initialize()
		rule 'cpp'
			fileExtension { ".cc", ".cpp", ".cxx", ".mm" }
			buildoutputs  { "$(OBJDIR)/%{file.objname}.o" }
			buildmessage  '$(notdir $<)'
			buildcommands {'$(CXX) %{premake.modules.gmake2.cpp.fileFlags(cfg, file)} $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'}

The second build line will contain the clang-tidy invocation:

	function cpp.initialize()
		rule 'cpp'
			fileExtension { ".cc", ".cpp", ".cxx", ".mm" }
			buildoutputs  { "$(OBJDIR)/%{file.objname}.o" }
			buildmessage  '$(notdir $<)'
			buildcommands {
                           '$(CXX) %{premake.modules.gmake2.cpp.fileFlags(cfg, file)} $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"',
                           'clang-tidy -- all necessary clang-tidy arguments along with compiler flags.'}

What would a conditional look like? Or, do I add a prebuild command instead?

Nice to haves:

  1. We would also need to inform clang-tidy where to read the .clang-tidy file from as it may not necessarily be in a standard location or inside the output project folder.
  2. Specify location of clang-tidy. Or perhaps this can be taken from llvmdir? But that is only supported for msvc.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the gmake2 generator's cpp.initialize function and review the approaches in issues #2190 and #2187. Resolve how clang-tidy is limited to the clang toolset, how its invocation is integrated, and how the configuration and executable locations are supplied. Done means the feature works for clang without affecting other toolsets.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.