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

bazel/clang-tidy: Cleanups and optimizations #2496

Merged
merged 2 commits into from
Dec 2, 2024

Conversation

phlax
Copy link
Member

@phlax phlax commented Dec 1, 2024

No description provided.

Signed-off-by: Ryan Northey <ryan@synca.io>
Copy link

netlify bot commented Dec 1, 2024

Deploy Preview for nifty-bassi-e26446 ready!

Name Link
🔨 Latest commit 821544a
🔍 Latest deploy log https://app.netlify.com/sites/nifty-bassi-e26446/deploys/674ce33e93daf50008cbcc4e
😎 Deploy Preview https://deploy-preview-2496--nifty-bassi-e26446.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@phlax
Copy link
Member Author

phlax commented Dec 1, 2024

cc @mathetake

Comment on lines 68 to 73
permitted_file_types = [
".c", ".cc", ".cpp", ".cxx", ".c++", ".C", ".h", ".hh", ".hpp", ".hxx", ".inc", ".inl", ".H",
]
for file_type in permitted_file_types:
if src.basename.endswith(file_type):
return True
Copy link
Member

Choose a reason for hiding this comment

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

can we use dict here? for loop with more than 10 items seems a bit unnecessary linear search

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure i follow exactly - in real python there are various ways to optimize this but i dont think they work in starlark - can you give example?

Copy link
Member

Choose a reason for hiding this comment

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


PERMITTED_TYPES = {"c": True, "cpp": True}

def perimtted(file_name):
    if file_name.split(".")[-1] in PERMITTED_TYPES:
        return True

like this?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure if the dict would be faster than a list

what i think we can do is ...

Suggested change
permitted_file_types = [
".c", ".cc", ".cpp", ".cxx", ".c++", ".C", ".h", ".hh", ".hpp", ".hxx", ".inc", ".inl", ".H",
]
for file_type in permitted_file_types:
if src.basename.endswith(file_type):
return True
permitted_file_types = [
".c", ".cc", ".cpp", ".cxx", ".c++", ".C", ".h", ".hh", ".hpp", ".hxx", ".inc", ".inl", ".H",
]
return src.extension in permitted_file_types

Copy link
Member Author

Choose a reason for hiding this comment

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

probably - we can shift the list out and get rid of the fun also

Copy link
Member

Choose a reason for hiding this comment

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

at least can you move .h and .cc to the first elements?

Copy link
Member

Choose a reason for hiding this comment

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

they are the most common in envoy code base

Copy link
Member Author

Choose a reason for hiding this comment

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

re .h i think we dont want it to run over the headers directly it causes a stack of other issues

if we do want that then we need to fish them out from the hdrs attr

Comment on lines +24 to +25
# echo "RUN: ${CLANG_TIDY_BIN} ${*}"

Copy link
Member

Choose a reason for hiding this comment

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

leftover?

Copy link
Member Author

Choose a reason for hiding this comment

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

i figured keep it - its kinda useful for debugging

@@ -158,11 +137,11 @@ def _clang_tidy_aspect_impl(target, ctx):
src,
target.label.name,
)
for src in srcs
for src in _rule_sources(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

I think this outputs can be one run i guess? i don't see any reason why we cannot run clang-tidy for all source codes in the target at once vs here run each file per clang-tidy.

Copy link
Member Author

Choose a reason for hiding this comment

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

let me test ...

Copy link
Member Author

@phlax phlax Dec 1, 2024

Choose a reason for hiding this comment

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

so the one issue with this plan is that the flags are set according to whether src is .c or .cc

a quick grep of the code suggests there are not any builds that have both as a src (not sure that would make sense - but what do i know) - so probably surmountable

on the upsides it makes the code cleaner and removes the need to use to_list on the srcs

Copy link
Member

@mathetake mathetake Dec 1, 2024

Choose a reason for hiding this comment

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

i believe all Envoy codes are C++ hence .cc and .c are for test C program code (not clang-tidy worthy), so we can simply ignore them

Copy link
Member Author

@phlax phlax Dec 1, 2024

Choose a reason for hiding this comment

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

so next problem is

 38     outfile = ctx.actions.declare_file(
 39         "bazel_clang_tidy_%s.%s.clang-tidy.yaml" % (infile.path, discriminator)
 40     )

i can workaround for now - i think in the original implementation this was intended for the fix file altho not sure it was actually implemented

my intention is to use this output for the output from clang-tidy and then collect those up so probs we can think of a different path scheme

Copy link
Member Author

Choose a reason for hiding this comment

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

lets deal with this separately - the benefit is marginal at best and it requires quite a lot of change to make it work

Signed-off-by: Ryan Northey <ryan@synca.io>
@phlax phlax merged commit 06f3599 into envoyproxy:main Dec 2, 2024
24 checks passed
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.

2 participants