erenon / bazel_clang_tidy

Run clang-tidy on Bazel C++ targets directly, efficiently, with caching enabled
MIT License
103 stars 54 forks source link

clang-tidy is not found when installed in a custom path #19

Closed aminya closed 1 year ago

aminya commented 2 years ago

clang-tidy is not found in run_clang_tidy.sh although it is on the PATH. It seems that the spawn doesn't pass the env variables. https://github.com/erenon/bazel_clang_tidy/blob/783aa523aafb4a6798a538c61e700b6ed27975a7/clang_tidy/run_clang_tidy.sh#L14

erenon commented 2 years ago

Do you have --action_env specified?

aminya commented 2 years ago

No, as far as I have set. Maybe my dependencies set that. I can check and get back to you

aminya commented 2 years ago

I checked. I didn't specify that. I hope it can be fixed.

I have found a hacky workaround to hot patch the clang_tidy path using go-task

  clang_tidy_path:
    cmds:
      - sed -i '/^clang-tidy "\$@"$/s|clang-tidy|{{.HOME}}/llvm/bin/clang-tidy -p {{.CWD}}|' {{.run_clang_tidy}}
    preconditions:
      - test -f {{.run_clang_tidy}}
    vars:
      run_clang_tidy: ./external/bazel_clang_tidy/clang_tidy/run_clang_tidy.sh
      CWD:
        sh: git rev-parse --show-toplevel

  clang_tidy:
    cmds:
      - task: clang_tidy_path
      - bazel build --config=tidy myproj

I run [compile_commands.json] extractor before running clang_tidy: https://github.com/hedronvision/bazel-compile-commands-extractor

erenon commented 2 years ago

You need to set the PATH correctly, and specify action_env accordingly, otherwise bazel will not find your custom tools. This is unrelated to this repo.

On Fri, May 6, 2022, 20:51 Amin Yahyaabadi @.***> wrote:

I checked. I didn't specify that. I hope it can be fixed.

I have found a hacky workaround to hot patch the clang_tidy path using go-task https://taskfile.dev/#/

clang_tidy_path: cmds:

  • sed -i '/^clang-tidy "\$@"$/s|clang-tidy|{{.HOME}}/llvm/bin/clang-tidy/|' {{.run_clang_tidy}} preconditions:
  • test -f {{.run_clang_tidy}} vars: run_clang_tidy: ./bazel-myproj/external/bazel_clang_tidy/clang_tidy/run_clang_tidy.sh

    tidy: cmds:

  • task: clang_tidy_path
  • bazel build --config=tidy myproj

— Reply to this email directly, view it on GitHub https://github.com/erenon/bazel_clang_tidy/issues/19#issuecomment-1119921323, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABOYM5GBHIMD7IXTFSAVI3VIVSZNANCNFSM5VGDERXA . You are receiving this because you commented.Message ID: @.***>

aminya commented 2 years ago

My PATH variable is already set. What should I specify in action_env? I cannot find anything in the documentation.

erenon commented 2 years ago

Here's the doc: https://docs.bazel.build/versions/main/command-line-reference.html#flag--action_env action_env should specify a path set that contains your custom clang tidy install.

oliverlee commented 2 years ago

If you are on macOS, see https://github.com/bazelbuild/bazel/issues/12049

kkpattern commented 2 years ago

We created a llvm_repo repository rule to create an external repository and link the installed llvm directory into the llvm_repo. This ensures bazel_clang_tidy can find clang-tidy and also makes the clang-tidy check reproducible.

Here is the related blog if anyone is interested.