diff options
Diffstat (limited to 'yocto-poky/bitbake/lib/bb/utils.py')
-rw-r--r-- | yocto-poky/bitbake/lib/bb/utils.py | 104 |
1 files changed, 85 insertions, 19 deletions
diff --git a/yocto-poky/bitbake/lib/bb/utils.py b/yocto-poky/bitbake/lib/bb/utils.py index 31ec2b7c9..3544bbe17 100644 --- a/yocto-poky/bitbake/lib/bb/utils.py +++ b/yocto-poky/bitbake/lib/bb/utils.py @@ -33,6 +33,7 @@ import fnmatch import traceback import errno import signal +import ast from commands import getstatusoutput from contextlib import contextmanager from ctypes import cdll @@ -291,19 +292,26 @@ def _print_trace(body, line): error.append(' %.4d:%s' % (i, body[i-1].rstrip())) return error -def better_compile(text, file, realfile, mode = "exec"): +def better_compile(text, file, realfile, mode = "exec", lineno = 0): """ A better compile method. This method will print the offending lines. """ try: - return compile(text, file, mode) + cache = bb.methodpool.compile_cache(text) + if cache: + return cache + # We can't add to the linenumbers for compile, we can pad to the correct number of blank lines though + text2 = "\n" * int(lineno) + text + code = compile(text2, realfile, mode) + bb.methodpool.compile_cache_add(text, code) + return code except Exception as e: error = [] # split the text into lines again body = text.split('\n') - error.append("Error in compiling python function in %s:\n" % realfile) - if e.lineno: + error.append("Error in compiling python function in %s, line %s:\n" % (realfile, lineno)) + if hasattr(e, "lineno"): error.append("The code lines resulting in this error were:") error.extend(_print_trace(body, e.lineno)) else: @@ -323,8 +331,10 @@ def _print_exception(t, value, tb, realfile, text, context): exception = traceback.format_exception_only(t, value) error.append('Error executing a python function in %s:\n' % realfile) - # Strip 'us' from the stack (better_exec call) - tb = tb.tb_next + # Strip 'us' from the stack (better_exec call) unless that was where the + # error came from + if tb.tb_next is not None: + tb = tb.tb_next textarray = text.split('\n') @@ -353,15 +363,6 @@ def _print_exception(t, value, tb, realfile, text, context): error.extend(_print_trace(text, tbextract[level+1][1])) except: error.append(tbformat[level+1]) - elif "d" in context and tbextract[level+1][2]: - # Try and find the code in the datastore based on the functionname - d = context["d"] - functionname = tbextract[level+1][2] - text = d.getVar(functionname, True) - if text: - error.extend(_print_trace(text.split('\n'), tbextract[level+1][1])) - else: - error.append(tbformat[level+1]) else: error.append(tbformat[level+1]) nexttb = tb.tb_next @@ -371,7 +372,7 @@ def _print_exception(t, value, tb, realfile, text, context): finally: logger.error("\n".join(error)) -def better_exec(code, context, text = None, realfile = "<code>"): +def better_exec(code, context, text = None, realfile = "<code>", pythonexception=False): """ Similiar to better_compile, better_exec will print the lines that are responsible for the @@ -388,6 +389,8 @@ def better_exec(code, context, text = None, realfile = "<code>"): # Error already shown so passthrough, no need for traceback raise except Exception as e: + if pythonexception: + raise (t, value, tb) = sys.exc_info() try: _print_exception(t, value, tb, realfile, text, context) @@ -533,6 +536,21 @@ def sha256_file(filename): s.update(line) return s.hexdigest() +def sha1_file(filename): + """ + Return the hex string representation of the SHA1 checksum of the filename + """ + try: + import hashlib + except ImportError: + return None + + s = hashlib.sha1() + with open(filename, "rb") as f: + for line in f: + s.update(line) + return s.hexdigest() + def preserved_envvars_exported(): """Variables which are taken from the environment and placed in and exported from the metadata""" @@ -621,7 +639,7 @@ def build_environment(d): """ import bb.data for var in bb.data.keys(d): - export = d.getVarFlag(var, "export") + export = d.getVarFlag(var, "export", False) if export: os.environ[var] = d.getVar(var, True) or "" @@ -906,6 +924,24 @@ def to_boolean(string, default=None): raise ValueError("Invalid value for to_boolean: %s" % string) def contains(variable, checkvalues, truevalue, falsevalue, d): + """Check if a variable contains all the values specified. + + Arguments: + + variable -- the variable name. This will be fetched and expanded (using + d.getVar(variable, True)) and then split into a set(). + + checkvalues -- if this is a string it is split on whitespace into a set(), + otherwise coerced directly into a set(). + + truevalue -- the value to return if checkvalues is a subset of variable. + + falsevalue -- the value to return if variable is empty or if checkvalues is + not a subset of variable. + + d -- the data store. + """ + val = d.getVar(variable, True) if not val: return falsevalue @@ -914,7 +950,7 @@ def contains(variable, checkvalues, truevalue, falsevalue, d): checkvalues = set(checkvalues.split()) else: checkvalues = set(checkvalues) - if checkvalues.issubset(val): + if checkvalues.issubset(val): return truevalue return falsevalue @@ -1140,7 +1176,7 @@ def edit_metadata(meta_lines, variables, varfunc, match_overrides=False): if in_var.endswith('()'): if full_value.count('{') - full_value.count('}') >= 0: continue - full_value = full_value[:-1] + full_value = full_value[:-1] if handle_var_end(): updated = True checkspc = True @@ -1385,3 +1421,33 @@ def ioprio_set(who, cls, value): raise ValueError("Unable to set ioprio, syscall returned %s" % rc) else: bb.warn("Unable to set IO Prio for arch %s" % _unamearch) + +def set_process_name(name): + from ctypes import cdll, byref, create_string_buffer + # This is nice to have for debugging, not essential + try: + libc = cdll.LoadLibrary('libc.so.6') + buff = create_string_buffer(len(name)+1) + buff.value = name + libc.prctl(15, byref(buff), 0, 0, 0) + except: + pass + +# export common proxies variables from datastore to environment +def export_proxies(d): + import os + + variables = ['http_proxy', 'HTTP_PROXY', 'https_proxy', 'HTTPS_PROXY', + 'ftp_proxy', 'FTP_PROXY', 'no_proxy', 'NO_PROXY'] + exported = False + + for v in variables: + if v in os.environ.keys(): + exported = True + else: + v_proxy = d.getVar(v, True) + if v_proxy is not None: + os.environ[v] = v_proxy + exported = True + + return exported |