From 8a2db0aabddbec2be4e7d57d5f3d46acaa58018d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 5 Jul 2018 12:04:57 -0400 Subject: [PATCH] qapi: mcgen() shouldn't indent # lines Skip preprocessor lines when adding indentation, since that would likely result in invalid code. Backports commit 485d948ce86f5a096dc848ec31b70cd66452d40d from qemu --- qemu/scripts/qapi/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qemu/scripts/qapi/common.py b/qemu/scripts/qapi/common.py index 0c9eb053..63ec3a7a 100644 --- a/qemu/scripts/qapi/common.py +++ b/qemu/scripts/qapi/common.py @@ -1953,8 +1953,8 @@ def cgen(code, **kwds): if indent_level: indent = genindent(indent_level) # re.subn() lacks flags support before Python 2.7, use re.compile() - raw = re.subn(re.compile(r'^.', re.MULTILINE), - indent + r'\g<0>', raw) + raw = re.subn(re.compile(r'^(?!(#|$))', re.MULTILINE), + indent, raw) raw = raw[0] return re.sub(re.escape(eatspace) + r' *', '', raw)