diff options
-rw-r--r-- | bitbake/lib/bb/build.py | 22 | ||||
-rw-r--r-- | bitbake/lib/bb/utils.py | 13 |
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 | ||
28 | from bb import data, event, mkdirhier, utils | ||
29 | import os | 28 | import os |
30 | import sys | 29 | import sys |
31 | import logging | 30 | import logging |
32 | import bb | 31 | import bb |
33 | import bb.utils | 32 | import bb.utils |
34 | import bb.process | 33 | import bb.process |
34 | from contextlib import nested | ||
35 | from bb import data, event, mkdirhier, utils | ||
35 | 36 | ||
36 | logger = logging.getLogger("BitBake.Build") | 37 | logger = 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 = """ |
166 | def {function}(d): | 162 | def {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 | |||
26 | import bb | 26 | import bb |
27 | import bb.msg | 27 | import bb.msg |
28 | from commands import getstatusoutput | 28 | from commands import getstatusoutput |
29 | from contextlib import contextmanager | ||
29 | 30 | ||
30 | logger = logging.getLogger("BitBake.Util") | 31 | logger = logging.getLogger("BitBake.Util") |
31 | 32 | ||
@@ -398,6 +399,18 @@ def simple_exec(code, context): | |||
398 | def better_eval(source, locals): | 399 | def better_eval(source, locals): |
399 | return eval(source, _context, locals) | 400 | return eval(source, _context, locals) |
400 | 401 | ||
402 | @contextmanager | ||
403 | def 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 | |||
401 | def lockfile(name): | 414 | def 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. |