diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2023-02-27 17:31:57 -0500 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-02-28 09:10:15 -0500 |
commit | c2db6eb2e2321ebdb08a696fd7272b17ee7a4423 (patch) | |
tree | 1deab4c0c0d78f57ad621ee68f60792188976f96 | |
parent | 808d5934dd6c6a6c16f66e9dc51dae6e83e02cef (diff) | |
download | meson-c2db6eb2e2321ebdb08a696fd7272b17ee7a4423.zip meson-c2db6eb2e2321ebdb08a696fd7272b17ee7a4423.tar.gz meson-c2db6eb2e2321ebdb08a696fd7272b17ee7a4423.tar.bz2 |
msetup: clarify error message when wrong directories are specified
This can happen from typos, which then confusingly claim that neither
build directory has a meson.build file because the implicit . directory
was not actually one of the directories. Instead a random command line
argument was interpreted as a directory name.
Fixes #11472
-rw-r--r-- | mesonbuild/msetup.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/mesonbuild/msetup.py b/mesonbuild/msetup.py index 41cc441..e37f2a9 100644 --- a/mesonbuild/msetup.py +++ b/mesonbuild/msetup.py @@ -15,7 +15,7 @@ from __future__ import annotations import typing as T import time -import sys, stat +import sys import datetime import os.path import platform @@ -118,6 +118,7 @@ class MesonApp: return os.path.exists(fname) def validate_core_dirs(self, dir1: str, dir2: str) -> T.Tuple[str, str]: + invalid_msg_prefix = f'Neither source directory {dir1!r} nor build directory {dir2!r}' if dir1 is None: if dir2 is None: if not os.path.exists('meson.build') and os.path.exists('../meson.build'): @@ -129,14 +130,16 @@ class MesonApp: dir2 = os.getcwd() ndir1 = os.path.abspath(os.path.realpath(dir1)) ndir2 = os.path.abspath(os.path.realpath(dir2)) - if not os.path.exists(ndir1): - os.makedirs(ndir1) - if not os.path.exists(ndir2): - os.makedirs(ndir2) - if not stat.S_ISDIR(os.stat(ndir1).st_mode): - raise MesonException(f'{dir1} is not a directory') - if not stat.S_ISDIR(os.stat(ndir2).st_mode): - raise MesonException(f'{dir2} is not a directory') + if not os.path.exists(ndir1) and not os.path.exists(ndir2): + raise MesonException(f'{invalid_msg_prefix} exist.') + try: + os.makedirs(ndir1, exist_ok=True) + except FileExistsError as e: + raise MesonException(f'{dir1} is not a directory') from e + try: + os.makedirs(ndir2, exist_ok=True) + except FileExistsError as e: + raise MesonException(f'{dir2} is not a directory') from e if os.path.samefile(ndir1, ndir2): # Fallback to textual compare if undefined entries found has_undefined = any((s.st_ino == 0 and s.st_dev == 0) for s in (os.stat(ndir1), os.stat(ndir2))) @@ -148,7 +151,7 @@ class MesonApp: return ndir1, ndir2 if self.has_build_file(ndir2): return ndir2, ndir1 - raise MesonException(f'Neither directory contains a build file {environment.build_filename}.') + raise MesonException(f'{invalid_msg_prefix} contain a build file {environment.build_filename}.') def add_vcs_ignore_files(self, build_dir: str) -> None: if os.listdir(build_dir): |