summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/codeparser.py
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@linux.intel.com>2011-01-01 23:55:54 +0000
committerRichard Purdie <rpurdie@linux.intel.com>2011-01-04 14:46:54 +0000
commit0090a798eb868ebc926944eac2e6d4a5aff3e1b3 (patch)
tree9b90e66234e6ad7b9616c8c5944029426746110f /bitbake/lib/bb/codeparser.py
parente8c48e668c7525257926ab7db9b6e44aa2705483 (diff)
downloadpoky-0090a798eb868ebc926944eac2e6d4a5aff3e1b3.tar.gz
bitbake: Sync a load of whitespace and other non-functionality changes with bitbake uptream
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/codeparser.py')
-rw-r--r--bitbake/lib/bb/codeparser.py40
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 @@
1from bb.pysh import pyshyacc, pyshlex
2from itertools import chain
3from bb import msg, utils
4import ast 1import ast
5import codegen 2import codegen
3import logging
4import os.path
5import bb.utils, bb.data
6from itertools import chain
7from bb.pysh import pyshyacc, pyshlex
6 8
9logger = logging.getLogger('BitBake.CodeParser')
7PARSERCACHE_VERSION = 2 10PARSERCACHE_VERSION = 2
8 11
9try: 12try:
10 import cPickle as pickle 13 import cPickle as pickle
11except ImportError: 14except 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
15def check_indent(codestr): 19def 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 = {}
31shellparsecache = {} 35shellparsecache = {}
32 36
33def parser_cachefile(d): 37def 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
42def parser_cache_init(d): 47def 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
60def parser_cache_save(d): 67def 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
69class PythonParser(): 75class 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