summaryrefslogtreecommitdiff
path: root/bitbake/lib/bb/build.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/build.py')
-rw-r--r--bitbake/lib/bb/build.py64
1 files changed, 30 insertions, 34 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py
index 43dbfc136..1f4107fb6 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -27,8 +27,9 @@
from bb import data, event, mkdirhier, utils
import bb, os, sys
+import bb.utils
-# When we execute a python function we'd like certain things
+# When we execute a python function we'd like certain things
# in all namespaces, hence we add them to __builtins__
# If we do not do this and use the exec globals, they will
# not be available to subfunctions.
@@ -98,18 +99,19 @@ def exec_func(func, d, dirs = None):
ispython = flags['python']
- cleandirs = (data.expand(flags['cleandirs'], d) or "").split()
- for cdir in cleandirs:
- os.system("rm -rf %s" % cdir)
+ cleandirs = flags['cleandirs']
+ if cleandirs:
+ for cdir in data.expand(cleandirs, d).split():
+ os.system("rm -rf %s" % cdir)
- if dirs:
- dirs = data.expand(dirs, d)
- else:
- dirs = (data.expand(flags['dirs'], d) or "").split()
- for adir in dirs:
- mkdirhier(adir)
+ if dirs is None:
+ dirs = flags['dirs']
+ if dirs:
+ dirs = data.expand(dirs, d).split()
- if len(dirs) > 0:
+ if dirs:
+ for adir in dirs:
+ bb.utils.mkdirhier(adir)
adir = dirs[-1]
else:
adir = data.getVar('B', d, 1)
@@ -123,8 +125,8 @@ def exec_func(func, d, dirs = None):
# Setup logfiles
t = data.getVar('T', d, 1)
if not t:
- bb.msg.fatal(bb.msg.domain.Build, "T not set")
- mkdirhier(t)
+ raise SystemExit("T variable not set, unable to build")
+ bb.utils.mkdirhier(t)
logfile = "%s/log.%s.%s" % (t, func, str(os.getpid()))
runfile = "%s/run.%s.%s" % (t, func, str(os.getpid()))
@@ -139,7 +141,7 @@ def exec_func(func, d, dirs = None):
so = os.popen("tee \"%s\"" % logfile, "w")
else:
so = file(logfile, 'w')
- except OSError, e:
+ except OSError as e:
bb.msg.error(bb.msg.domain.Build, "opening log file: %s" % e)
pass
@@ -156,9 +158,10 @@ def exec_func(func, d, dirs = None):
os.dup2(se.fileno(), ose[1])
locks = []
- lockfiles = (data.expand(flags['lockfiles'], d) or "").split()
- for lock in lockfiles:
- locks.append(bb.utils.lockfile(lock))
+ lockfiles = flags['lockfiles']
+ if lockfiles:
+ for lock in data.expand(lockfiles, d).split():
+ locks.append(bb.utils.lockfile(lock))
try:
# Run the function
@@ -200,26 +203,22 @@ def exec_func(func, d, dirs = None):
def exec_func_python(func, d, runfile, logfile):
"""Execute a python BB 'function'"""
- import re, os
bbfile = bb.data.getVar('FILE', d, 1)
- tmp = "def " + func + "():\n%s" % data.getVar(func, d)
- tmp += '\n' + func + '()'
+ tmp = "def " + func + "(d):\n%s" % data.getVar(func, d)
+ tmp += '\n' + func + '(d)'
f = open(runfile, "w")
f.write(tmp)
comp = utils.better_compile(tmp, func, bbfile)
- g = {} # globals
- g['d'] = d
try:
- utils.better_exec(comp, g, tmp, bbfile)
+ utils.better_exec(comp, {"d": d}, tmp, bbfile)
except:
- (t,value,tb) = sys.exc_info()
+ (t, value, tb) = sys.exc_info()
if t in [bb.parse.SkipPackage, bb.build.FuncFailed]:
raise
- bb.msg.error(bb.msg.domain.Build, "Function %s failed" % func)
- raise FuncFailed("function %s failed" % func, logfile)
+ raise FuncFailed("Function %s failed" % func, logfile)
def exec_func_shell(func, d, runfile, logfile, flags):
"""Execute a shell BB 'function' Returns true if execution was successful.
@@ -248,7 +247,6 @@ def exec_func_shell(func, d, runfile, logfile, flags):
f.close()
os.chmod(runfile, 0775)
if not func:
- bb.msg.error(bb.msg.domain.Build, "Function not specified")
raise FuncFailed("Function not specified for exec_func_shell")
# execute function
@@ -262,7 +260,6 @@ def exec_func_shell(func, d, runfile, logfile, flags):
if ret == 0:
return
- bb.msg.error(bb.msg.domain.Build, "Function %s failed" % func)
raise FuncFailed("function %s failed" % func, logfile)
@@ -287,7 +284,7 @@ def exec_task(task, d):
event.fire(TaskStarted(task, localdata), localdata)
exec_func(task, localdata)
event.fire(TaskSucceeded(task, localdata), localdata)
- except FuncFailed, message:
+ except FuncFailed as message:
# Try to extract the optional logfile
try:
(msg, logfile) = message
@@ -305,8 +302,8 @@ def exec_task(task, d):
def extract_stamp(d, fn):
"""
- Extracts stamp format which is either a data dictonary (fn unset)
- or a dataCache entry (fn set).
+ Extracts stamp format which is either a data dictonary (fn unset)
+ or a dataCache entry (fn set).
"""
if fn:
return d.stamp[fn]
@@ -323,7 +320,7 @@ def stamp_internal(task, d, file_name):
if not stamp:
return
stamp = "%s.%s" % (stamp, task)
- mkdirhier(os.path.dirname(stamp))
+ bb.utils.mkdirhier(os.path.dirname(stamp))
# Remove the file and recreate to force timestamp
# change on broken NFS filesystems
if os.access(stamp, os.F_OK):
@@ -363,7 +360,7 @@ def add_tasks(tasklist, d):
if not task in task_deps['tasks']:
task_deps['tasks'].append(task)
- flags = data.getVarFlags(task, d)
+ flags = data.getVarFlags(task, d)
def getTask(name):
if not name in task_deps:
task_deps[name] = {}
@@ -389,4 +386,3 @@ def remove_task(task, kill, d):
If kill is 1, also remove tasks that depend on this task."""
data.delVarFlag(task, 'task', d)
-