Advanced Workflow
Walk you through the suggested advanced workflow for using Codee, demonstrated with a C project.
Getting ready
For multi-file projects, we recommended following the top-down approach introduced in the Basic Workflow, now using a compilation database to efficiently handle the compiler invocations for different source files.
To keep the demonstration simple, we will continue using the C matrix
multiplication,
consisting of three .c
source files. Start by cloning the repository if necessary:
git clone https://github.com/codee-com/codee-demos.git
Walkthrough of the workflow
0. Compilation Database
As introduced in the Basic Workflow, Codee requires the compiler invocation for each file to analyze. For large projects containing many files, this can quickly become impractical.
First, navigate to the source code directory:
- Linux
- Windows
cd codee-demos/C/MATMUL
cd codee-demos\C\MATMUL
To streamline the analysis, Codee can ingest a compilation database that details the invocation for each file. This allows Codee to automatically process all files in a project and generate reports aggregating the results of the entire codebase.
The generation of the compilation database depends on the particular build system used:
-
CMake: Add
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
to your usual CMake invocation; for instance:cmake . -DCMAKE_C_COMPILER=gcc -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release -G "Ninja" -B build
-
Makefiles: Since they do not natively support the generation of compilation databases, we recommend using
bear
. This tool is available on Linux systems through common package managers.To generate the compilation database, prepend
bear --
to your typicalmake
invocation; for example:bear -- make
The example project supports both CMake and make
.
Any of the above commands will generate a compile_commands.json
file containing the
compiler invocation for each file in the project. As discussed earlier, this
matrix multiplication code is composed of three .c
source files:
[
{
"directory": "/home/user/codee-demos/C/MATMUL/build",
"command": "/usr/bin/gcc -I/home/user/codee-demos/C/MATMUL/include -O3 -DNDEBUG -fopenmp -o CMakeFiles/matmul.dir/matrix.c.o -c /home/user/codee-demos/C/MATMUL/matrix.c",
"file": "/home/user/codee-demos/C/MATMUL/matrix.c"
},
{
"directory": "/home/user/codee-demos/C/MATMUL/build",
"command": "/usr/bin/gcc -I/home/user/codee-demos/C/MATMUL/include -O3 -DNDEBUG -fopenmp -o CMakeFiles/matmul.dir/clock.c.o -c /home/user/codee-demos/C/MATMUL/clock.c",
"file": "/home/user/codee-demos/C/MATMUL/clock.c"
},
{
"directory": "/home/user/codee-demos/C/MATMUL/build",
"command": "/usr/bin/gcc -I/home/user/codee-demos/C/MATMUL/include -O3 -DNDEBUG -fopenmp -o CMakeFiles/matmul.dir/main.c.o -c /home/user/codee-demos/C/MATMUL/main.c",
"file": "/home/user/codee-demos/C/MATMUL/main.c"
}
]
1-5. Codee Reports
To generate any of the Codee reports, simply provide the compilation database
using the -p
flag.
The reports will aggregate the results of all project files found in the compilation database. By default, Codee displays the progress of the analysis across the various files that make up the project:
codee technical-debt --verbose -p build/compile_commands.json
[1/3] /home/user/codee-demos/C/MATMUL/matrix.c ... Done
[2/3] /home/user/codee-demos/C/MATMUL/clock.c ... Done
[3/3] /home/user/codee-demos/C/MATMUL/main.c ... Done
TECHNICAL DEBT REPORT
This report quantifies the technical debt associated with the modernization of legacy code by assessing the extent of refactoring required for language constructs. The score is determined based on the number of language constructs necessitating refactoring to bring the source code up to modern standards. Additionally, the metric identifies the impacted source code segments, detailing affected files, functions, and loops.
Score Affected files Affected functions Affected loops
----- -------------- ------------------ --------------
8 2 2 5
TECHNICAL DEBT BREAKDOWN
Target Lines of code Analysis time Checkers Technical debt score
---------------------------------------- ------------- ------------- -------- --------------------
/home/user/codee-demos/C/MATMUL/matrix.c 41 9 ms 2 2
/home/user/codee-demos/C/MATMUL/clock.c 12 5 ms 0 0
/home/user/codee-demos/C/MATMUL/main.c 55 13 ms 6 6
---------------------------------------- ------------- ------------- -------- --------------------
Total 108 27 ms 8 8
SUGGESTIONS
Use 'checks' to find out details about the detected checks:
codee checks --verbose -p build/compile_commands.json
3 files, 7 functions, 11 loops successfully analyzed and 0 non-analyzed files in 29 ms
In the technical debt report, the verbose
argument provides an additional
breakdown of the total score by showing the contributions from each file.