aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-02-16 19:26:45 -0500
committerEli Schwartz <eschwartz@archlinux.org>2022-02-16 23:00:28 -0500
commit2974f2bcb836fc8ff7eafaa1a1d371efbc025c0f (patch)
tree27c89221a5723f83199ecb92a967838469e66858 /mesonbuild
parentaa0450adda03e40874deb5085260ee28f3f46e3b (diff)
downloadmeson-2974f2bcb836fc8ff7eafaa1a1d371efbc025c0f.zip
meson-2974f2bcb836fc8ff7eafaa1a1d371efbc025c0f.tar.gz
meson-2974f2bcb836fc8ff7eafaa1a1d371efbc025c0f.tar.bz2
fix malformed warning to print the way it was meant to print
Given a meson.build with the contents: ``` t = ' ' ``` We want to warn that this is bad. So we emitted this warning: ``` WARNING: Newline character in a string detected, use ''' (three single quotes) for multiline strings instead. This will become a hard error in a future Meson release. t = ' 4 4 ``` The line contents and the offset are printed as gibberish after a big whitespace run. These are elsewhere often passed to ParseException, which pretty-prints this, but newlines aren't an exception, merely a warning, and mlog.warning doesn't accept numeric strings as anything more meaningful than something to print as text. Fix this (by wrapping it in a ParseException) to properly print: ``` meson.build:4: WARNING: Newline character in a string detected, use ''' (three single quotes) for multiline strings instead. This will become a hard error in a future Meson release. t = ' ^ ```
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/mparser.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py
index 85b649a..97a87d8 100644
--- a/mesonbuild/mparser.py
+++ b/mesonbuild/mparser.py
@@ -15,7 +15,6 @@
from dataclasses import dataclass
import re
import codecs
-import textwrap
import types
import typing as T
from .mesonlib import MesonException
@@ -194,14 +193,11 @@ class Lexer:
elif tid in {'string', 'fstring'}:
# Handle here and not on the regexp to give a better error message.
if match_text.find("\n") != -1:
- mlog.warning(textwrap.dedent("""\
- Newline character in a string detected, use ''' (three single quotes) for multiline strings instead.
- This will become a hard error in a future Meson release.
- """),
- self.getline(line_start),
- str(lineno),
- str(col)
- )
+ msg = ParseException("Newline character in a string detected, use ''' (three single quotes) "
+ "for multiline strings instead.\n"
+ "This will become a hard error in a future Meson release.",
+ self.getline(line_start), lineno, col)
+ mlog.warning(msg, location=BaseNode(lineno, col, filename))
value = match_text[2 if tid == 'fstring' else 1:-1]
try:
value = ESCAPE_SEQUENCE_SINGLE_RE.sub(decode_match, value)