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): def exec_func(func, d, dirs = None, pythonexception=False): """Execute a BB 'function'""" + try: + oldcwd = os.getcwd() + except: + oldcwd = None + body = d.getVar(func, False) if not body: if body is None: @@ -211,9 +216,7 @@ def exec_func(func, d, dirs = None, pythonexception=False): bb.utils.mkdirhier(adir) adir = dirs[-1] else: - adir = d.getVar('B', True) - bb.utils.mkdirhier(adir) - + adir = None ispython = flags.get('python') lockflag = flags.get('lockfiles') @@ -257,6 +260,13 @@ def exec_func(func, d, dirs = None, pythonexception=False): else: exec_func_shell(func, d, runfile, cwd=adir) + if oldcwd and os.getcwd() != oldcwd: + try: + bb.warn("Task %s changed cwd to %s" % (func, os.getcwd())) + os.chdir(oldcwd) + except: + pass + _functionfmt = """ {function}(d) """ @@ -272,7 +282,8 @@ def exec_func_python(func, d, runfile, cwd=None, pythonexception=False): if cwd: try: olddir = os.getcwd() - except OSError: + except OSError as e: + bb.warn("%s: Cannot get cwd: %s" % (func, e)) olddir = None os.chdir(cwd) @@ -298,8 +309,8 @@ def exec_func_python(func, d, runfile, cwd=None, pythonexception=False): if cwd and olddir: try: os.chdir(olddir) - except OSError: - pass + except OSError as e: + bb.warn("%s: Cannot restore cwd %s: %s" % (func, olddir, e)) def shell_trap_code(): return '''#!/bin/sh\n