Skip to content

Commit

Permalink
Ensure meson's prefix is a valid absolute path (#17206)
Browse files Browse the repository at this point in the history
The path / is not considered an absolute path on Windows, failing with:

    ERROR: prefix value '/' must be an absolute path

os.path.abspath ensures that "/" becomes a valid absolute path on all major
platforms, resolving to "/" on Linux and macOS, and to "C:/" (or whichever
filesystem is currently active, could be E:/ as well) on Windows.

Closes #17204.
  • Loading branch information
shoeffner authored Oct 28, 2024
1 parent 3cf4536 commit 48e9c81
Showing 1 changed file with 28 additions and 2 deletions.
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("\\", "/")

0 comments on commit 48e9c81

Please sign in to comment.