diff options
Diffstat (limited to 'bitbake/lib/bb/codeparser.py')
| -rw-r--r-- | bitbake/lib/bb/codeparser.py | 40 | 
1 files changed, 23 insertions, 17 deletions
diff --git a/bitbake/lib/bb/codeparser.py b/bitbake/lib/bb/codeparser.py index 8b7db934d3..1d3557cd6d 100644 --- a/bitbake/lib/bb/codeparser.py +++ b/bitbake/lib/bb/codeparser.py  | |||
| @@ -1,16 +1,20 @@ | |||
| 1 | from bb.pysh import pyshyacc, pyshlex | ||
| 2 | from itertools import chain | ||
| 3 | from bb import msg, utils | ||
| 4 | import ast | 1 | import ast | 
| 5 | import codegen | 2 | import codegen | 
| 3 | import logging | ||
| 4 | import os.path | ||
| 5 | import bb.utils, bb.data | ||
| 6 | from itertools import chain | ||
| 7 | from bb.pysh import pyshyacc, pyshlex | ||
| 6 | 8 | ||
| 9 | logger = logging.getLogger('BitBake.CodeParser') | ||
| 7 | PARSERCACHE_VERSION = 2 | 10 | PARSERCACHE_VERSION = 2 | 
| 8 | 11 | ||
| 9 | try: | 12 | try: | 
| 10 | import cPickle as pickle | 13 | import cPickle as pickle | 
| 11 | except ImportError: | 14 | except ImportError: | 
| 12 | import pickle | 15 | import pickle | 
| 13 | bb.msg.note(1, bb.msg.domain.Cache, "Importing cPickle failed. Falling back to a very slow implementation.") | 16 | logger.info('Importing cPickle failed. Falling back to a very slow implementation.') | 
| 17 | |||
| 14 | 18 | ||
| 15 | def check_indent(codestr): | 19 | def check_indent(codestr): | 
| 16 | """If the code is indented, add a top level piece of code to 'remove' the indentation""" | 20 | """If the code is indented, add a top level piece of code to 'remove' the indentation""" | 
| @@ -23,7 +27,7 @@ def check_indent(codestr): | |||
| 23 | return codestr | 27 | return codestr | 
| 24 | 28 | ||
| 25 | if codestr[i-1] is " " or codestr[i-1] is " ": | 29 | if codestr[i-1] is " " or codestr[i-1] is " ": | 
| 26 | return "if 1:\n" + codestr | 30 | return "if 1:\n" + codestr | 
| 27 | 31 | ||
| 28 | return codestr | 32 | return codestr | 
| 29 | 33 | ||
| @@ -31,15 +35,18 @@ pythonparsecache = {} | |||
| 31 | shellparsecache = {} | 35 | shellparsecache = {} | 
| 32 | 36 | ||
| 33 | def parser_cachefile(d): | 37 | def parser_cachefile(d): | 
| 34 | cachedir = bb.data.getVar("PERSISTENT_DIR", d, True) or bb.data.getVar("CACHE", d, True) | 38 | cachedir = (bb.data.getVar("PERSISTENT_DIR", d, True) or | 
| 39 | bb.data.getVar("CACHE", d, True)) | ||
| 35 | if cachedir in [None, '']: | 40 | if cachedir in [None, '']: | 
| 36 | return None | 41 | return None | 
| 37 | bb.utils.mkdirhier(cachedir) | 42 | bb.utils.mkdirhier(cachedir) | 
| 38 | cachefile = os.path.join(cachedir, "bb_codeparser.dat") | 43 | cachefile = os.path.join(cachedir, "bb_codeparser.dat") | 
| 39 | bb.msg.debug(1, bb.msg.domain.Cache, "Using cache in '%s' for codeparser cache" % cachefile) | 44 | logger.debug(1, "Using cache in '%s' for codeparser cache", cachefile) | 
| 40 | return cachefile | 45 | return cachefile | 
| 41 | 46 | ||
| 42 | def parser_cache_init(d): | 47 | def parser_cache_init(d): | 
| 48 | global pythonparsecache | ||
| 49 | global shellparsecache | ||
| 43 | 50 | ||
| 44 | cachefile = parser_cachefile(d) | 51 | cachefile = parser_cachefile(d) | 
| 45 | if not cachefile: | 52 | if not cachefile: | 
| @@ -54,17 +61,16 @@ def parser_cache_init(d): | |||
| 54 | if version != PARSERCACHE_VERSION: | 61 | if version != PARSERCACHE_VERSION: | 
| 55 | return | 62 | return | 
| 56 | 63 | ||
| 57 | bb.codeparser.pythonparsecache = data[0] | 64 | pythonparsecache = data[0] | 
| 58 | bb.codeparser.shellparsecache = data[1] | 65 | shellparsecache = data[1] | 
| 59 | 66 | ||
| 60 | def parser_cache_save(d): | 67 | def parser_cache_save(d): | 
| 61 | |||
| 62 | cachefile = parser_cachefile(d) | 68 | cachefile = parser_cachefile(d) | 
| 63 | if not cachefile: | 69 | if not cachefile: | 
| 64 | return | 70 | return | 
| 65 | 71 | ||
| 66 | p = pickle.Pickler(file(cachefile, "wb"), -1) | 72 | p = pickle.Pickler(file(cachefile, "wb"), -1) | 
| 67 | p.dump([[bb.codeparser.pythonparsecache, bb.codeparser.shellparsecache], PARSERCACHE_VERSION]) | 73 | p.dump([[pythonparsecache, shellparsecache], PARSERCACHE_VERSION]) | 
| 68 | 74 | ||
| 69 | class PythonParser(): | 75 | class PythonParser(): | 
| 70 | class ValueVisitor(): | 76 | class ValueVisitor(): | 
| @@ -129,10 +135,10 @@ class PythonParser(): | |||
| 129 | funcstr = codegen.to_source(func) | 135 | funcstr = codegen.to_source(func) | 
| 130 | argstr = codegen.to_source(arg) | 136 | argstr = codegen.to_source(arg) | 
| 131 | except TypeError: | 137 | except TypeError: | 
| 132 | msg.debug(2, None, "Failed to convert function and argument to source form") | 138 | logger.debug(2, 'Failed to convert function and argument to source form') | 
| 133 | else: | 139 | else: | 
| 134 | msg.debug(1, None, "Warning: in call to '%s', argument '%s' is not a literal" % | 140 | logger.debug(1, "Warning: in call to '%s', argumen t'%s' is" | 
| 135 | (funcstr, argstr)) | 141 | "not a literal", funcstr, argstr) | 
| 136 | 142 | ||
| 137 | def visit_Call(self, node): | 143 | def visit_Call(self, node): | 
| 138 | if self.compare_name(self.getvars, node.func): | 144 | if self.compare_name(self.getvars, node.func): | 
| @@ -184,7 +190,7 @@ class PythonParser(): | |||
| 184 | self.execs = pythonparsecache[h]["execs"] | 190 | self.execs = pythonparsecache[h]["execs"] | 
| 185 | return | 191 | return | 
| 186 | 192 | ||
| 187 | code = compile(check_indent(str(node)), "<string>", "exec", | 193 | code = compile(check_indent(str(node)), "<string>", "exec", | 
| 188 | ast.PyCF_ONLY_AST) | 194 | ast.PyCF_ONLY_AST) | 
| 189 | 195 | ||
| 190 | visitor = self.ValueVisitor(code) | 196 | visitor = self.ValueVisitor(code) | 
| @@ -319,11 +325,11 @@ class ShellParser(): | |||
| 319 | 325 | ||
| 320 | cmd = word[1] | 326 | cmd = word[1] | 
| 321 | if cmd.startswith("$"): | 327 | if cmd.startswith("$"): | 
| 322 | msg.debug(1, None, "Warning: execution of non-literal command '%s'" % cmd) | 328 | logger.debug(1, "Warning: execution of non-literal" | 
| 329 | "command '%s'", cmd) | ||
| 323 | elif cmd == "eval": | 330 | elif cmd == "eval": | 
| 324 | command = " ".join(word for _, word in words[1:]) | 331 | command = " ".join(word for _, word in words[1:]) | 
| 325 | self.parse_shell(command) | 332 | self.parse_shell(command) | 
| 326 | else: | 333 | else: | 
| 327 | self.allexecs.add(cmd) | 334 | self.allexecs.add(cmd) | 
| 328 | break | 335 | break | 
| 329 | |||
