diff options
Diffstat (limited to 'bitbake/lib/bb/build.py')
| -rw-r--r-- | bitbake/lib/bb/build.py | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py index 43dbfc1363..1f4107fb65 100644 --- a/bitbake/lib/bb/build.py +++ b/bitbake/lib/bb/build.py | |||
| @@ -27,8 +27,9 @@ | |||
| 27 | 27 | ||
| 28 | from bb import data, event, mkdirhier, utils | 28 | from bb import data, event, mkdirhier, utils |
| 29 | import bb, os, sys | 29 | import bb, os, sys |
| 30 | import bb.utils | ||
| 30 | 31 | ||
| 31 | # When we execute a python function we'd like certain things | 32 | # When we execute a python function we'd like certain things |
| 32 | # in all namespaces, hence we add them to __builtins__ | 33 | # in all namespaces, hence we add them to __builtins__ |
| 33 | # If we do not do this and use the exec globals, they will | 34 | # If we do not do this and use the exec globals, they will |
| 34 | # not be available to subfunctions. | 35 | # not be available to subfunctions. |
| @@ -98,18 +99,19 @@ def exec_func(func, d, dirs = None): | |||
| 98 | 99 | ||
| 99 | ispython = flags['python'] | 100 | ispython = flags['python'] |
| 100 | 101 | ||
| 101 | cleandirs = (data.expand(flags['cleandirs'], d) or "").split() | 102 | cleandirs = flags['cleandirs'] |
| 102 | for cdir in cleandirs: | 103 | if cleandirs: |
| 103 | os.system("rm -rf %s" % cdir) | 104 | for cdir in data.expand(cleandirs, d).split(): |
| 105 | os.system("rm -rf %s" % cdir) | ||
| 104 | 106 | ||
| 105 | if dirs: | 107 | if dirs is None: |
| 106 | dirs = data.expand(dirs, d) | 108 | dirs = flags['dirs'] |
| 107 | else: | 109 | if dirs: |
| 108 | dirs = (data.expand(flags['dirs'], d) or "").split() | 110 | dirs = data.expand(dirs, d).split() |
| 109 | for adir in dirs: | ||
| 110 | mkdirhier(adir) | ||
| 111 | 111 | ||
| 112 | if len(dirs) > 0: | 112 | if dirs: |
| 113 | for adir in dirs: | ||
| 114 | bb.utils.mkdirhier(adir) | ||
| 113 | adir = dirs[-1] | 115 | adir = dirs[-1] |
| 114 | else: | 116 | else: |
| 115 | adir = data.getVar('B', d, 1) | 117 | adir = data.getVar('B', d, 1) |
| @@ -123,8 +125,8 @@ def exec_func(func, d, dirs = None): | |||
| 123 | # Setup logfiles | 125 | # Setup logfiles |
| 124 | t = data.getVar('T', d, 1) | 126 | t = data.getVar('T', d, 1) |
| 125 | if not t: | 127 | if not t: |
| 126 | bb.msg.fatal(bb.msg.domain.Build, "T not set") | 128 | raise SystemExit("T variable not set, unable to build") |
| 127 | mkdirhier(t) | 129 | bb.utils.mkdirhier(t) |
| 128 | logfile = "%s/log.%s.%s" % (t, func, str(os.getpid())) | 130 | logfile = "%s/log.%s.%s" % (t, func, str(os.getpid())) |
| 129 | runfile = "%s/run.%s.%s" % (t, func, str(os.getpid())) | 131 | runfile = "%s/run.%s.%s" % (t, func, str(os.getpid())) |
| 130 | 132 | ||
| @@ -139,7 +141,7 @@ def exec_func(func, d, dirs = None): | |||
| 139 | so = os.popen("tee \"%s\"" % logfile, "w") | 141 | so = os.popen("tee \"%s\"" % logfile, "w") |
| 140 | else: | 142 | else: |
| 141 | so = file(logfile, 'w') | 143 | so = file(logfile, 'w') |
| 142 | except OSError, e: | 144 | except OSError as e: |
| 143 | bb.msg.error(bb.msg.domain.Build, "opening log file: %s" % e) | 145 | bb.msg.error(bb.msg.domain.Build, "opening log file: %s" % e) |
| 144 | pass | 146 | pass |
| 145 | 147 | ||
| @@ -156,9 +158,10 @@ def exec_func(func, d, dirs = None): | |||
| 156 | os.dup2(se.fileno(), ose[1]) | 158 | os.dup2(se.fileno(), ose[1]) |
| 157 | 159 | ||
| 158 | locks = [] | 160 | locks = [] |
| 159 | lockfiles = (data.expand(flags['lockfiles'], d) or "").split() | 161 | lockfiles = flags['lockfiles'] |
| 160 | for lock in lockfiles: | 162 | if lockfiles: |
| 161 | locks.append(bb.utils.lockfile(lock)) | 163 | for lock in data.expand(lockfiles, d).split(): |
| 164 | locks.append(bb.utils.lockfile(lock)) | ||
| 162 | 165 | ||
| 163 | try: | 166 | try: |
| 164 | # Run the function | 167 | # Run the function |
| @@ -200,26 +203,22 @@ def exec_func(func, d, dirs = None): | |||
| 200 | 203 | ||
| 201 | def exec_func_python(func, d, runfile, logfile): | 204 | def exec_func_python(func, d, runfile, logfile): |
| 202 | """Execute a python BB 'function'""" | 205 | """Execute a python BB 'function'""" |
| 203 | import re, os | ||
| 204 | 206 | ||
| 205 | bbfile = bb.data.getVar('FILE', d, 1) | 207 | bbfile = bb.data.getVar('FILE', d, 1) |
| 206 | tmp = "def " + func + "():\n%s" % data.getVar(func, d) | 208 | tmp = "def " + func + "(d):\n%s" % data.getVar(func, d) |
| 207 | tmp += '\n' + func + '()' | 209 | tmp += '\n' + func + '(d)' |
| 208 | 210 | ||
| 209 | f = open(runfile, "w") | 211 | f = open(runfile, "w") |
| 210 | f.write(tmp) | 212 | f.write(tmp) |
| 211 | comp = utils.better_compile(tmp, func, bbfile) | 213 | comp = utils.better_compile(tmp, func, bbfile) |
| 212 | g = {} # globals | ||
| 213 | g['d'] = d | ||
| 214 | try: | 214 | try: |
| 215 | utils.better_exec(comp, g, tmp, bbfile) | 215 | utils.better_exec(comp, {"d": d}, tmp, bbfile) |
| 216 | except: | 216 | except: |
| 217 | (t,value,tb) = sys.exc_info() | 217 | (t, value, tb) = sys.exc_info() |
| 218 | 218 | ||
| 219 | if t in [bb.parse.SkipPackage, bb.build.FuncFailed]: | 219 | if t in [bb.parse.SkipPackage, bb.build.FuncFailed]: |
| 220 | raise | 220 | raise |
| 221 | bb.msg.error(bb.msg.domain.Build, "Function %s failed" % func) | 221 | raise FuncFailed("Function %s failed" % func, logfile) |
| 222 | raise FuncFailed("function %s failed" % func, logfile) | ||
| 223 | 222 | ||
| 224 | def exec_func_shell(func, d, runfile, logfile, flags): | 223 | def exec_func_shell(func, d, runfile, logfile, flags): |
| 225 | """Execute a shell BB 'function' Returns true if execution was successful. | 224 | """Execute a shell BB 'function' Returns true if execution was successful. |
| @@ -248,7 +247,6 @@ def exec_func_shell(func, d, runfile, logfile, flags): | |||
| 248 | f.close() | 247 | f.close() |
| 249 | os.chmod(runfile, 0775) | 248 | os.chmod(runfile, 0775) |
| 250 | if not func: | 249 | if not func: |
| 251 | bb.msg.error(bb.msg.domain.Build, "Function not specified") | ||
| 252 | raise FuncFailed("Function not specified for exec_func_shell") | 250 | raise FuncFailed("Function not specified for exec_func_shell") |
| 253 | 251 | ||
| 254 | # execute function | 252 | # execute function |
| @@ -262,7 +260,6 @@ def exec_func_shell(func, d, runfile, logfile, flags): | |||
| 262 | if ret == 0: | 260 | if ret == 0: |
| 263 | return | 261 | return |
| 264 | 262 | ||
| 265 | bb.msg.error(bb.msg.domain.Build, "Function %s failed" % func) | ||
| 266 | raise FuncFailed("function %s failed" % func, logfile) | 263 | raise FuncFailed("function %s failed" % func, logfile) |
| 267 | 264 | ||
| 268 | 265 | ||
| @@ -287,7 +284,7 @@ def exec_task(task, d): | |||
| 287 | event.fire(TaskStarted(task, localdata), localdata) | 284 | event.fire(TaskStarted(task, localdata), localdata) |
| 288 | exec_func(task, localdata) | 285 | exec_func(task, localdata) |
| 289 | event.fire(TaskSucceeded(task, localdata), localdata) | 286 | event.fire(TaskSucceeded(task, localdata), localdata) |
| 290 | except FuncFailed, message: | 287 | except FuncFailed as message: |
| 291 | # Try to extract the optional logfile | 288 | # Try to extract the optional logfile |
| 292 | try: | 289 | try: |
| 293 | (msg, logfile) = message | 290 | (msg, logfile) = message |
| @@ -305,8 +302,8 @@ def exec_task(task, d): | |||
| 305 | 302 | ||
| 306 | def extract_stamp(d, fn): | 303 | def extract_stamp(d, fn): |
| 307 | """ | 304 | """ |
| 308 | Extracts stamp format which is either a data dictonary (fn unset) | 305 | Extracts stamp format which is either a data dictonary (fn unset) |
| 309 | or a dataCache entry (fn set). | 306 | or a dataCache entry (fn set). |
| 310 | """ | 307 | """ |
| 311 | if fn: | 308 | if fn: |
| 312 | return d.stamp[fn] | 309 | return d.stamp[fn] |
| @@ -323,7 +320,7 @@ def stamp_internal(task, d, file_name): | |||
| 323 | if not stamp: | 320 | if not stamp: |
| 324 | return | 321 | return |
| 325 | stamp = "%s.%s" % (stamp, task) | 322 | stamp = "%s.%s" % (stamp, task) |
| 326 | mkdirhier(os.path.dirname(stamp)) | 323 | bb.utils.mkdirhier(os.path.dirname(stamp)) |
| 327 | # Remove the file and recreate to force timestamp | 324 | # Remove the file and recreate to force timestamp |
| 328 | # change on broken NFS filesystems | 325 | # change on broken NFS filesystems |
| 329 | if os.access(stamp, os.F_OK): | 326 | if os.access(stamp, os.F_OK): |
| @@ -363,7 +360,7 @@ def add_tasks(tasklist, d): | |||
| 363 | if not task in task_deps['tasks']: | 360 | if not task in task_deps['tasks']: |
| 364 | task_deps['tasks'].append(task) | 361 | task_deps['tasks'].append(task) |
| 365 | 362 | ||
| 366 | flags = data.getVarFlags(task, d) | 363 | flags = data.getVarFlags(task, d) |
| 367 | def getTask(name): | 364 | def getTask(name): |
| 368 | if not name in task_deps: | 365 | if not name in task_deps: |
| 369 | task_deps[name] = {} | 366 | task_deps[name] = {} |
| @@ -389,4 +386,3 @@ def remove_task(task, kill, d): | |||
| 389 | If kill is 1, also remove tasks that depend on this task.""" | 386 | If kill is 1, also remove tasks that depend on this task.""" |
| 390 | 387 | ||
| 391 | data.delVarFlag(task, 'task', d) | 388 | data.delVarFlag(task, 'task', d) |
| 392 | |||
