diff options
author | Ross Burton <ross.burton@intel.com> | 2016-07-14 19:56:22 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-07-19 08:56:50 +0100 |
commit | 2afcbfef2cd1ca568e5225884a8021df38ee3db0 (patch) | |
tree | a56018978d6d52733d23d2b88e8d4a8c761b2cb7 /bitbake/lib/bb/build.py | |
parent | faa726824dfb5bc0141919bb16c0d0069a3da69e (diff) | |
download | poky-2afcbfef2cd1ca568e5225884a8021df38ee3db0.tar.gz |
bitbake: build: don't use $B as the default cwd for functions
When bitbake executes a shell or Python function it can cd/chdir() into a
directory before executing the task. If no directory is specified then the
default of $B is used. However $B is an OpenEmbedded variable and BitBake
shouldn't be aware of it.
To solve this change the semantics slightly so that if no directory is
specified, the current working directory isn't changed. There's also a sanity
check that emits a warning if a Python task does os.chdir() without restoring
the old path, and the previous working directory is restored.
This does change semantics: whereas before a function in OE would have $B as the
working directory unless specified, now the working directory is the top of the
build tree. Any breakage this causes can be solved by either adding
do_some_task[dirs] = "${B}" or by using absolute paths in the task.
[ YOCTO #4634 ]
(Bitbake rev: 67a7b8b021badc17d8fdf447c250e79d291e75f7)
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/build.py')
-rw-r--r-- | bitbake/lib/bb/build.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py index 04979acbd3..a4deb00b88 100644 --- a/bitbake/lib/bb/build.py +++ b/bitbake/lib/bb/build.py | |||
@@ -188,6 +188,11 @@ class LogTee(object): | |||
188 | def exec_func(func, d, dirs = None, pythonexception=False): | 188 | def exec_func(func, d, dirs = None, pythonexception=False): |
189 | """Execute a BB 'function'""" | 189 | """Execute a BB 'function'""" |
190 | 190 | ||
191 | try: | ||
192 | oldcwd = os.getcwd() | ||
193 | except: | ||
194 | oldcwd = None | ||
195 | |||
191 | body = d.getVar(func, False) | 196 | body = d.getVar(func, False) |
192 | if not body: | 197 | if not body: |
193 | if body is None: | 198 | if body is None: |
@@ -211,9 +216,7 @@ def exec_func(func, d, dirs = None, pythonexception=False): | |||
211 | bb.utils.mkdirhier(adir) | 216 | bb.utils.mkdirhier(adir) |
212 | adir = dirs[-1] | 217 | adir = dirs[-1] |
213 | else: | 218 | else: |
214 | adir = d.getVar('B', True) | 219 | adir = None |
215 | bb.utils.mkdirhier(adir) | ||
216 | |||
217 | ispython = flags.get('python') | 220 | ispython = flags.get('python') |
218 | 221 | ||
219 | lockflag = flags.get('lockfiles') | 222 | lockflag = flags.get('lockfiles') |
@@ -257,6 +260,13 @@ def exec_func(func, d, dirs = None, pythonexception=False): | |||
257 | else: | 260 | else: |
258 | exec_func_shell(func, d, runfile, cwd=adir) | 261 | exec_func_shell(func, d, runfile, cwd=adir) |
259 | 262 | ||
263 | if oldcwd and os.getcwd() != oldcwd: | ||
264 | try: | ||
265 | bb.warn("Task %s changed cwd to %s" % (func, os.getcwd())) | ||
266 | os.chdir(oldcwd) | ||
267 | except: | ||
268 | pass | ||
269 | |||
260 | _functionfmt = """ | 270 | _functionfmt = """ |
261 | {function}(d) | 271 | {function}(d) |
262 | """ | 272 | """ |
@@ -272,7 +282,8 @@ def exec_func_python(func, d, runfile, cwd=None, pythonexception=False): | |||
272 | if cwd: | 282 | if cwd: |
273 | try: | 283 | try: |
274 | olddir = os.getcwd() | 284 | olddir = os.getcwd() |
275 | except OSError: | 285 | except OSError as e: |
286 | bb.warn("%s: Cannot get cwd: %s" % (func, e)) | ||
276 | olddir = None | 287 | olddir = None |
277 | os.chdir(cwd) | 288 | os.chdir(cwd) |
278 | 289 | ||
@@ -298,8 +309,8 @@ def exec_func_python(func, d, runfile, cwd=None, pythonexception=False): | |||
298 | if cwd and olddir: | 309 | if cwd and olddir: |
299 | try: | 310 | try: |
300 | os.chdir(olddir) | 311 | os.chdir(olddir) |
301 | except OSError: | 312 | except OSError as e: |
302 | pass | 313 | bb.warn("%s: Cannot restore cwd %s: %s" % (func, olddir, e)) |
303 | 314 | ||
304 | def shell_trap_code(): | 315 | def shell_trap_code(): |
305 | return '''#!/bin/sh\n | 316 | return '''#!/bin/sh\n |