Hi On Mon, Jul 17, 2017 at 1:14 PM, Gerd Hoffmann <kra...@redhat.com> wrote: > On Mon, 2017-07-17 at 10:58 +0000, Marc-André Lureau wrote: >> Hi >> >> On Mon, Jul 17, 2017 at 12:49 PM Gerd Hoffmann <kra...@redhat.com> >> wrote: >> > On Mon, 2017-07-17 at 10:36 +0000, Marc-André Lureau wrote: >> > > Hi >> > > >> > > On Mon, Jul 17, 2017 at 12:18 PM Gerd Hoffmann <kra...@redhat.com >> > > >> > > wrote: >> > > > Script to reformat sources in qemu style. >> > > > >> > > > Signed-off-by: Gerd Hoffmann <kra...@redhat.com> >> > > >> > > A quite powerful approach would be to use clang-format: https://l >> > ists >> > > .gnu.org/archive/html/qemu-devel/2015-10/msg01278.html >> > > >> > > It comes with a bunch of editor integration and scripts. My >> > config >> > > could use a bit more tweaking though, I haven't been using it for >> > a >> > > while, and newer version have more options. >> > >> > Hmm, I want reformat all audio stuff to qemu code style some day, >> > the >> > current situation where patches are either break qemu code style or >> > lead to mixed-style in the audio source files isn't very good. >> > >> > I don't mind much which tool we use for that, I picked indent >> > mostly >> > because I know that one. If clang-format can do that too, fine >> > with >> > me. I'm missing documentation though, there is no man-page and >> > there >> > isn't anything in /usr/share/doc/clang-3.4.2 either ... >> >> Afaik, most of clang-tools documentation is only in html. The most >> recent version is online at >> https://clang.llvm.org/docs/ClangFormat.html & >> https://clang.llvm.org/docs/ClangFormatStyleOptions.html > > Can you add those links as comments to the .clang-format file?
Sorry for the late reply, fwiw, my best attempt so far: https://gist.github.com/elmarco/aa5e0b23567f46fb7f0e73cde586a0c1 It's not perfect, you can easily see the result by running inplace with clang-format -i && git diff. In particular: - array declaration is often much uglier (with the indendation aligned to open brace) - indent seems doing worse. also related: https://bugs.llvm.org/show_bug.cgi?id=18455 - it uses a space in "FOREACH (" macros - good/bad ? - long line are splitted in less friendly way than manual split - also true with indent - qemu doesn't have BinPack true/false, it uses a mix - clang-format should learn that - perhaps covered by https://bugs.llvm.org/show_bug.cgi?id=31907 - we may want not to do #include ordering - I find it nicer though The point is not to apply blindly clang-format over the whole code base, but rather to give a decent default formatting when running clang-tools, or simply when making a patch. For this, .clang-format is necessary, and I would rather have it in qemu tree than in my own working directory. -- Marc-André Lureau