Ericsson / codechecker

CodeChecker is an analyzer tooling, defect database and viewer extension for static and dynamic analyzer tools.
https://codechecker.readthedocs.io
Apache License 2.0
2.27k stars 382 forks source link

Unreal Engine 4 support #1971

Open Charusso opened 5 years ago

Charusso commented 5 years ago

What behaviour was expected instead of what happened.

  1. As usual I tried the following to produce the database:

    • CodeChecker log -b "make -j13" -o compile_commands.json

    • Outcome: Build failed.

2.1. I have followed the advice by Timothee "TTimo" Besset with Bear:

git clone --single-branch --branch ttimo https://github.com/TTimo/Bear.git
cd Bear/
cmake .
make all
sudo make install
cd ..
bear ./Engine/Build/BatchFiles/Linux/Build.sh UE4Game Linux Development -disableunity -nopch

2.2. I wanted to use that Bear-made compile_commands.json:


  1. Copied the tricky build command from TTimo to CodeChecker:

    • CodeChecker log -b "./Engine/Build/BatchFiles/Linux/Build.sh UE4Game Linux Development -disableunity -nopch" -o compile_commands.json

    • Outcome: successfully built, but the compile_commands.json was empty, so failed.

    • I have hard-coded the arguments into Build.sh and the outcome was the same so the parsing is cool I think.

  2. Tried out the hack made by TTimo combined with his build command with CodeChecker:

    • export CC_LOGGER_GCC_LIKE="gcc:g++:clang:cc1"
    • Note: cc1plus may would be involved so I tried "gcc:g++:clang:cc1:cc1plus" as well.
    • CodeChecker log -b "./Engine/Build/BatchFiles/Linux/Build.sh UE4Game Linux Development -disableunity -nopch" -o compile_commands.json

Additional information

  1. It is too heavy
    • If you try to produce a compile_commands.json with ninja it immediately run into a trouble:
    • Argument list too long.
  1. How to reproduce the environment

  2. The environment

    • The project folder without built stuff is 69,3 GB.
    • After build and ./Engine/Binaries/Linux/UE4Editor to check if it is working the folder is 78 GB.
    • Building is about 5120 compilation unit with the tricky command.

  3. The tricky command explained /Engine/Build/BatchFiles/Linux/Build.sh UE4Game Linux Development -disableunity -nopch


Summary

I cannot decide if we would

The best would be just a simple CodeChecker log -b "make -j13" -o compile_commands.json.

csordasmarton commented 4 years ago

@Charusso I think #2092 solved your problem. Could you please try it out?

axsaucedo commented 4 years ago

@Charusso since UE2.24 you can actually use the UnrealBuildTool to generate the compile_commands.json. You just need to run "<path_to_ue4.24>/Engine/Binaries/DotNet/UnrealBuildTool.exe -mode=GenerateClangDatabase -project".uproject" Development Win64". This was tested in Windows + WSL. The output is a compile_commands.json file in your Unreal Engine base path.

Currently I am using it for the CCLS languag server for code checking in editor, however it doesn't seem to work fully as still several errors appear, but it may be enough for your usecase.

Here is an ongoing thread in the forums where it's being discussed as well, and includes further references to the documentation that mentions it in release notes https://forums.unrealengine.com/development-discussion/c-gameplay-programming/1525128-linux-rdm-compile_commands-json

blasco commented 4 years ago

@axsaucedo Is this working in Linux? I'm trying to do the same but when I run:

 /home/user/Programs/UnrealEngine/Engine/Build/BatchFiles/Linux/Build.sh/Build.sh -project=/home/user/Documents/Unreal/MyProject/MyProject.uproject -mode=GenerateClangDatabase UE4Game Linux Development

I get an error complaining that clang is not installed, but it is:

 clang --version

 clang version 10.0.0-4ubuntu1 
 Target: x86_64-pc-linux-gnu
 Thread model: posix
 InstalledDir: /usr/bin
gyorb commented 4 years ago

There is a comment in the mentioned forum discussion about the same problem, that the Build.sh script can not generate a compile command database file right now on linux.

10-11-2020, 01:47 PM Same situation here, not able to use -mode=GenerateClangDatabase it complaints about not finding clang, which is insatlled.