summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/utils/platform.py5
-rw-r--r--mesonbuild/utils/posix.py11
-rw-r--r--mesonbuild/utils/win32.py11
-rw-r--r--mesonbuild/wrap/wrap.py2
4 files changed, 25 insertions, 4 deletions
diff --git a/mesonbuild/utils/platform.py b/mesonbuild/utils/platform.py
index 8fdfee6e5..f9eaa47ed 100644
--- a/mesonbuild/utils/platform.py
+++ b/mesonbuild/utils/platform.py
@@ -20,10 +20,13 @@ class DirectoryLockAction(enum.Enum):
FAIL = 2
class DirectoryLockBase:
- def __init__(self, directory: str, lockfile: str, action: DirectoryLockAction, err: str) -> None:
+ def __init__(self, directory: str, lockfile: str, action: DirectoryLockAction, err: str,
+ optional: bool = False) -> None:
self.action = action
self.err = err
self.lockpath = os.path.join(directory, lockfile)
+ self.optional = optional
+ self.lockfile: T.Optional[T.TextIO] = None
def __enter__(self) -> None:
mlog.debug('Calling the no-op version of DirectoryLock')
diff --git a/mesonbuild/utils/posix.py b/mesonbuild/utils/posix.py
index a601dee46..9dbc5c1ac 100644
--- a/mesonbuild/utils/posix.py
+++ b/mesonbuild/utils/posix.py
@@ -17,7 +17,16 @@ __all__ = ['DirectoryLock', 'DirectoryLockAction']
class DirectoryLock(DirectoryLockBase):
def __enter__(self) -> None:
- self.lockfile = open(self.lockpath, 'w+', encoding='utf-8')
+ try:
+ self.lockfile = open(self.lockpath, 'w+', encoding='utf-8')
+ except (FileNotFoundError, IsADirectoryError):
+ # For FileNotFoundError, there is nothing to lock.
+ # For IsADirectoryError, something is seriously wrong.
+ raise
+ except OSError:
+ if self.action == DirectoryLockAction.IGNORE or self.optional:
+ return
+
try:
flags = fcntl.LOCK_EX
if self.action != DirectoryLockAction.WAIT:
diff --git a/mesonbuild/utils/win32.py b/mesonbuild/utils/win32.py
index 22aea8680..8f1a0998d 100644
--- a/mesonbuild/utils/win32.py
+++ b/mesonbuild/utils/win32.py
@@ -17,7 +17,16 @@ __all__ = ['DirectoryLock', 'DirectoryLockAction']
class DirectoryLock(DirectoryLockBase):
def __enter__(self) -> None:
- self.lockfile = open(self.lockpath, 'w+', encoding='utf-8')
+ try:
+ self.lockfile = open(self.lockpath, 'w+', encoding='utf-8')
+ except (FileNotFoundError, IsADirectoryError):
+ # For FileNotFoundError, there is nothing to lock.
+ # For IsADirectoryError, something is seriously wrong.
+ raise
+ except OSError:
+ if self.action == DirectoryLockAction.IGNORE or self.optional:
+ return
+
try:
mode = msvcrt.LK_LOCK
if self.action != DirectoryLockAction.WAIT:
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index 1cc2cee61..f8ed5e0fe 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -588,7 +588,7 @@ class Resolver:
try:
with DirectoryLock(self.subdir_root, '.wraplock',
DirectoryLockAction.WAIT,
- 'Failed to lock subprojects directory'):
+ 'Failed to lock subprojects directory', optional=True):
return self._resolve(packagename, force_method)
except FileNotFoundError:
raise WrapNotFoundException('Attempted to resolve subproject without subprojects directory present.')