summaryrefslogtreecommitdiffstats
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 79fb1def9b..5d07b06640 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -25,13 +25,14 @@
25# 25#
26#Based on functions from the base bb module, Copyright 2003 Holger Schurig 26#Based on functions from the base bb module, Copyright 2003 Holger Schurig
27 27
28from bb import data, event, mkdirhier, utils
29import os 28import os
30import sys 29import sys
31import logging 30import logging
32import bb 31import bb
33import bb.utils 32import bb.utils
34import bb.process 33import bb.process
34from contextlib import nested
35from bb import data, event, mkdirhier, utils
35 36
36logger = logging.getLogger("BitBake.Build") 37logger = logging.getLogger("BitBake.Build")
37 38
@@ -142,26 +143,21 @@ def exec_func(func, d, dirs = None, logfile = NULL):
142 if flags.get('fakeroot') and not flags.get('task'): 143 if flags.get('fakeroot') and not flags.get('task'):
143 bb.fatal("Function %s specifies fakeroot but isn't a task?!" % func) 144 bb.fatal("Function %s specifies fakeroot but isn't a task?!" % func)
144 145
146 lockflag = flags.get('lockfiles')
147 if lockflag:
148 lockfiles = [data.expand(f, d) for f in lockflag.split()]
149 else:
150 lockfiles = None
151
145 tempdir = data.getVar('T', d, 1) 152 tempdir = data.getVar('T', d, 1)
146 runfile = os.path.join(tempdir, 'run.{0}.{1}'.format(func, os.getpid())) 153 runfile = os.path.join(tempdir, 'run.{0}.{1}'.format(func, os.getpid()))
147 154
148 locks = [] 155 with bb.utils.fileslocked(lockfiles):
149 lockfiles = flags.get('lockfiles')
150 if lockfiles:
151 for lock in data.expand(lockfiles, d).split():
152 locks.append(bb.utils.lockfile(lock))
153
154 try:
155 if ispython: 156 if ispython:
156 exec_func_python(func, d, runfile, logfile, cwd=adir) 157 exec_func_python(func, d, runfile, logfile, cwd=adir)
157 else: 158 else:
158 exec_func_shell(func, d, runfile, logfile, cwd=adir) 159 exec_func_shell(func, d, runfile, logfile, cwd=adir)
159 160
160 finally:
161 # Unlock any lockfiles
162 for lock in locks:
163 bb.utils.unlockfile(lock)
164
165_functionfmt = """ 161_functionfmt = """
166def {function}(d): 162def {function}(d):
167{body} 163{body}
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index d9f543bc60..ba50801ae9 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -26,6 +26,7 @@ import logging
26import bb 26import bb
27import bb.msg 27import bb.msg
28from commands import getstatusoutput 28from commands import getstatusoutput
29from contextlib import contextmanager
29 30
30logger = logging.getLogger("BitBake.Util") 31logger = logging.getLogger("BitBake.Util")
31 32
@@ -398,6 +399,18 @@ def simple_exec(code, context):
398def better_eval(source, locals): 399def better_eval(source, locals):
399 return eval(source, _context, locals) 400 return eval(source, _context, locals)
400 401
402@contextmanager
403def fileslocked(files):
404 locks = []
405 if files:
406 for lockfile in files:
407 locks.append(bb.utils.lockfile(lock))
408
409 yield
410
411 for lock in locks:
412 bb.utils.unlockfile(lock)
413
401def lockfile(name): 414def lockfile(name):
402 """ 415 """
403 Use the file fn as a lock file, return when the lock has been acquired. 416 Use the file fn as a lock file, return when the lock has been acquired.