Add '-supported-checks-json' command line option
ClosedPublic

Authored by nkosjar on Mon, Sep 2, 1:55 PM.

Details

Summary

...to dump the contents of checks.json.

This is useful for IDEs as they can find out now whether a particular
check is supported.

BUG: 409986

Diff Detail

Repository
R74 Clazy
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
nkosjar requested review of this revision.Mon, Sep 2, 1:55 PM
nkosjar created this revision.

I'm not sure whether "-meta-checks" is descriptive enough. Can't come up with a better name right now. Suggestions?

How do I run the tests properly? I've tried running tests/run_tests.py from the build dir, but this results in many errors...

Should this option consider the checks provided with "-checks="? That would be in line with clang-tidy and would allow IDEs to query the checks enabled by default (providing -meta-checks but no -checks=).

Honoring -checks= would also mean that available_categories in checks.json needs to be adapted accordingly. That is, this patch would not only dump the compiled in string, but read the json, and filter it.

I'm not sure whether "-meta-checks" is descriptive enough. Can't come up with a better name right now. Suggestions?

How do I run the tests properly? I've tried running tests/run_tests.py from the build dir, but this results in many errors...

cd tests/ && ./run_tests.py should work
also works in the build dir
maybe it's not finding the plugin for you

Should this option consider the checks provided with "-checks="? That would be in line with clang-tidy and would allow IDEs to query the checks enabled by default (providing -meta-checks but no -checks=).

Honoring -checks= would also mean that available_categories in checks.json needs to be adapted accordingly. That is, this patch would not only dump the compiled in string, but read the json, and filter it.

Maybe rename to -supported-checks-json , doesn't matter if it's too long, it's for IDE consumption only.
And, as the name suggests, it will print all supported checks.

Something that honours -checks can be orthogonal and be in another option. Also note that the CLAZY_CHECKS env var also influences the checks that are used.
Does this second option even need to be json based ? it can just output the list of enabled checks, and then you can cross-reference with the json you already have

I'm not sure whether "-meta-checks" is descriptive enough. Can't come up with a better name right now. Suggestions?

How do I run the tests properly? I've tried running tests/run_tests.py from the build dir, but this results in many errors...

cd tests/ && ./run_tests.py should work
also works in the build dir
maybe it's not finding the plugin for you

Yes, I get

/d2/clazy/trunk/source/tests on master % ./run_tests.py

[FAIL] mutable-container-key (Failed to build test. Check mutable-container-key/main.cpp.out for details)

Contents of mutable-container-key/main.cpp.out:
[FAIL] missing-qobject-macro (Failed to build test. Check missing-qobject-macro/main.cpp.out for details)

[FAIL] copyable-polymorphic (Failed to build test. Check copyable-polymorphic/main.cpp.out for details)

Contents of missing-qobject-macro/main.cpp.out:

Contents of copyable-polymorphic/main.cpp.out:
error: unable to load plugin 'ClazyPlugin.so': 'ClazyPlugin.so: cannot open shared object file: No such file or directory'

error: unable to load plugin 'ClazyPlugin.so': 'ClazyPlugin.so: cannot open shared object file: No such file or directory'


If I use LD_LIBRARY_PATH to point to the dir with ClazyPlugin.so, I get crashes:

d2/clazy/trunk/source/tests on master % LD_LIBRARY_PATH=/d2/clazy/trunk/builds/Debug/lib /d2/clazy/trunk/source/tests/run_tests.py

[FAIL] missing-qobject-macro (Failed to build test. Check missing-qobject-macro/main.cpp.out for details)

Contents of missing-qobject-macro/main.cpp.out:
terminate called after throwing an instance of 'std::bad_alloc'

what():  std::bad_alloc

Stack dump:
0. Program arguments: /usr/lib/llvm-7/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /d2/clazy/trunk/source/tests/main.gcno -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -isystem /home/nik/opt/qt-5.12.4/5.12.4/gcc_64/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-unused-value -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /d2/clazy/trunk/source/tests -ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -load ClazyPlugin.so -add-plugin clazy -plugin-arg-clazy missing-qobject-macro -o main.o -x c++ missing-qobject-macro/main.cpp -faddrsig
#0 0x00007f46673b2e8a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/lib/llvm-7/bin/../lib/libLLVM-7.so.1+0x908e8a)
#1 0x00007f46673b1544 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-7/bin/../lib/libLLVM-7.so.1+0x907544)
#2 0x00007f46673b1682 (/usr/lib/llvm-7/bin/../lib/libLLVM-7.so.1+0x907682)
#3 0x00007f466a994890 restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
#4 0x00007f4665db8e97 gsignal /build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
#5 0x00007f4665dba801 abort /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:81:0
#6 0x00007f46667ad957
strtof_l (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x8c957)
#7 0x00007f46667b3ab6 (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x92ab6)
#8 0x00007f46667b3af1 (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x92af1)
#9 0x00007f46667b3d24 (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x92d24)
#10 0x00007f46667dbfa2 (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xbafa2)
#11 0x000055c77383ad64 (/usr/lib/llvm-7/bin/clang+0x9b9d64)
#12 0x00007f4663754f53 ClazyASTAction::ParseArgs(clang::CompilerInstance const&, std::vector<std::cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) /d2/clazy/trunk/source/src/Clazy.cpp:235:0
#13 0x000055c77385f586 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-7/bin/clang+0x9de586)
#14 0x000055c773312688 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-7/bin/clang+0x491688)
#15 0x000055c7733013fc main (/usr/lib/llvm-7/bin/clang+0x4803fc)
#16 0x00007f4665d9bb97 __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344:0
#17 0x000055c77330fe5a _start (/usr/lib/llvm-7/bin/clang+0x48ee5a)
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 7.0.0-3~ubuntu0.18.04.1 (tags/RELEASE_700/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
clang: error: unable to execute command: Aborted (core dumped)
clang: note: diagnostic msg: Error generating preprocessed source(s).


Any recipe to run the tests correctly would be nice :)

Should this option consider the checks provided with "-checks="? That would be in line with clang-tidy and would allow IDEs to query the checks enabled by default (providing -meta-checks but no -checks=).

Honoring -checks= would also mean that available_categories in checks.json needs to be adapted accordingly. That is, this patch would not only dump the compiled in string, but read the json, and filter it.

Maybe rename to -supported-checks-json , doesn't matter if it's too long, it's for IDE consumption only.
And, as the name suggests, it will print all supported checks.

Something that honours -checks can be orthogonal and be in another option. Also note that the CLAZY_CHECKS env var also influences the checks that are used.
Does this second option even need to be json based ? it can just output the list of enabled checks, and then you can cross-reference with the json you already have

Sounds good regarding the two separate options. So I'll finish -supported-checks-json first.

nkosjar updated this revision to Diff 65759.Tue, Sep 10, 2:13 PM

Changed the cmd line option name.

nkosjar retitled this revision from Add '-meta-checks' command line option to Add '-supported-checks-json' command line option.Tue, Sep 10, 2:14 PM

Side note: How to tell "arc" to update the commit message, too?

nkosjar updated this revision to Diff 65847.Wed, Sep 11, 2:07 PM

Rebased only.

Any recipe to run the tests correctly would be nice :)

Probably add the plugin to the LD_LIBRARY_PATH

anyway, the tests pass here, will have a better look tomorrow

Looks fine!

Since you're the copyright holder, would you agree to an eventual clazy copyright change to something BSD style ?
I don't know if or when it will happen, but would like to gather the authorizations in advance anyway.

BSD style is better for working with upstream clang tooling.

Looks fine!

Since you're the copyright holder, would you agree to an eventual clazy copyright change to something BSD style ?

Sure, I agree :)

smartins accepted this revision.Fri, Sep 13, 1:03 PM
This revision is now accepted and ready to land.Fri, Sep 13, 1:03 PM
This revision was automatically updated to reflect the committed changes.