diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-12-09 20:29:31 -0500 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2011-01-04 14:46:48 +0000 |
commit | e2363f3cdddb597c0321b6c396306be966ac58f9 (patch) | |
tree | cef6f4fd59a91c558a528b841c3159f264f68234 /bitbake/lib/bb/build.py | |
parent | b4eff9fcefe2fefab1caaf22e497317e9338063e (diff) | |
download | poky-e2363f3cdddb597c0321b6c396306be966ac58f9.tar.gz |
build: use a contextmanager for locks
Also don't bother passing logfile to exec_func_python, at least until we start
adding the logfile as a file handler to the bitbake logger.
(Bitbake rev: f99ee4680c9f67b7ed13fc06044ba2382f9a782c)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/build.py')
-rw-r--r-- | bitbake/lib/bb/build.py | 22 |
1 files changed, 9 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} |