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
This commit is contained in:
Marc-André Lureau 2018-07-05 12:04:57 -04:00 committed by Lioncash
parent 2ba3229cbb
commit 8a2db0aabd
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -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)