summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-09-10 12:33:27 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-09-11 17:58:33 +0100
commit560fa9ad8dd46f23cff7a2e88a3492c363314b29 (patch)
tree546aaaea213e9b82587747ccd9535226de27f6da /bitbake
parentd734ab491a30078d43dee5440c03acce2d251425 (diff)
downloadpoky-560fa9ad8dd46f23cff7a2e88a3492c363314b29.tar.gz
bitbake: methodpool: Retire it, remove global method scope
Having a global method scope confuses users and with the introduction of parallel parsing, its not even possible to correctly detect conflicting functions. Rather than try and fix that, its simpler to retire the global method scope and restrict functions to those locations they're defined within. This is more what users actually expect too. If we remove the global function scope, the need for methodpool is reduced to the point we may as well retire it. There is some small loss of caching of parsed functions but timing measurements so the impact to be neglibile in the overall parsing time. (Bitbake rev: bbb4fa427739912ff3b87379bf629066f6662458) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Tested-by: Denys Dmytriyenko <denys@ti.com>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/cooker.py2
-rw-r--r--bitbake/lib/bb/methodpool.py43
-rw-r--r--bitbake/lib/bb/parse/ast.py8
-rw-r--r--bitbake/lib/bb/parse/parse_py/BBHandler.py4
4 files changed, 5 insertions, 52 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 2c54209f89..4d6cf81a3c 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -1606,6 +1606,7 @@ class Parser(multiprocessing.Process):
1606 self.quit = quit 1606 self.quit = quit
1607 self.init = init 1607 self.init = init
1608 multiprocessing.Process.__init__(self) 1608 multiprocessing.Process.__init__(self)
1609 self.context = bb.utils._context.copy()
1609 1610
1610 def run(self): 1611 def run(self):
1611 if self.init: 1612 if self.init:
@@ -1640,6 +1641,7 @@ class Parser(multiprocessing.Process):
1640 1641
1641 def parse(self, filename, appends, caches_array): 1642 def parse(self, filename, appends, caches_array):
1642 try: 1643 try:
1644 bb.utils._context = self.context.copy()
1643 return True, bb.cache.Cache.parse(filename, appends, self.cfg, caches_array) 1645 return True, bb.cache.Cache.parse(filename, appends, self.cfg, caches_array)
1644 except Exception as exc: 1646 except Exception as exc:
1645 tb = sys.exc_info()[2] 1647 tb = sys.exc_info()[2]
diff --git a/bitbake/lib/bb/methodpool.py b/bitbake/lib/bb/methodpool.py
index 2fb5d96a3f..3cf2040973 100644
--- a/bitbake/lib/bb/methodpool.py
+++ b/bitbake/lib/bb/methodpool.py
@@ -17,24 +17,7 @@
17# with this program; if not, write to the Free Software Foundation, Inc., 17# with this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 19
20
21"""
22 What is a method pool?
23
24 BitBake has a global method scope where .bb, .inc and .bbclass
25 files can install methods. These methods are parsed from strings.
26 To avoid recompiling and executing these string we introduce
27 a method pool to do this task.
28
29 This pool will be used to compile and execute the functions. It
30 will be smart enough to
31"""
32
33from bb.utils import better_compile, better_exec 20from bb.utils import better_compile, better_exec
34from bb import error
35
36# A dict of function names we have seen
37_parsed_fns = { }
38 21
39def insert_method(modulename, code, fn): 22def insert_method(modulename, code, fn):
40 """ 23 """
@@ -43,29 +26,3 @@ def insert_method(modulename, code, fn):
43 """ 26 """
44 comp = better_compile(code, modulename, fn ) 27 comp = better_compile(code, modulename, fn )
45 better_exec(comp, None, code, fn) 28 better_exec(comp, None, code, fn)
46
47 # now some instrumentation
48 code = comp.co_names
49 for name in code:
50 if name in ['None', 'False']:
51 continue
52 elif name in _parsed_fns and not _parsed_fns[name] == modulename:
53 error("The function %s defined in %s was already declared in %s. BitBake has a global python function namespace so shared functions should be declared in a common include file rather than being duplicated, or if the functions are different, please use different function names." % (name, modulename, _parsed_fns[name]))
54 else:
55 _parsed_fns[name] = modulename
56
57# A dict of modules the parser has finished with
58_parsed_methods = {}
59
60def parsed_module(modulename):
61 """
62 Has module been parsed?
63 """
64 return modulename in _parsed_methods
65
66def set_parsed_module(modulename):
67 """
68 Set module as parsed
69 """
70 _parsed_methods[modulename] = True
71
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py
index b2657f8044..713bef1cc2 100644
--- a/bitbake/lib/bb/parse/ast.py
+++ b/bitbake/lib/bb/parse/ast.py
@@ -148,9 +148,8 @@ class MethodNode(AstNode):
148 text = '\n'.join(self.body) 148 text = '\n'.join(self.body)
149 if self.func_name == "__anonymous": 149 if self.func_name == "__anonymous":
150 funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(string.maketrans('/.+-', '____')))) 150 funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(string.maketrans('/.+-', '____'))))
151 if not funcname in bb.methodpool._parsed_fns: 151 text = "def %s(d):\n" % (funcname) + text
152 text = "def %s(d):\n" % (funcname) + text 152 bb.methodpool.insert_method(funcname, text, self.filename)
153 bb.methodpool.insert_method(funcname, text, self.filename)
154 anonfuncs = data.getVar('__BBANONFUNCS') or [] 153 anonfuncs = data.getVar('__BBANONFUNCS') or []
155 anonfuncs.append(funcname) 154 anonfuncs.append(funcname)
156 data.setVar('__BBANONFUNCS', anonfuncs) 155 data.setVar('__BBANONFUNCS', anonfuncs)
@@ -171,8 +170,7 @@ class PythonMethodNode(AstNode):
171 # 'this' file. This means we will not parse methods from 170 # 'this' file. This means we will not parse methods from
172 # bb classes twice 171 # bb classes twice
173 text = '\n'.join(self.body) 172 text = '\n'.join(self.body)
174 if not bb.methodpool.parsed_module(self.modulename): 173 bb.methodpool.insert_method(self.modulename, text, self.filename)
175 bb.methodpool.insert_method(self.modulename, text, self.filename)
176 data.setVarFlag(self.function, "func", 1) 174 data.setVarFlag(self.function, "func", 1)
177 data.setVarFlag(self.function, "python", 1) 175 data.setVarFlag(self.function, "python", 1)
178 data.setVar(self.function, text) 176 data.setVar(self.function, text)
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py
index 81fb8d3adf..2aba9a09f3 100644
--- a/bitbake/lib/bb/parse/parse_py/BBHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py
@@ -166,10 +166,6 @@ def handle(fn, d, include):
166 if oldfile: 166 if oldfile:
167 d.setVar("FILE", oldfile) 167 d.setVar("FILE", oldfile)
168 168
169 # we have parsed the bb class now
170 if ext == ".bbclass" or ext == ".inc":
171 bb.methodpool.set_parsed_module(base_name)
172
173 return d 169 return d
174 170
175def feeder(lineno, s, fn, root, statements): 171def feeder(lineno, s, fn, root, statements):