From OpenPetra Wiki
Jump to navigation Jump to search

about uncrustify

"Source Code Beautifier for C, C++, C#, ObjectiveC, D, Java, Pawn and VALA"

"The goals of this project are simple: Create a highly configurable, easily modifiable source code beautifier."

See sources at Github: https://github.com/uncrustify/uncrustify

current version used

  • Currently we still use version 0.56.

our own installer for Windows

it is easier to have an installer for Windows, instead of the zip file provided by the uncrustify project.

build installer from git master

  • need a Fedora 25 64 bit virtual machine
dnf install git automake gcc-c++ make zip python cmake
git clone https://github.com/uncrustify/uncrustify.git
cd uncrustify
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build .
# resulting linux binary is build/uncrustify
cd ..

dnf install mingw32-gcc-c++ mingw32-winpthreads-static 
mkdir buildwin-32
cd buildwin-32
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw32.cmake \
   -DCMAKE_EXE_LINKER_FLAGS="-static -s" ..
# Result in: buildwin-32/uncrustify-Uncrustify-0.64-574-bc4307b-win32.zip

Release ICT_OpenPetra_2016_06

git clone -b ICT_OpenPetra_2016_06 https://github.com/tpokorra/uncrustify.git uncrustify.ICT_OpenPetra_2016_06

Debugging uncrustify and adding tests

For C# 6 support we noticed that even version 0.62 did not support all new C# 6 features. see https://sourceforge.net/p/uncrustify/bugs/672/ for details.

On Linux, I cloned the git master of uncrustify, to see if those issues had already been fixed there.

git clone https://github.com/uncrustify/uncrustify.git
cd uncrustify
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake --build .
cd ../src/
ln -s ../build/uncrustify
cd ..

To run the tests:

./run_tests.sh c-sharp

To show diff on failure, use the parameter -g when calling uncrustify:

./run_tests.sh c-sharp -d

You can add new tests with these steps:

If uncrustify has an exception, you only get message like this:

RUN: /home/timotheusp/dev/uncrustify.tpokorra/src/uncrustify -q -c config/ben.cfg -f input/cs/exception-filters.cs  > results/cs/10160-exception-filters.cs
FAILED: 10160

Then you should run this on the commandline, but without the -q:

cd tests
/home/timotheusp/dev/uncrustify.tpokorra/src/uncrustify -c config/ben.cfg -f input/cs/exception-filters.cs  > results/cs/10160-exception-filters.cs

Some hints for debugging:

  • does the parsing work? brace_cleanup.cpp, combine.cpp
  • does the output work? space.cpp, newlines.cpp
  • chunk_t, see uncrustify_types.h.
  printf("my message %s\n", pc->str.c_str());
  printf("my message %s\n", pc->next->str.c_str());