Code Monkey home page Code Monkey logo

Comments (8)

pocc avatar pocc commented on August 25, 2024

Thank you for reporting this issue. Off the top of my head, I would try using a comma instead of an equals like so:

args: [-p, /home/user/projects/myproject/build]

Failing that, please provide a Minimal Reproducible Example, including the error message.

from pre-commit-hooks.

sparfenyuk avatar sparfenyuk commented on August 25, 2024

Unfortunately, your suggestion doesn't work for me. Here you can see the minimal reproducible example mre.zip. Conan is required since it puts external libraries into its own path so clang-tidy cannot locate them even if '-p' argument is set in the parameter list. By the way, I want to be able to set a relative path not an absolute one.

from pre-commit-hooks.

TheButlah avatar TheButlah commented on August 25, 2024

I believe I have this same issue. Does pre-commit always use the project root as the current working directory, or does it use the actual cwd? Being able to specify things relative to the project root would be ideal.

from pre-commit-hooks.

TheButlah avatar TheButlah commented on August 25, 2024

Update: This is still an issue for me. The intended behavior would be to provide the location of the build directory relative to the project root. For example, both [-p, build], and [-p=build] fail, but if I manually run clang-tidy (not the hook), with clang-tidy -p=build my_file.cpp, it works.

I attempted to get around this by using [-p=$(git rev-parse --show-toplevel)/build] but that didn't work either, as it doesn't appear as though the shell command was expanded.

(See here for an explanation of the git command)

from pre-commit-hooks.

pocc avatar pocc commented on August 25, 2024

I'm sorry this is still an issue for you. I haven't had time to look at this properly. If you can make a PR, I would be happy to merge.

from pre-commit-hooks.

pocc avatar pocc commented on August 25, 2024

@sparfenyuk I've attempted to use your MRE and I see the same 3 errors with the pre-commit config hook as clang-tidy with the same arguments. This is after building it with cmake with the commands provided (on Macos 10.14).

Note: I have also made a python branch of this repo (use rev: python), which should play nicer with relative file names.

clang-tidy with arguments

build rj$ clang-tidy src/* -checks=* -warnings-as-errors=* -p ../build
Error while trying to load a compilation database:
Could not auto-detect compilation database from directory "../build"
No compilation database found in /Users/rj/code/mre/../build or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
Error while processing /Users/rj/code/mre/src/CMakeLists.txt.
396 warnings and 2 errors generated.
Error while processing /Users/rj/code/mre/src/main.cpp.
error: unable to handle compilation, expected exactly one compiler job in '' [clang-diagnostic-error]
/Users/rj/code/mre/src/main.cpp:1:10: error: 'opencv2/opencv.hpp' file not found [clang-diagnostic-error]
#include <opencv2/opencv.hpp>
         ^
/Users/rj/code/mre/src/main.cpp:3:14: error: parameter 'argc' is unused [misc-unused-parameters,-warnings-as-errors]
int main(int argc, char** argv)
             ^~~~
              /*argc*/
/Users/rj/code/mre/src/main.cpp:3:27: error: parameter 'argv' is unused [misc-unused-parameters,-warnings-as-errors]
int main(int argc, char** argv)
                          ^~~~
                           /*argv*/
Suppressed 394 warnings (394 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
2 warnings treated as errors

Same output from clang-tidy hook

clang-tidy...............................................................Failed
hookid: clang-tidy

Error while processing /Users/rj/code/mre/src/main.cpp.
/Users/rj/code/mre/src/main.cpp:1:10: error: 'opencv2/opencv.hpp' file not found [clang-diagnostic-error]
#include <opencv2/opencv.hpp>
         ^
/Users/rj/code/mre/src/main.cpp:3:14: error: parameter 'argc' is unused [misc-unused-parameters,-warnings-as-errors]
int main(int argc, char** argv)
             ^~~~
              /*argc*/
/Users/rj/code/mre/src/main.cpp:3:27: error: parameter 'argv' is unused [misc-unused-parameters,-warnings-as-errors]
int main(int argc, char** argv)
                          ^~~~
                           /*argv*/
Suppressed 393 warnings (393 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
2 warnings treated as errors

from pre-commit-hooks.

pocc avatar pocc commented on August 25, 2024

@TheButlah Pre-commit should use project root as cwd.

from pre-commit-hooks.

pocc avatar pocc commented on August 25, 2024

Closing as I was adding -- -DCMAKEOPTIONS=ON to suppress no compilation database errors in the bash version, which likely caused this issue. The python version checks for -p and -- options first.

from pre-commit-hooks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.