Open vadi2 opened 5 years ago
This looks really cool! But I might need some help implementing it; the docs seem to assume some general tool-chain familiarity that might be a blocker for me. Please let me know if you'd like help implementing this as a Restyler yourself.
Yes sure, what would you like help with?
I was more thinking you (or any contributor who knew this tool well) could take the lead, and I would help them :)
https://github.com/restyled-io/restyled.io/wiki/Adding-a-Restyler
Reading up on this a big,
Enabling Fixits
[P]ass ...
-export-fixes=somefile.yaml
forclazy-standalone
. Then runclang-apply-replacements <folder_with_yaml_files>
, which will modify your code.
So, this will require an extra script to:
clazy-standalone -export-fixes=x/...
, thenclang-apply-replacements x
I've started on this (will push a PR soon), but can't get it working.
It seems like clazy-standalone
is actually trying to compile things (or expects it to somehow have been compiled). Our test case fails with:
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "./clazy-test-1.cpp"
No compilation database found in /code 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.
/code/clazy-test-1.cpp:1:10: fatal error: 'QString' file not found
#include <QString>
^~~~~~~~~
1 error generated.
Error while processing /code/clazy-test-1.cpp.
I'm not sure what would be required to get it working.
Hey thanks for taking up work on this. Clazy requires a file called compile_commands.json which are instructions for the compiler on how to compile a certain file. This file can be generated by a bunch of build systems, including cmake if you pass it the -DCMAKE_EXPORT_COMPILE_COMMANDS
argument.
I'm not familiar with how restylers works (but looking forward to using it with clazy in) - you might need to get the user to provide some configuration to generate the compile commands file?
Under normal usage would that ./compile_commands.json
be present in the repository when cloned? If so, then we will see/use it and that's good -- I just have to update my test harness to create that scenario correctly.
And do you think this warning is the reason it can't find QString
? I've installed qt6 in the restyler image and confirmed that library exists on the filesystem, at least.
It's an autogenerated file and it's typically not checked in because the paths to the libraries would be different on every developers machine.
Here's an example of how I use another clang-based tool to first generate the file and then run the tool when the file is present: https://github.com/Mudlet/Mudlet/blob/development/.github/workflows/clangtidy-diff-analysis.yml#L107-L136
And do you think this warning is the reason it can't find QString?
Yeah, that would be it.
OK, a little further:
CMake Error: The source directory "/code" does not appear to contain CMakeLists.txt.
I added cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
before running clazy-standalone
.
Is this a file I can expect to be present in a checked-out clone? If so, how do I fake it for the test-harness.
For more context, the test harness is just running a single .cpp
file with the contents:
#include <QString>
QString str = "hello";
str.mid(5).toInt(ok);
Try this cpp file:
#include <iostream>
#include <QString>
int main() {
QString str = "hello";
QString result = str.mid(5);
std::cout << "Original string: " << str.toStdString() << std::endl;
std::cout << "Substring from index 5 onwards: " << result.toStdString() << std::endl;
return 0;
}
With this CMakeLists.txt file present in the same folder:
cmake_minimum_required(VERSION 3.16)
project(helloworld VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt6 REQUIRED COMPONENTS Core)
add_executable(helloworld
main.cpp
)
target_link_libraries(helloworld PRIVATE Qt6::Core)
and then run cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
as you did before.
OK, I think I'm in a good place. The following seems to function, without error:
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
clazy-standalone --export-fixes="$tmp"/fixes.yaml --checks=level0 <input>
clang-apply-replacements "$tmp"
The problem now is that it seems to do nothing. fixes.yaml
is not produced, apply-replacements is a no-op, and my test fails because .mid
was not replaced by midRef
.
:thinking:
https://github.com/KDE/clazy
Best practices checker for Qt (C++) with fixits.