Skip to content

Commit

Permalink
Add allow_abs_paths option
Browse files Browse the repository at this point in the history
The existing error upon detecting use of an absolute include directory
path (within the source tree) is a well-intentioned but blunt tool that
unnecessarily prevents use of valid and safe absolute include dir paths.

Absolute paths can be constructed from build-relative absolute paths
(e.g. src_root = project_source_root(), ... src_root / 'dir/inc') and so
use consistent 'src_root'-relative path construction across multiple
meson.build files while also making each meson.build file easy to move
without breaking through use of pure relative paths.

Discussed with more context and rationale here -
mesonbuild#12244

Setting the option `allow_abs_paths=true` prevents this error check and
is obviously used at your own risk.
  • Loading branch information
GertyP committed Sep 21, 2023
1 parent 7440767 commit d129bb2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/markdown/Builtin-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ machine](#specifying-options-per-machine) section for details.
| wrap_mode {default, nofallback,<br>nodownload, forcefallback, nopromote} | default | Wrap mode to use | no | no |
| force_fallback_for | [] | Force fallback for those dependencies | no | no |
| vsenv | false | Activate Visual Studio environment | no | no |
| allow_abs_paths | false | Suppress errors from use of absolute include paths | no | yes |

#### Details for `backend`

Expand Down
1 change: 1 addition & 0 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,7 @@ def add_to_argparse(self, name: str, parser: argparse.ArgumentParser, help_suffi
(OptionKey('wrap_mode'), BuiltinOption(UserComboOption, 'Wrap mode', 'default', choices=['default', 'nofallback', 'nodownload', 'forcefallback', 'nopromote'])),
(OptionKey('force_fallback_for'), BuiltinOption(UserArrayOption, 'Force fallback for those subprojects', [])),
(OptionKey('vsenv'), BuiltinOption(UserBooleanOption, 'Activate Visual Studio environment', False, readonly=True)),
(OptionKey('allow_abs_paths'), BuiltinOption(UserBooleanOption, 'Suppress errors from use of absolute include paths', False, yielding=False)),

# Pkgconfig module
(OptionKey('relocatable', module='pkgconfig'),
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2795,7 +2795,7 @@ def build_incdir_object(self, incdir_strings: T.List[str], is_system: bool = Fal
absbase_build = os.path.join(build_root, self.subdir)

for a in incdir_strings:
if path_is_in_root(Path(a), Path(src_root)):
if not self.coredata.options[OptionKey('allow_abs_paths')].value and path_is_in_root(Path(a), Path(src_root)):
raise InvalidArguments(textwrap.dedent('''\
Tried to form an absolute path to a dir in the source tree.
You should not do that but use relative paths instead, for
Expand Down
1 change: 1 addition & 0 deletions mesonbuild/utils/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2185,6 +2185,7 @@ class OptionType(enum.IntEnum):
'pkg_config_path',
'cmake_prefix_path',
'vsenv',
'allow_abs_paths',
}


Expand Down

0 comments on commit d129bb2

Please sign in to comment.