Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clang_tidy - Add defines and local_defines attributes to commandline args #477

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

molar
Copy link

@molar molar commented Feb 7, 2025

The clang_tidy aspect did not read the defines and local_defines attribute of the rule, causing clang_tidy to error
on parsing code that references these defines. This PR extends the clang_tidy.bzl with support for reading these attributes and adds them to the clang-tidy commandline.

I also added a guard against rules that do not have a srcs attribute, but do return a CcInfo.

Changes are visible to end-users: yes/no

Test plan

  • Manual testing; please provide instructions so we can reproduce:

Extended the example with a local_defines attribute and tried to lint the code without my changes, where i got the
error

_main/src/cpp/lib/hello-time.cc:16:28: error: use of undeclared identifier 'LOCAL_DEFINE_IS_DEFINED' [clang-diagnostic-error]
  static const char* str = LOCAL_DEFINE_IS_DEFINED;

after my change the error is gone and the normal fixes are proposed when running bazel lint //src/cpp/....

I only tested on ubuntu x86.

@CLAassistant
Copy link

CLAassistant commented Feb 7, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@@ -270,6 +273,12 @@ def _get_compiler_args(ctx, compilation_context, srcs):
args.append("-D" + define)
for define in compilation_context.local_defines.to_list():
args.append("-D" + define)
if hasattr(ctx.rule.attr, "defines"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, is it a bug that the compilation_context didn't already supply this local_define value? @jsharpe in case you have an opinion

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly seems like it, but given its the behaviour of bazel releases then we've got to fix up for it; there shouldn't be too much harm (other than line length and the associated increase in memory use) in adding the defines to the commandline multiple times?

@alexeagle
Copy link
Member

@molar are you able to click through the Contributor License Agreement?

@molar
Copy link
Author

molar commented Feb 17, 2025

@molar are you able to click through the Contributor License Agreement?

I am waiting for legal to look it over, not sure of the ETA.

@molar
Copy link
Author

molar commented Mar 6, 2025

@molar are you able to click through the Contributor License Agreement?

I am waiting for legal to look it over, not sure of the ETA.

@alexeagle i have signed cla - is there any other issues you would like to be addressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants