aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2018-01-03 22:32:40 +0200
committerGitHub <noreply@github.com>2018-01-03 22:32:40 +0200
commit65f78a722ad0f8ab260e7cf24636ef38e8bd957f (patch)
tree76024acbc0c7d90e8edd69ad07c79124de622a46 /mesonbuild
parentc814f1145bc521efd0a46b033751a6f844d24df5 (diff)
parentbcc95d7dd703779228ec81b92197e010d0e5a1ea (diff)
downloadmeson-65f78a722ad0f8ab260e7cf24636ef38e8bd957f.zip
meson-65f78a722ad0f8ab260e7cf24636ef38e8bd957f.tar.gz
meson-65f78a722ad0f8ab260e7cf24636ef38e8bd957f.tar.bz2
Merge pull request #2856 from jon-turney/warning-location
Consolidate warning location formatting
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/interpreter.py6
-rw-r--r--mesonbuild/interpreterbase.py18
-rw-r--r--mesonbuild/mlog.py7
-rw-r--r--mesonbuild/mparser.py5
4 files changed, 23 insertions, 13 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 1abc134..29b4033 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1574,7 +1574,7 @@ class Interpreter(InterpreterBase):
modname = args[0]
if modname.startswith('unstable-'):
plainname = modname.split('-', 1)[1]
- mlog.warning('Module %s has no backwards or forwards compatibility and might not exist in future releases.' % modname)
+ mlog.warning('Module %s has no backwards or forwards compatibility and might not exist in future releases' % modname, location=node)
modname = 'unstable_' + plainname
if modname not in self.environment.coredata.modules:
try:
@@ -1935,7 +1935,7 @@ to directly access options of other subprojects.''')
@noKwargs
def func_warning(self, node, args, kwargs):
argstr = self.get_message_string_arg(node)
- mlog.warning('%s in file %s, line %d' % (argstr, os.path.join(node.subdir, 'meson.build'), node.lineno))
+ mlog.warning(argstr, location=node)
@noKwargs
def func_error(self, node, args, kwargs):
@@ -2751,7 +2751,7 @@ root and issuing %s.
mlog.warning(
"The variable(s) %s in the input file %s are not "
"present in the given configuration data" % (
- var_list, inputfile))
+ var_list, inputfile), location=node)
else:
mesonlib.dump_conf_header(ofile_abs, conf.held_object)
conf.mark_used()
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index 91f4bd3..9dc6b0f 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -18,7 +18,7 @@
from . import mparser, mesonlib, mlog
from . import environment, dependencies
-import os, copy, re
+import os, copy, re, types
from functools import wraps
# Decorators for method calls.
@@ -63,17 +63,19 @@ class permittedKwargs:
def __call__(self, f):
@wraps(f)
def wrapped(s, node_or_state, args, kwargs):
+ loc = types.SimpleNamespace()
if hasattr(s, 'subdir'):
- subdir = s.subdir
- lineno = s.current_lineno
+ loc.subdir = s.subdir
+ loc.lineno = s.current_lineno
elif hasattr(node_or_state, 'subdir'):
- subdir = node_or_state.subdir
- lineno = node_or_state.current_lineno
+ loc.subdir = node_or_state.subdir
+ loc.lineno = node_or_state.current_lineno
+ else:
+ loc = None
for k in kwargs:
if k not in self.permitted:
- fname = os.path.join(subdir, environment.build_filename)
- mlog.warning('''Passed invalid keyword argument "%s" in %s line %d.
-This will become a hard error in the future.''' % (k, fname, lineno))
+ mlog.warning('''Passed invalid keyword argument "{}"'''.format(k), location=loc)
+ mlog.warning('This will become a hard error in the future.')
return f(s, node_or_state, args, kwargs)
return wrapped
diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py
index a0d07ec..aa2ac20 100644
--- a/mesonbuild/mlog.py
+++ b/mesonbuild/mlog.py
@@ -103,6 +103,13 @@ def log(*args, **kwargs):
force_print(*arr, **kwargs)
def warning(*args, **kwargs):
+ from . import environment
+
+ if kwargs.get('location'):
+ location = kwargs['location']
+ del kwargs['location']
+ args += ('in file {}, line {}.'.format(os.path.join(location.subdir, environment.build_filename), location.lineno),)
+
log(yellow('WARNING:'), *args, **kwargs)
# Format a list for logging purposes as a string. It separates
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py
index 782b7a7..eb03393 100644
--- a/mesonbuild/mparser.py
+++ b/mesonbuild/mparser.py
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os, re
+import re
from .mesonlib import MesonException
from . import mlog
@@ -368,7 +368,8 @@ class ArgumentNode:
def set_kwarg(self, name, value):
if name in self.kwargs:
- mlog.warning('Keyword argument "%s" defined multiple times in file %s, line %d. This will be an error in future Meson releases.' % (name, os.path.join(self.subdir, 'meson.build'), self.lineno))
+ mlog.warning('Keyword argument "{}" defined multiple times'.format(name), location=self)
+ mlog.warning('This will be an error in future Meson releases.')
self.kwargs[name] = value
def num_args(self):