[oe-commits] [bitbake] 01/02: build: don't use $B as the default cwd for functions
git at git.openembedded.org
git at git.openembedded.org
Thu Jun 16 23:02:33 UTC 2016
rpurdie pushed a commit to branch master-next
in repository bitbake.
commit 37b97c8cdf53783796be14a515e3fc375983a4b9
Author: Ross Burton <ross.burton at intel.com>
AuthorDate: Tue Jun 14 15:09:34 2016 +0100
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 ]
Signed-off-by: Ross Burton <ross.burton at intel.com>
Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
lib/bb/build.py | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/lib/bb/build.py b/lib/bb/build.py
index e016ae3..43d9ebf 100644
--- a/lib/bb/build.py
+++ b/lib/bb/build.py
@@ -168,6 +168,7 @@ class LogTee(object):
def exec_func(func, d, dirs = None, pythonexception=False):
"""Execute a BB 'function'"""
+ oldcwd = os.getcwd()
body = d.getVar(func, False)
if not body:
if body is None:
@@ -191,9 +192,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')
@@ -237,6 +236,10 @@ def exec_func(func, d, dirs = None, pythonexception=False):
else:
exec_func_shell(func, d, runfile, cwd=adir)
+ if os.getcwd() != oldcwd:
+ bb.warn("Task %s changed cwd to %s" % (func, os.getcwd()))
+ os.chdir(oldcwd)
+
_functionfmt = """
{function}(d)
"""
@@ -252,7 +255,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)
@@ -278,8 +282,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
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Openembedded-commits
mailing list