aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2025-07-23 11:07:27 +0200
committerJussi Pakkanen <jussi.pakkanen@mailbox.org>2025-07-24 16:04:48 +0300
commit884fb4eefcfdb17a8434ac4a32600e120021641a (patch)
treebab8b68c252d4b4d2d8630b7aac33eca735c628c
parent8b81e8c89660d224212d9771dc5b45a29713e16b (diff)
downloadmeson-884fb4eefcfdb17a8434ac4a32600e120021641a.zip
meson-884fb4eefcfdb17a8434ac4a32600e120021641a.tar.gz
meson-884fb4eefcfdb17a8434ac4a32600e120021641a.tar.bz2
Work around os.path.isabs bug in fs module
-rw-r--r--mesonbuild/modules/fs.py12
-rw-r--r--test cases/common/220 fs module/meson.build1
2 files changed, 10 insertions, 3 deletions
diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py
index 3d3159d..f6c1e1d 100644
--- a/mesonbuild/modules/fs.py
+++ b/mesonbuild/modules/fs.py
@@ -14,7 +14,7 @@ from .. import mlog
from ..build import BuildTarget, CustomTarget, CustomTargetIndex, InvalidArguments
from ..interpreter.type_checking import INSTALL_KW, INSTALL_MODE_KW, INSTALL_TAG_KW, NoneType
from ..interpreterbase import FeatureNew, KwargInfo, typed_kwargs, typed_pos_args, noKwargs
-from ..mesonlib import File, MesonException, has_path_sep, path_is_in_root, relpath
+from ..mesonlib import File, MesonException, has_path_sep, is_windows, path_is_in_root, relpath
if T.TYPE_CHECKING:
from . import ModuleState
@@ -110,9 +110,15 @@ class FSModule(ExtensionModule):
@FeatureNew('fs.is_absolute', '0.54.0')
@typed_pos_args('fs.is_absolute', (str, File))
def is_absolute(self, state: ModuleState, args: T.Tuple[FileOrString], kwargs: T.Dict[str, T.Any]) -> bool:
- if isinstance(args[0], File):
+ path = args[0]
+ if isinstance(path, File):
FeatureNew('fs.is_absolute with file', '0.59.0').use(state.subproject, location=state.current_node)
- return os.path.isabs(str(args[0]))
+ path = str(path)
+ if is_windows():
+ # os.path.isabs was broken for Windows before Python 3.13, so we implement it ourselves
+ path = path[:3].replace(posixsep, ntsep)
+ return path.startswith(ntsep * 2) or path.startswith(':' + ntsep, 1)
+ return path.startswith(posixsep)
@noKwargs
@FeatureNew('fs.as_posix', '0.54.0')
diff --git a/test cases/common/220 fs module/meson.build b/test cases/common/220 fs module/meson.build
index 34eaab7..f90a996 100644
--- a/test cases/common/220 fs module/meson.build
+++ b/test cases/common/220 fs module/meson.build
@@ -52,6 +52,7 @@ unixabs = '/foo'
if is_windows
assert(fs.is_absolute(winabs), 'is_absolute windows not detected')
assert(not fs.is_absolute(unixabs), 'is_absolute unix false positive')
+ assert(fs.is_absolute('//foo'), 'is_absolute failed on incomplete UNC path')
else
assert(fs.is_absolute(unixabs), 'is_absolute unix not detected')
assert(not fs.is_absolute(winabs), 'is_absolute windows false positive')