summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bitbake/lib/bb/build.py22
-rw-r--r--bitbake/lib/bb/utils.py13
2 files changed, 22 insertions, 13 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py
index 79fb1def9..5d07b0664 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -25,13 +25,14 @@
#
#Based on functions from the base bb module, Copyright 2003 Holger Schurig
-from bb import data, event, mkdirhier, utils
import os
import sys
import logging
import bb
import bb.utils
import bb.process
+from contextlib import nested
+from bb import data, event, mkdirhier, utils
logger = logging.getLogger("BitBake.Build")
@@ -142,26 +143,21 @@ def exec_func(func, d, dirs = None, logfile = NULL):
if flags.get('fakeroot') and not flags.get('task'):
bb.fatal("Function %s specifies fakeroot but isn't a task?!" % func)
+ lockflag = flags.get('lockfiles')
+ if lockflag:
+ lockfiles = [data.expand(f, d) for f in lockflag.split()]
+ else:
+ lockfiles = None
+
tempdir = data.getVar('T', d, 1)
runfile = os.path.join(tempdir, 'run.{0}.{1}'.format(func, os.getpid()))
- locks = []
- lockfiles = flags.get('lockfiles')
- if lockfiles:
- for lock in data.expand(lockfiles, d).split():
- locks.append(bb.utils.lockfile(lock))
-
- try:
+ with bb.utils.fileslocked(lockfiles):
if ispython:
exec_func_python(func, d, runfile, logfile, cwd=adir)
else:
exec_func_shell(func, d, runfile, logfile, cwd=adir)
- finally:
- # Unlock any lockfiles
- for lock in locks:
- bb.utils.unlockfile(lock)
-
_functionfmt = """
def {function}(d):
{body}
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index d9f543bc6..ba50801ae 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -26,6 +26,7 @@ import logging
import bb
import bb.msg
from commands import getstatusoutput
+from contextlib import contextmanager
logger = logging.getLogger("BitBake.Util")
@@ -398,6 +399,18 @@ def simple_exec(code, context):
def better_eval(source, locals):
return eval(source, _context, locals)
+@contextmanager
+def fileslocked(files):
+ locks = []
+ if files:
+ for lockfile in files:
+ locks.append(bb.utils.lockfile(lock))
+
+ yield
+
+ for lock in locks:
+ bb.utils.unlockfile(lock)
+
def lockfile(name):
"""
Use the file fn as a lock file, return when the lock has been acquired.