Re: [PATCH 16/19] scripts/qapi: strip trailing whitespaces
Paolo Bonzini <[email protected]>
| Newsgroups | org.nongnu.qemu-rust,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
On 12/9/25 09:48, Markus Armbruster wrote: > Paolo Bonzini <[email protected]> writes: > >> From: Marc-André Lureau <[email protected]> >> >> This help workaround a rustfmt issue. > > Which one? Pointer suffices. > >> >> Signed-off-by: Marc-André Lureau <[email protected]> >> Link: https://lore.kernel.org/r/[email protected] >> Signed-off-by: Paolo Bonzini <[email protected]> >> --- >> scripts/qapi/gen.py | 6 +++++- >> 1 file changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py >> index 0c9b8db3b02..c9721545ea7 100644 >> --- a/scripts/qapi/gen.py >> +++ b/scripts/qapi/gen.py >> @@ -58,7 +58,11 @@ def add(self, text: str) -> None: >> self._body += text >> >> def get_content(self) -> str: >> - return self._top() + self._preamble + self._body + self._bottom() >> + content = self._top() + self._preamble + self._body + self._bottom() >> + # delete trailing white-spaces (working around >> + # https://github.com/rust-lang/rustfmt/issues/4248) >> + content = re.sub(r'\s+$', '\n', content, 0, re.M) >> + return content >> >> def _top(self) -> str: >> # pylint: disable=no-self-use > > This doesn't just delete trailing whitespace, it also collapses multiple > blank lines into one: \s matches newlines. > > We lose the ability to generate multiple blank lines for all generators > based on QAPIGen: C (.c and .h), trace events, Rust. Hmm. > > Is collapsing blank lines necessary for working around the rustfmt > issue? > > The generators other than the Rust generator do not emit trailing > whitespace. Would that be practical for the Rust generator, too? The main source is stuff like %(cfg)s and %(serde_skip_if)s. Rust's syntax makes it more natural to write in this style, compared to C where you have "#ifdef"..."#endif", but it results in empty lines. I'll see if there's another way to clean up the output. Paolo