Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure meson's prefix is a valid absolute path #17206

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions conan/tools/meson/meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def configure(self, reconfigure=False):
else: # extra native file for cross-building scenarios
cmd += f' --native-file "{native}"'
cmd += ' "{}" "{}"'.format(build_folder, source_folder)
# Issue related: https://github.com/mesonbuild/meson/issues/12880
cmd += ' --prefix=/' # this must be an absolute path, otherwise, meson complains
cmd += f" --prefix={self._prefix}"
self._conanfile.output.info("Meson configure cmd: {}".format(cmd))
self._conanfile.run(cmd)

Expand Down Expand Up @@ -112,3 +111,30 @@ def _install_verbosity(self):
# so it's a bit backwards
verbosity = self._conanfile.conf.get("tools.build:verbosity", choices=("quiet", "verbose"))
return "--quiet" if verbosity else ""

@property
def _prefix(self):
"""Generate a valid ``--prefix`` argument value for meson.
For conan, the prefix must be similar to the Unix root directory ``/``.

The result of this function should be passed to
``meson setup --prefix={self._prefix} ...``

Python 3.13 changed the semantics of ``/`` on the Windows ntpath module,
it is now special-cased as a relative directory.
Thus, ``os.path.isabs("/")`` is true on Linux but false on Windows.
So for Windows, an equivalent path is ``C:\\``. However, this can be
parsed wrongly in meson in specific circumstances due to the trailing
backslash. Hence, we also use forward slashes for Windows, leaving us
with ``C:/`` or similar paths.

See also
--------
* The meson issue discussing the need to set ``--prefix`` to ``/``:
`mesonbuild/meson#12880 <https://github.com/mesonbuild/meson/issues/12880>`_
* The cpython PR introducing the ``/`` behavior change:
`python/cpython#113829 <https://github.com/python/cpython/pull/113829>`_
* The issue detailing the erroneous parsing of ``\\``:
`conan-io/conan#14213 <https://github.com/conan-io/conan/issues/14213>`_
"""
return os.path.abspath("/").replace("\\", "/")