aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2022-01-29 19:54:15 +0100
committerEli Schwartz <eschwartz93@gmail.com>2022-02-09 11:04:59 -0500
commitdf451f10130fc5d64cf1c65504a69bedd2fbdfdd (patch)
treeefc457f194ce5312bb59da5791f5f10eaa2bbabf /mesonbuild
parentd2d9df3121d228797d0b3bccfd614849b637c0fe (diff)
downloadmeson-df451f10130fc5d64cf1c65504a69bedd2fbdfdd.zip
meson-df451f10130fc5d64cf1c65504a69bedd2fbdfdd.tar.gz
meson-df451f10130fc5d64cf1c65504a69bedd2fbdfdd.tar.bz2
meson: Allow directory options outside of prefix
This bring us in line with Autotools and CMake and it is useful for platforms like Nix, which install projects into multiple independent prefixes. As a consequence, `get_option` might return absolute paths for some directory options, if a directory outside of prefix is passed. This is technically a backwards incompatible change but its effect should be minimal, thanks to widespread use of `join_paths`/`/` operator and pkg-config generator module. It should only cause an issue when a path were constructed by concatenating the value of directory path option. Also remove a comment about commonpath since we do not use that since <https://github.com/mesonbuild/meson/commit/00f5dadd5b7d71c30bd7393d165a87f554eb92e5>. Fixes: https://github.com/mesonbuild/meson/issues/2561
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/coredata.py36
1 files changed, 17 insertions, 19 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 2bb89a2..4a84467 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -549,14 +549,13 @@ class CoreData:
def sanitize_dir_option_value(self, prefix: str, option: OptionKey, value: T.Any) -> T.Any:
'''
- If the option is an installation directory option and the value is an
- absolute path, check that it resides within prefix and return the value
- as a path relative to the prefix.
+ If the option is an installation directory option, the value is an
+ absolute path and resides within prefix, return the value
+ as a path relative to the prefix. Otherwise, return it as is.
- This way everyone can do f.ex, get_option('libdir') and be sure to get
- the library directory relative to prefix.
-
- .as_posix() keeps the posix-like file separators Meson uses.
+ This way everyone can do f.ex, get_option('libdir') and usually get
+ the library directory relative to prefix, even though it really
+ should not be relied upon.
'''
try:
value = PurePath(value)
@@ -564,21 +563,20 @@ class CoreData:
return value
if option.name.endswith('dir') and value.is_absolute() and \
option not in BULITIN_DIR_NOPREFIX_OPTIONS:
- # Value must be a subdir of the prefix
- # commonpath will always return a path in the native format, so we
- # must use pathlib.PurePath to do the same conversion before
- # comparing.
- msg = ('The value of the \'{!s}\' option is \'{!s}\' which must be a '
- 'subdir of the prefix {!r}.\nNote that if you pass a '
- 'relative path, it is assumed to be a subdir of prefix.')
- # os.path.commonpath doesn't understand case-insensitive filesystems,
- # but PurePath().relative_to() does.
try:
+ # Try to relativize the path.
value = value.relative_to(prefix)
except ValueError:
- raise MesonException(msg.format(option, value, prefix))
- if '..' in str(value):
- raise MesonException(msg.format(option, value, prefix))
+ # Path is not relative, let’s keep it as is.
+ pass
+ if '..' in value.parts:
+ raise MesonException(
+ f'The value of the \'{option}\' option is \'{value}\' but '
+ 'directory options are not allowed to contain \'..\'.\n'
+ f'If you need a path outside of the {prefix!r} prefix, '
+ 'please use an absolute path.'
+ )
+ # .as_posix() keeps the posix-like file separators Meson uses.
return value.as_posix()
def init_builtins(self, subproject: str) -> None: