First, we need to install codebrowser along with dependancies. We can install from binary (.deb) file at this link. Note that the binary available at this location is an old build.
sudo dpkg -i woboq-codebrowser_2.1_amd64.deb
sudo apt install libtinfo5
OR
We can build it using the source code,
sudo apt install llvm-7 clang-7 libclang-7-dev
git clone https://github.com/KDAB/codebrowser.git
cd codebrowser
cmake . -DCMAKE_BUILD_TYPE=Release
make
sudo make install
For woboq enhancements, please refer to Deployment Tips
The next most important thing is to generate compile_commands.json for our project.
For woboq tools, the format of compile_commands.json entry should of the following template:
{
"directory": "/home/user/dev/llvm/build",
"file": "/home/user/dev/llvm/llvm/lib/Support/APFloat.cpp",
"command": "/usr/bin/g++ ... /dev/llvm/llvm/lib/Support/APFloat.cpp"
}
Note that woboq currently doesn't support the latest format of compile_commands entries with output
field as shown below,
{
"directory": "/home/user/dev/llvm/build",
"file": "/tmp/foo.cpp",
"output": "foo.o",
"arguments": ["/usr/bin/g++", ... ]
}
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
sudo apt install bear
Here let's try and generate compile_commands for postgres project
git clone https://github.com/postgres/postgres
cd postgres
bear -- ./configure
bear -- make
but bear generates the compile command entries with output field. This is currently
is not supported by the the woboq parser(see issue-94).
In order to get compile commands in the older format, we can try workaround mentioned by
creator of bear(rizsotto).
So instead of just say bear -- make we need to do
intercept --output commands.json -- make
citnames --input commands.json --output compile_commands.json --config config.json
where contents of config.json are
{
"compilation": {},
"output": {
"content": {
"include_only_existing_source": true
},
"format": {
"command_as_array": false,
"drop_output_field": true
}
}
}
OUTPUT_DIRECTORY=~/public_html/postgres
DATA_DIRECTORY=$OUTPUT_DIRECTORY/../data
mkdir -p $OUTPUT_DIRECTORY
mkdir -p $DATA_DIRECTORY
BUILD_DIRECTORY=$PWD
SOURCE_DIRECTORY=$PWD
VERSION=`git describe --always --tags`
codebrowser_generator -b $BUILD_DIRECTORY -a \
-o $OUTPUT_DIRECTORY \
-p postgres:$SOURCE_DIRECTORY:$VERSION
codebrowser_indexgenerator $OUTPUT_DIRECTORY
Copy required css/js files
cp -rv /usr/share/woboq/data/.* $DATA_DIRECTORY/
Alternatively, we can also use the latest css/js files from woboq repository
git clone https://github.com/KDAB/codebrowser
cd codebrowser
cp -rv data/.* $DATA_DIRECTORY/
cd ~/public_html
python3 -m http.server 8000
Now we can browse through generated files :)