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

build: support clang tidy #1118

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

build: support clang tidy #1118

wants to merge 4 commits into from

Conversation

jrajahalme
Copy link
Member

@jrajahalme jrajahalme commented Jan 16, 2025

Add new clang-tidy make targets tidy and tidy-fix. Rename existing clang-format targets from check and fix to format and format-fix, respectively.

Bazel build options are passed into gen_compilation_database.py so that the analysis cache is not invalidated between make tidy and make tests targets, for example.

.clang-tidy is copied from upstream Envoy, with addition of misc-include-cleaner IgnoreHeaders options adapted from .clangd.

By default make tidy will tidy up all sources in tests and cilium directories, which takes a long time. Defining the variable TIDY_SOURCES can be used to specify a subset, e.g.,:

$ TIDY_SOURCES=cilium/network_policy.cc make tidy

Please note that make tidy-fix is prone to producing duplicated includes and non-compiling code, so all edits made with it must be manually inspected.

For the tidy targets to work, the host must have the package clang-tidy-17 installed.

@jrajahalme jrajahalme requested a review from a team as a code owner January 16, 2025 15:13
Add the following clang packages to install_clang function:
- clangd-17
- lldb-17
- clang-tools-17
- cland-tidy-17

Add make targets:

- compile_commands.json: create the compile commands database needed for
                         both clang-tidy and clangd. Include absl which
			 otherwise was unreachable for clangd.

- tidy: Use run-clang-tidy-17 to run clang-tidy in parallel. It is still
        very slow.

- tidy-fix: Run clang tidy and fix errors. Use with caution, as the fixes
            do not always compile.

Add query option --incompatible_merge_fixed_and_default_shell_env to
.bazelrc so that query does not trigger re-download of envoy
dependency. This same option is set on 'build' in 'envoy.bazelrc'.

Signed-off-by: Jarno Rajahalme <[email protected]>
Now that we have new targets 'tidy' and 'tidy-fix', rename the old
clang-format targets 'check' and 'fix' as 'format' and 'format-fix',
respectively.

Signed-off-by: Jarno Rajahalme <[email protected]>
We do not have a policy socket options any more, but a
CiliumPolicyFilterState that contains a weak reference to the policy
map. Rename 'policy_socket_option' as 'policy_ref' to make this a bit
clearer.

Signed-off-by: Jarno Rajahalme <[email protected]>
Signed-off-by: Jarno Rajahalme <[email protected]>
@jrajahalme jrajahalme force-pushed the build-support-clang-tidy branch from e36b76f to 240684c Compare January 31, 2025 18:13
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.

1 participant