add scripts/indent.sh
PATCH 1/1 add scripts/indent.sh
Script to reformat sources in qemu style.
--- scripts/indent.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 scripts/indent.sh
scripts/indent.sh new file +11 -0
@@ -0,0 +1,11 @@ +#!/bin/sh +# +# indent wrapper script, with args to format +# source code according to qemu coding style. +# +indent --ignore-profile \ + --k-and-r-style \ + --line-length 80 \ + --indent-level 4 \ + --no-tabs \ + "$@"
Signature · 1 line
2.9.3
Hi
Quoted 4 lines · Gerd Hoffmann
Script to reformat sources in qemu style.
Signed-off-by Gerd Hoffmann <[email protected]>
A quite powerful approach would be to use clang-format:
https://lists.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.
Quoted 26 lines
--- scripts/indent.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 scripts/indent.shscripts/indent.sh new file +11
-1@@ -0,0 +1,11 @@ +#!/bin/sh +# +# indent wrapper script, with args to format +# source code according to qemu coding style. +# +indent --ignore-profile \ + --k-and-r-style \ + --line-length 80 \ + --indent-level 4 \ + --no-tabs \ + "$@" --2.9.3
Quoted 1 line
--
Marc-André Lureau
Quoted 15 lines · Gerd Hoffmann
Script to reformat sources in qemu style.
Signed-off-by Gerd Hoffmann <[email protected]>--- scripts/indent.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 scripts/indent.shscripts/indent.sh new file +1
-0@@ -0,0 +1,11 @@ +#!/bin/sh
scripts/indent.sh line 11
Quoted 10 lines
scripts/indent.sh new file +10
-0+# +# indent wrapper script, with args to format +# source code according to qemu coding style. +# +indent --ignore-profile \ + --k-and-r-style \ + --line-length 80 \ + --indent-level 4 \ + --no-tabs \ + "$@"
A quick pass of this over target/arm suggests it's probably missing some arguments. For instance, things it gets wrong:
(1) it's adding spaces after '*' in "SomeType *foo" parameters:
-static void aarch64_note_init(struct aarch64_note *note, DumpState *s, +static void aarch64_note_init(struct aarch64_note *note, DumpState * s,
(2) weird extra space after cast:
- ((TaskState *)cs->opaque)->swi_errno = err;
+ ((TaskState *) cs->opaque)->swi_errno = err;
(3) weird spacing around address-of operator:
- cpu_memory_rw_debug(cs, arm_flen_buf(cpu) + 32, (uint8_t *)&size, 4, 0);
+ cpu_memory_rw_debug(cs, arm_flen_buf(cpu) + 32, (uint8_t *) & size, 4, 0);
(4) weird spacing addition to a negative number constant:
- return (uint32_t)-1;
+ return (uint32_t) - 1;
(5) mis-indentation of second line of multi-line assignment:
static Property arm_cpu_reset_cbar_property =
- DEFINE_PROP_UINT64("reset-cbar", ARMCPU, reset_cbar, 0);
+DEFINE_PROP_UINT64("reset-cbar", ARMCPU, reset_cbar, 0);
(6) incorrectly deletes spaces in a named-struct-field initializer:
- .name = "IFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 1,
+ .name = "IFAR",.cp = 15,.crn = 6,.crm = 0,.opc1 = 0,.opc2 = 1,
(7) gets confused by HELPER() macro in function definition:
-int64_t HELPER(sdiv64)(int64_t num, int64_t den) -{
+int64_t HELPER(sdiv64) (int64_t num, int64_t den) {
(8) It disagrees with our emacs indent config about level of indent for expressions:
return arm_feature(env, ARM_FEATURE_PMSA) &&
- arm_feature(env, ARM_FEATURE_V7);
+ arm_feature(env, ARM_FEATURE_V7);
--no-space-after-casts ought to fix 2, but in practice doesn't seem to...
thanks
-- PMM
Quoted 6 lines · Marc-André Lureau
Hi
Quoted 2 lines · Gerd Hoffmann
Script to reformat sources in qemu style.
Quoted 8 lines
Quoted 1 line
Signed-off-by Gerd Hoffmann <[email protected]>A quite powerful approach would be to use clang-format: https://lists
.gnu.org/archive/html/qemu-devel/2015-10/msg01278.htmlIt 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 ...
cheers,
Gerd
Hi
Quoted 16 lines · Gerd Hoffmann
Quoted 6 lines · Marc-André Lureau
Hi
Quoted 2 lines · Gerd Hoffmann
Script to reformat sources in qemu style.
Quoted 8 lines
Quoted 1 line
Signed-off-by Gerd Hoffmann <[email protected]>A quite powerful approach would be to use clang-format: https://lists
.gnu.org/archive/html/qemu-devel/2015-10/msg01278.htmlIt 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.
Quoted 9 lines
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.2either ...
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
Another advantage of using clang-format, is that it should be used by other clang refactoring tools (as in my clang-tidy series for ex).
Quoted 4 lines
cheers,
Gerd--
Marc-André Lureau
Quoted 37 lines · Marc-André Lureau
Hi
Quoted 25 lines · Gerd Hoffmann
Quoted 10 lines · Marc-André Lureau
Hi
On Mon, Jul 17, 2017 at 12:18 PM Gerd Hoffmann <[email protected]
Quoted 3 lines · wrote:
Script to reformat sources in qemu style.
Signed-off-by Gerd Hoffmann <[email protected]>A quite powerful approach would be to use clang-format: https://l
ists
Quoted 3 lines
.gnu.org/archive/html/qemu-devel/2015-10/msg01278.html
It comes with a bunch of editor integration and scripts. My
config
Quoted 1 line
could use a bit more tweaking though, I haven't been using it for
a
Quoted 1 line
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.Quoted 7 lines
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.2either ...
Quoted 4 lines
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?
cheers,
Gerd
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH] add scripts/indent.sh
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
8352810 add scripts/indent.sh
=== OUTPUT BEGIN ===
Checking PATCH 1/1: add scripts/indent.sh...
ERROR: code indent should never use tabs
#22: FILE: scripts/indent.sh:6:
+indent^I--ignore-profile^I\$
ERROR: code indent should never use tabs
#23: FILE: scripts/indent.sh:7:
+^I--k-and-r-style^I^I\$
ERROR: code indent should never use tabs
#24: FILE: scripts/indent.sh:8:
+^I--line-length 80^I\$
ERROR: code indent should never use tabs
#25: FILE: scripts/indent.sh:9:
+^I--indent-level 4^I\$
ERROR: code indent should never use tabs
#26: FILE: scripts/indent.sh:10:
+^I--no-tabs^I^I\$
ERROR: code indent should never use tabs
#27: FILE: scripts/indent.sh:11:
+^I"$@"$
total: 6 errors, 0 warnings, 11 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
Quoted 1 line · On 17 July 2017 at 19:11, <[email protected]> wrote:
This series seems to have some coding style problems.
Very ironic :-)
thanks
-- PMM
Hi
Quoted 38 lines · Gerd Hoffmann
Quoted 37 lines · Marc-André Lureau
Hi
Quoted 32 lines · Gerd Hoffmann
Quoted 10 lines · Marc-André Lureau
Hi
On Mon, Jul 17, 2017 at 12:18 PM Gerd Hoffmann <[email protected]
Quoted 3 lines · wrote:
Script to reformat sources in qemu style.
Signed-off-by Gerd Hoffmann <[email protected]>A quite powerful approach would be to use clang-format: https://l
ists
Quoted 3 lines
.gnu.org/archive/html/qemu-devel/2015-10/msg01278.html
It comes with a bunch of editor integration and scripts. My
config
Quoted 1 line
could use a bit more tweaking though, I haven't been using it for
a
Quoted 1 line
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.2either ...
Quoted 6 lines
Quoted 4 lines
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.htmlCan 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.
Signature · 1 line
Marc-André Lureau