diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-06-17 09:52:38 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2021-06-18 09:52:23 -0700 |
commit | 3ec2cf9c60d42735f26b3539c6dfc9af7aead7ca (patch) | |
tree | e86d1e7bc3a4ef4a9673d0bf9ddf6ca31936350f | |
parent | 5f3b73beb594b837e7b817b570c0a722c9cc2f63 (diff) | |
download | meson-3ec2cf9c60d42735f26b3539c6dfc9af7aead7ca.zip meson-3ec2cf9c60d42735f26b3539c6dfc9af7aead7ca.tar.gz meson-3ec2cf9c60d42735f26b3539c6dfc9af7aead7ca.tar.bz2 |
interpreter: add type annotations to build_incdir_object
and use textwrap.dedent to make the very large messages more readable
and not break method folding.
-rw-r--r-- | mesonbuild/interpreter/interpreter.py | 59 | ||||
-rw-r--r-- | test cases/failing/45 abspath to srcdir/test.json | 2 |
2 files changed, 31 insertions, 30 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index b5335e6..93cabec 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -57,7 +57,7 @@ import re import stat import collections import typing as T - +import textwrap import importlib if T.TYPE_CHECKING: @@ -2178,7 +2178,7 @@ This will become a hard error in the future.''' % kwargs['input'], location=self def func_include_directories(self, node, args, kwargs): return self.build_incdir_object(args, kwargs.get('is_system', False)) - def build_incdir_object(self, incdir_strings, is_system=False): + def build_incdir_object(self, incdir_strings: T.List[str], is_system: bool = False) -> IncludeDirsHolder: if not isinstance(is_system, bool): raise InvalidArguments('Is_system must be boolean.') src_root = self.environment.get_source_dir() @@ -2188,46 +2188,47 @@ This will become a hard error in the future.''' % kwargs['input'], location=self for a in incdir_strings: if a.startswith(src_root): - raise InvalidArguments('Tried to form an absolute path to a source dir. ' - 'You should not do that but use relative paths instead.' - ''' + raise InvalidArguments(textwrap.dedent('''\ + Tried to form an absolute path to a source dir. + You should not do that but use relative paths instead. -To get include path to any directory relative to the current dir do + To get include path to any directory relative to the current dir do -incdir = include_directories(dirname) + incdir = include_directories(dirname) -After this incdir will contain both the current source dir as well as the -corresponding build dir. It can then be used in any subdirectory and -Meson will take care of all the busywork to make paths work. + After this incdir will contain both the current source dir as well as the + corresponding build dir. It can then be used in any subdirectory and + Meson will take care of all the busywork to make paths work. -Dirname can even be '.' to mark the current directory. Though you should -remember that the current source and build directories are always -put in the include directories by default so you only need to do -include_directories('.') if you intend to use the result in a -different subdirectory. -''') + Dirname can even be '.' to mark the current directory. Though you should + remember that the current source and build directories are always + put in the include directories by default so you only need to do + include_directories('.') if you intend to use the result in a + different subdirectory. + ''')) else: try: self.validate_within_subproject(self.subdir, a) except InterpreterException: mlog.warning('include_directories sandbox violation!') - print(f'''The project is trying to access the directory {a} which belongs to a different -subproject. This is a problem as it hardcodes the relative paths of these two projeccts. -This makes it impossible to compile the project in any other directory layout and also -prevents the subproject from changing its own directory layout. + print(textwrap.dedent(f'''\ + The project is trying to access the directory {a} which belongs to a different + subproject. This is a problem as it hardcodes the relative paths of these two projeccts. + This makes it impossible to compile the project in any other directory layout and also + prevents the subproject from changing its own directory layout. -Instead of poking directly at the internals the subproject should be executed and -it should set a variable that the caller can then use. Something like: + Instead of poking directly at the internals the subproject should be executed and + it should set a variable that the caller can then use. Something like: -# In subproject -some_dep = declare_depencency(include_directories: include_directories('include')) + # In subproject + some_dep = declare_depencency(include_directories: include_directories('include')) -# In parent project -some_dep = depencency('some') -executable(..., dependencies: [some_dep]) + # In parent project + some_dep = depencency('some') + executable(..., dependencies: [some_dep]) -This warning will become a hard error in a future Meson release. -''') + This warning will become a hard error in a future Meson release. + ''')) absdir_src = os.path.join(absbase_src, a) absdir_build = os.path.join(absbase_build, a) if not os.path.isdir(absdir_src) and not os.path.isdir(absdir_build): diff --git a/test cases/failing/45 abspath to srcdir/test.json b/test cases/failing/45 abspath to srcdir/test.json index b6a87fe..177bac1 100644 --- a/test cases/failing/45 abspath to srcdir/test.json +++ b/test cases/failing/45 abspath to srcdir/test.json @@ -1,7 +1,7 @@ { "stdout": [ { - "line": "test cases/failing/45 abspath to srcdir/meson.build:3:0: ERROR: Tried to form an absolute path to a source dir. You should not do that but use relative paths instead." + "line": "test cases/failing/45 abspath to srcdir/meson.build:3:0: ERROR: Tried to form an absolute path to a source dir." } ] } |