Artificial truth

The more you see, the less you believe.

[archives] [latest] | [homepage] | [atom/rss]

Browsing php's source code with woboq's code browser
Fri 30 December 2016 — download

Php's source code being as clean as php itself, it is often non-trivial to find what you're looking for (since the developer documentation is spartiate), ctags chokes on it, and their lxr instance seems to be down for various reasons.

So I decided to give a try to woboq's code browser, since it seems that it's a bit better than lxr: it works by inspecting the AST of the source code, using clang.

Unfortunately, it relies on the json compilation database format-magic-fu that is only supported by cmake for now. The php build system may have a lot of tares, but it's doesn't use cmake.

Fortunately, one can simply instrument make itself, with a sweet mix of C++ and Python called Bear that uses LD_PRELOAD internally, to generate the precious compile_commands.json file.

Here is the listing of commands that you can copy/paste if you're lazy.

git clone git@github.com:rizsotto/Bear.git
cd Bear
mkdir build && cd build
cmake ..
make all -j `cat /proc/cpuinfo | grep processor | wc -l`
make install
cd -

git clone git@github.com:php/php-src.git
cd php-src
./buildconf
./configure
bear make -j `cat /proc/cpuinfo | grep processor | wc -l`  # this takes ages
cd -

git clone git@github.com:woboq/woboq_codebrowser.git
cd wobog_codebrowser
cmake . -DLLVM_CONFIG_EXECUTABLE=/opt/llvm/bin/llvm-config -DCMAKE_BUILD_TYPE=Release
make -j `cat /proc/cpuinfo | grep processor | wc -l`

./generator/codebrowser_generator -b ../php-src -a -o /tmp/www_data -p php-src:../php-src:7.0
./indexgenerator/codebrowser_indexgenerator ../php-src
cp -rv ./data /tmp/data

x-www-browser /tmp/www_data

If everything went according to plan, you should now have a sweet browsable (static) web display for php's source code like this one:

screenshot of woboq's CB with php stuff