diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2020-03-01 18:17:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-01 18:17:41 +0200 |
commit | 25cbcb19a9208ebf8f5cde3f8ecb91df0a2dfebf (patch) | |
tree | cf29f0c60ac4014b9395edbe2a9c3efdad449291 /mesonbuild/mlog.py | |
parent | 74452f2a1c842291c893504876507946103ac77f (diff) | |
parent | 96f661e15046a4222fd01a7216e18de901b73cb6 (diff) | |
download | meson-25cbcb19a9208ebf8f5cde3f8ecb91df0a2dfebf.zip meson-25cbcb19a9208ebf8f5cde3f8ecb91df0a2dfebf.tar.gz meson-25cbcb19a9208ebf8f5cde3f8ecb91df0a2dfebf.tar.bz2 |
Merge pull request #6627 from jon-turney/cwd-relative-file-locations
Consistently report file locations relative to cwd
Diffstat (limited to 'mesonbuild/mlog.py')
-rw-r--r-- | mesonbuild/mlog.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index 64c16f5..a1acfa3 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -221,11 +221,19 @@ def log_once(*args: T.Union[str, AnsiDecorator], is_error: bool = False, _logged_once.add(t) log(*args, is_error=is_error, **kwargs) +# This isn't strictly correct. What we really want here is something like: +# class StringProtocol(typing_extensions.Protocol): +# +# def __str__(self) -> str: ... +# +# This would more accurately embody what this function can handle, but we +# don't have that yet, so instead we'll do some casting to work around it +def get_error_location_string(fname: str, lineno: str) -> str: + return '{}:{}:'.format(fname, lineno) + def _log_error(severity: str, *rargs: T.Union[str, AnsiDecorator], once: bool = False, **kwargs: T.Any) -> None: - from .mesonlib import get_error_location_string - from .environment import build_filename - from .mesonlib import MesonException + from .mesonlib import MesonException, relpath # The typing requirements here are non-obvious. Lists are invariant, # therefore T.List[A] and T.List[T.Union[A, B]] are not able to be joined @@ -242,7 +250,7 @@ def _log_error(severity: str, *rargs: T.Union[str, AnsiDecorator], location = kwargs.pop('location', None) if location is not None: - location_file = os.path.join(location.subdir, build_filename) + location_file = relpath(location.filename, os.getcwd()) location_str = get_error_location_string(location_file, location.lineno) # Unions are frankly awful, and we have to T.cast here to get mypy # to understand that the list concatenation is safe |