diff options
author | Richard Purdie <richard@openedhand.com> | 2006-05-09 15:44:08 +0000 |
---|---|---|
committer | Richard Purdie <richard@openedhand.com> | 2006-05-09 15:44:08 +0000 |
commit | 27dba1e6247ae48349aee1bce141a9eefaafaad1 (patch) | |
tree | 822235005ccbd2707f7874ad680dedc4df36760c /bitbake/lib/bb/methodpool.py | |
parent | ed234aca98d0867c7b32801fc63820b19cf67df9 (diff) | |
download | poky-27dba1e6247ae48349aee1bce141a9eefaafaad1.tar.gz |
Update to bitbake 1.4.2 (latest stable branch release). This includes the caching speedups
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@371 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'bitbake/lib/bb/methodpool.py')
-rw-r--r-- | bitbake/lib/bb/methodpool.py | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/bitbake/lib/bb/methodpool.py b/bitbake/lib/bb/methodpool.py new file mode 100644 index 0000000000..d7434ed33e --- /dev/null +++ b/bitbake/lib/bb/methodpool.py | |||
@@ -0,0 +1,101 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | # | ||
4 | # | ||
5 | # Copyright (C) 2006 Holger Hans Peter Freyther | ||
6 | # All rights reserved. | ||
7 | # | ||
8 | # Redistribution and use in source and binary forms, with or without | ||
9 | # modification, are permitted provided that the following conditions are met: | ||
10 | # | ||
11 | # Redistributions of source code must retain the above copyright notice, | ||
12 | # this list of conditions and the following disclaimer. | ||
13 | # | ||
14 | # Redistributions in binary form must reproduce the above copyright | ||
15 | # notice, this list of conditions and the following disclaimer in the | ||
16 | # documentation and/or other materials provided with the distribution. | ||
17 | # | ||
18 | # Neither the name Holger Hans Peter Freyther nor the names of its | ||
19 | # contributors may be used to endorse or promote products derived | ||
20 | # from this software without specific prior written permission. | ||
21 | # | ||
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
28 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
29 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
30 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
31 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
32 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
33 | # POSSIBILITY OF SUCH DAMAGE. | ||
34 | |||
35 | |||
36 | """ | ||
37 | What is a method pool? | ||
38 | |||
39 | BitBake has a global method scope where .bb, .inc and .bbclass | ||
40 | files can install methods. These methods are parsed from strings. | ||
41 | To avoid recompiling and executing these string we introduce | ||
42 | a method pool to do this task. | ||
43 | |||
44 | This pool will be used to compile and execute the functions. It | ||
45 | will be smart enough to | ||
46 | """ | ||
47 | |||
48 | from bb.utils import better_compile, better_exec | ||
49 | from bb import error | ||
50 | |||
51 | # A dict of modules we have handled | ||
52 | # it is the number of .bbclasses + x in size | ||
53 | _parsed_methods = { } | ||
54 | _parsed_fns = { } | ||
55 | |||
56 | def insert_method(modulename, code, fn): | ||
57 | """ | ||
58 | Add code of a module should be added. The methods | ||
59 | will be simply added, no checking will be done | ||
60 | """ | ||
61 | comp = better_compile(code, "<bb>", fn ) | ||
62 | better_exec(comp, __builtins__, code, fn) | ||
63 | |||
64 | # hack hack hack XXX | ||
65 | return | ||
66 | |||
67 | # now some instrumentation | ||
68 | code = comp.co_names | ||
69 | for name in code: | ||
70 | if name in ['None', 'False']: | ||
71 | continue | ||
72 | elif name in _parsed_fns and not _parsed_fns[name] == modulename: | ||
73 | error( "Error Method already seen: %s in' %s' now in '%s'" % (name, _parsed_fns[name], modulename)) | ||
74 | else: | ||
75 | _parsed_fns[name] = modulename | ||
76 | |||
77 | def check_insert_method(modulename, code, fn): | ||
78 | """ | ||
79 | Add the code if it wasnt added before. The module | ||
80 | name will be used for that | ||
81 | |||
82 | Variables: | ||
83 | @modulename a short name e.g. base.bbclass | ||
84 | @code The actual python code | ||
85 | @fn The filename from the outer file | ||
86 | """ | ||
87 | if not modulename in _parsed_methods: | ||
88 | return insert_method(modulename, code, fn) | ||
89 | |||
90 | def parsed_module(modulename): | ||
91 | """ | ||
92 | Inform me file xyz was parsed | ||
93 | """ | ||
94 | return modulename in _parsed_methods | ||
95 | |||
96 | |||
97 | def get_parsed_dict(): | ||
98 | """ | ||
99 | shortcut | ||
100 | """ | ||
101 | return _parsed_methods | ||