From 129624205cd5df03bccc096c2c907d6f4b96a855 Mon Sep 17 00:00:00 2001 From: Bryce Kahle Date: Thu, 18 Jul 2024 14:30:44 -0700 Subject: [PATCH] remove ebpf clang pre-commit (#27645) --- .clang-tidy | 42 -------------- .pre-commit-config.yaml | 9 --- tasks/pre_commit.py | 22 -------- tasks/system_probe.py | 119 ---------------------------------------- 4 files changed, 192 deletions(-) delete mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy deleted file mode 100644 index 0b2add312cdf0..0000000000000 --- a/.clang-tidy +++ /dev/null @@ -1,42 +0,0 @@ ---- -Checks: 'clang-diagnostic-*,clang-analyzer-*,readability-*,-readability-magic-numbers,linuxkernel-*,portability-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling' -HeaderFilterRegex: '.*' -AnalyzeTemporaryDtors: false -FormatStyle: file -CheckOptions: - - key: cert-dcl16-c.NewSuffixes - value: 'L;LL;LU;LLU' - - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField - value: '0' - - key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons - value: '0' - - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors - value: '1' - - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic - value: '1' - - key: google-readability-braces-around-statements.ShortStatementLines - value: '1' - - key: google-readability-function-size.StatementThreshold - value: '800' - - key: google-readability-namespace-comments.ShortNamespaceLines - value: '10' - - key: google-readability-namespace-comments.SpacesBeforeComments - value: '2' - - key: llvm-else-after-return.WarnOnConditionVariables - value: '0' - - key: llvm-else-after-return.WarnOnUnfixable - value: '0' - - key: llvm-qualified-auto.AddConstToQualified - value: '0' - - key: modernize-loop-convert.MaxCopySize - value: '16' - - key: modernize-loop-convert.MinConfidence - value: reasonable - - key: modernize-loop-convert.NamingStyle - value: CamelCase - - key: modernize-pass-by-value.IncludeStyle - value: llvm - - key: modernize-replace-auto-ptr.IncludeStyle - value: llvm - - key: modernize-use-nullptr.NullMacros - value: 'NULL' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 09d42f10d2185..3bc80db24e44b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -67,15 +67,6 @@ repos: language: system types_or: [c, c++, c#] pass_filenames: false - - id: clang-format - name: clang-format - description: clang-format - entry: 'inv pre-commit.check-clang-format' - language: system - require_serial: true - pass_filenames: false - files: '^pkg/(ebpf|network|security)/.*\.(c|h)$' - exclude: '^pkg/ebpf/(c/bpf_endian|c/bpf_helpers|compiler/clang-stdarg).h$' - id: go-mod-tidy name: go-mod-tidy description: check that all go.mod files are tidy diff --git a/tasks/pre_commit.py b/tasks/pre_commit.py index cc8ab89a183d4..8b7a84cca0b22 100644 --- a/tasks/pre_commit.py +++ b/tasks/pre_commit.py @@ -7,8 +7,6 @@ from tasks.libs.common.color import color_message from tasks.libs.common.git import get_staged_files -from tasks.tools import clang_format -from tasks.tools.clang_format import ExitStatus DEFAULT_PRE_COMMIT_CONFIG = ".pre-commit-config.yaml" DEVA_PRE_COMMIT_CONFIG = ".pre-commit-config-deva.yaml" @@ -72,23 +70,3 @@ def check_set_x(ctx): print(error, file=sys.stderr) print(color_message('error:', 'red'), 'No shell script should use "set -x"', file=sys.stderr) raise Exit(code=1) - - -@task -def check_clang_format(ctx): - files = [ - file - for file in get_staged_files(ctx) - if ( - re.match(r"^pkg/(ebpf|network|security)/.*\.(c|h)$", file) - and not re.match( - "^pkg/ebpf/(c/bpf_endian|c/bpf_helpers|compiler/clang-stdarg).h$", - file, - ) - ) - ] - - if files: - res = clang_format.run(files) - if res != ExitStatus.SUCCESS: - raise Exit(code=res) diff --git a/tasks/system_probe.py b/tasks/system_probe.py index 7b29b0e8f20be..5c06c8c22bf15 100644 --- a/tasks/system_probe.py +++ b/tasks/system_probe.py @@ -963,125 +963,6 @@ def kitchen_prepare(ctx, kernel_release=None, ci=False, packages=""): ctx.run(f"echo {get_commit_sha(ctx)} > {BUILD_COMMIT}") -@task -def clang_format(ctx, targets=None, fix=False, fail_on_issue=False): - """ - Format C code using clang-format - """ - ctx.run("which clang-format") - if isinstance(targets, str): - # when this function is called from the command line, targets are passed - # as comma separated tokens in a string - targets = targets.split(',') - - if not targets: - targets = get_ebpf_targets() - - # remove externally maintained files - ignored_files = [ - "pkg/ebpf/c/bpf_builtins.h", - "pkg/ebpf/c/bpf_core_read.h", - "pkg/ebpf/c/bpf_cross_compile.h", - "pkg/ebpf/c/bpf_endian.h", - "pkg/ebpf/c/bpf_helpers.h", - "pkg/ebpf/c/bpf_helper_defs.h", - "pkg/ebpf/c/bpf_tracing.h", - "pkg/ebpf/c/bpf_tracing_custom.h", - "pkg/ebpf/c/compiler.h", - "pkg/ebpf/c/map-defs.h", - "pkg/ebpf/c/vmlinux_5_15_0.h", - "pkg/ebpf/c/vmlinux_5_15_0_arm.h", - "pkg/ebpf/compiler/clang-stdarg.h", - ] - for f in ignored_files: - if f in targets: - targets.remove(f) - - fmt_cmd = "clang-format -i --style=file --fallback-style=none" - if not fix: - fmt_cmd = fmt_cmd + " --dry-run" - if fail_on_issue: - fmt_cmd = fmt_cmd + " --Werror" - - ctx.run(f"{fmt_cmd} {' '.join(targets)}") - - -@task -def clang_tidy(ctx, fix=False, fail_on_issue=False, kernel_release=None): - """ - Lint C code using clang-tidy - """ - - print("checking for clang-tidy executable...") - ctx.run("which clang-tidy") - - build_flags = get_ebpf_build_flags() - build_flags.append("-DDEBUG=1") - build_flags.append("-emit-llvm") - build_flags.extend(get_kernel_headers_flags(kernel_release=kernel_release)) - - bpf_dir = os.path.join(".", "pkg", "ebpf") - base_files = glob.glob(f"{bpf_dir}/c/**/*.c") - - network_c_dir = os.path.join(".", "pkg", "network", "ebpf", "c") - network_files = list(base_files) - network_files.extend(glob.glob(f"{network_c_dir}/**/*.c")) - network_flags = list(build_flags) - network_flags.append(f"-I{network_c_dir}") - network_flags.append(f"-I{os.path.join(network_c_dir, 'prebuilt')}") - network_flags.append(f"-I{os.path.join(network_c_dir, 'runtime')}") - network_checks = [ - "-readability-function-cognitive-complexity", - "-readability-isolate-declaration", - "-clang-analyzer-security.insecureAPI.bcmp", - ] - run_tidy( - ctx, - files=network_files, - build_flags=network_flags, - fix=fix, - fail_on_issue=fail_on_issue, - checks=network_checks, - ) - - security_agent_c_dir = os.path.join(".", "pkg", "security", "ebpf", "c") - security_files = list(base_files) - security_files.extend(glob.glob(f"{security_agent_c_dir}/**/*.c")) - security_flags = list(build_flags) - security_flags.append(f"-I{security_agent_c_dir}") - security_flags.append(f"-I{security_agent_c_dir}/include") - security_flags.append("-DUSE_SYSCALL_WRAPPER=0") - security_checks = ["-readability-function-cognitive-complexity", "-readability-isolate-declaration"] - run_tidy( - ctx, - files=security_files, - build_flags=security_flags, - fix=fix, - fail_on_issue=fail_on_issue, - checks=security_checks, - ) - - -def run_tidy(ctx, files, build_flags, fix=False, fail_on_issue=False, checks=None): - flags = ["--quiet"] - if fix: - flags.append("--fix") - if fail_on_issue: - flags.append("--warnings-as-errors='*'") - - if checks is not None: - flags.append(f"--checks={','.join(checks)}") - - ctx.run(f"clang-tidy {' '.join(flags)} {' '.join(files)} -- {' '.join(build_flags)}", warn=True) - - -def get_ebpf_targets(): - files = glob.glob("pkg/ebpf/c/*.[c,h]") - files.extend(glob.glob("pkg/network/ebpf/c/**/*.[c,h]", recursive=True)) - files.extend(glob.glob("pkg/security/ebpf/c/**/*.[c,h]", recursive=True)) - return files - - def get_kernel_arch() -> Arch: # Mapping used by the kernel, from https://elixir.bootlin.com/linux/latest/source/scripts/subarch.include kernel_arch = (