diff options
Diffstat (limited to 'bitbake/lib/bb/data_smart.py')
-rw-r--r-- | bitbake/lib/bb/data_smart.py | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py index fbd4167fe4..054b852200 100644 --- a/bitbake/lib/bb/data_smart.py +++ b/bitbake/lib/bb/data_smart.py | |||
@@ -29,14 +29,12 @@ Based on functions from the base bb module, Copyright 2003 Holger Schurig | |||
29 | """ | 29 | """ |
30 | 30 | ||
31 | import copy, os, re, sys, time, types | 31 | import copy, os, re, sys, time, types |
32 | from bb import note, debug, error, fatal, utils, methodpool | 32 | import bb |
33 | from bb import utils, methodpool | ||
34 | from COW import COWDictBase | ||
33 | from sets import Set | 35 | from sets import Set |
36 | from new import classobj | ||
34 | 37 | ||
35 | try: | ||
36 | import cPickle as pickle | ||
37 | except ImportError: | ||
38 | import pickle | ||
39 | print "NOTE: Importing cPickle failed. Falling back to a very slow implementation." | ||
40 | 38 | ||
41 | __setvar_keyword__ = ["_append","_prepend"] | 39 | __setvar_keyword__ = ["_append","_prepend"] |
42 | __setvar_regexp__ = re.compile('(?P<base>.*?)(?P<keyword>_append|_prepend)(_(?P<add>.*))?') | 40 | __setvar_regexp__ = re.compile('(?P<base>.*?)(?P<keyword>_append|_prepend)(_(?P<add>.*))?') |
@@ -45,12 +43,14 @@ __expand_python_regexp__ = re.compile(r"\${@.+?}") | |||
45 | 43 | ||
46 | 44 | ||
47 | class DataSmart: | 45 | class DataSmart: |
48 | def __init__(self): | 46 | def __init__(self, special = COWDictBase.copy(), seen = COWDictBase.copy() ): |
49 | self.dict = {} | 47 | self.dict = {} |
50 | 48 | ||
51 | # cookie monster tribute | 49 | # cookie monster tribute |
52 | self._special_values = {} | 50 | self._special_values = special |
53 | self._seen_overrides = {} | 51 | self._seen_overrides = seen |
52 | |||
53 | self.expand_cache = {} | ||
54 | 54 | ||
55 | def expand(self,s, varname): | 55 | def expand(self,s, varname): |
56 | def var_sub(match): | 56 | def var_sub(match): |
@@ -75,6 +75,9 @@ class DataSmart: | |||
75 | if type(s) is not types.StringType: # sanity check | 75 | if type(s) is not types.StringType: # sanity check |
76 | return s | 76 | return s |
77 | 77 | ||
78 | if varname and varname in self.expand_cache: | ||
79 | return self.expand_cache[varname] | ||
80 | |||
78 | while s.find('$') != -1: | 81 | while s.find('$') != -1: |
79 | olds = s | 82 | olds = s |
80 | try: | 83 | try: |
@@ -82,15 +85,20 @@ class DataSmart: | |||
82 | s = __expand_python_regexp__.sub(python_sub, s) | 85 | s = __expand_python_regexp__.sub(python_sub, s) |
83 | if s == olds: break | 86 | if s == olds: break |
84 | if type(s) is not types.StringType: # sanity check | 87 | if type(s) is not types.StringType: # sanity check |
85 | error('expansion of %s returned non-string %s' % (olds, s)) | 88 | bb.msg.error(bb.msg.domain.Data, 'expansion of %s returned non-string %s' % (olds, s)) |
86 | except KeyboardInterrupt: | 89 | except KeyboardInterrupt: |
87 | raise | 90 | raise |
88 | except: | 91 | except: |
89 | note("%s:%s while evaluating:\n%s" % (sys.exc_info()[0], sys.exc_info()[1], s)) | 92 | bb.msg.note(1, bb.msg.domain.Data, "%s:%s while evaluating:\n%s" % (sys.exc_info()[0], sys.exc_info()[1], s)) |
90 | raise | 93 | raise |
94 | |||
95 | if varname: | ||
96 | self.expand_cache[varname] = s | ||
97 | |||
91 | return s | 98 | return s |
92 | 99 | ||
93 | def initVar(self, var): | 100 | def initVar(self, var): |
101 | self.expand_cache = {} | ||
94 | if not var in self.dict: | 102 | if not var in self.dict: |
95 | self.dict[var] = {} | 103 | self.dict[var] = {} |
96 | 104 | ||
@@ -119,6 +127,7 @@ class DataSmart: | |||
119 | self.initVar(var) | 127 | self.initVar(var) |
120 | 128 | ||
121 | def setVar(self,var,value): | 129 | def setVar(self,var,value): |
130 | self.expand_cache = {} | ||
122 | match = __setvar_regexp__.match(var) | 131 | match = __setvar_regexp__.match(var) |
123 | if match and match.group("keyword") in __setvar_keyword__: | 132 | if match and match.group("keyword") in __setvar_keyword__: |
124 | base = match.group('base') | 133 | base = match.group('base') |
@@ -128,6 +137,7 @@ class DataSmart: | |||
128 | l.append([value, override]) | 137 | l.append([value, override]) |
129 | self.setVarFlag(base, keyword, l) | 138 | self.setVarFlag(base, keyword, l) |
130 | 139 | ||
140 | # todo make sure keyword is not __doc__ or __module__ | ||
131 | # pay the cookie monster | 141 | # pay the cookie monster |
132 | try: | 142 | try: |
133 | self._special_values[keyword].add( base ) | 143 | self._special_values[keyword].add( base ) |
@@ -135,10 +145,6 @@ class DataSmart: | |||
135 | self._special_values[keyword] = Set() | 145 | self._special_values[keyword] = Set() |
136 | self._special_values[keyword].add( base ) | 146 | self._special_values[keyword].add( base ) |
137 | 147 | ||
138 | # SRC_URI_append_simpad is both a flag and a override | ||
139 | #if not override in self._seen_overrides: | ||
140 | # self._seen_overrides[override] = Set() | ||
141 | #self._seen_overrides[override].add( base ) | ||
142 | return | 148 | return |
143 | 149 | ||
144 | if not var in self.dict: | 150 | if not var in self.dict: |
@@ -150,7 +156,7 @@ class DataSmart: | |||
150 | # more cookies for the cookie monster | 156 | # more cookies for the cookie monster |
151 | if '_' in var: | 157 | if '_' in var: |
152 | override = var[var.rfind('_')+1:] | 158 | override = var[var.rfind('_')+1:] |
153 | if not override in self._seen_overrides: | 159 | if not self._seen_overrides.has_key(override): |
154 | self._seen_overrides[override] = Set() | 160 | self._seen_overrides[override] = Set() |
155 | self._seen_overrides[override].add( var ) | 161 | self._seen_overrides[override].add( var ) |
156 | 162 | ||
@@ -165,6 +171,7 @@ class DataSmart: | |||
165 | return value | 171 | return value |
166 | 172 | ||
167 | def delVar(self,var): | 173 | def delVar(self,var): |
174 | self.expand_cache = {} | ||
168 | self.dict[var] = {} | 175 | self.dict[var] = {} |
169 | 176 | ||
170 | def setVarFlag(self,var,flag,flagvalue): | 177 | def setVarFlag(self,var,flag,flagvalue): |
@@ -234,10 +241,8 @@ class DataSmart: | |||
234 | Create a copy of self by setting _data to self | 241 | Create a copy of self by setting _data to self |
235 | """ | 242 | """ |
236 | # we really want this to be a DataSmart... | 243 | # we really want this to be a DataSmart... |
237 | data = DataSmart() | 244 | data = DataSmart(seen=self._seen_overrides.copy(), special=self._special_values.copy()) |
238 | data.dict["_data"] = self.dict | 245 | data.dict["_data"] = self.dict |
239 | data._seen_overrides = copy.deepcopy(self._seen_overrides) | ||
240 | data._special_values = copy.deepcopy(self._special_values) | ||
241 | 246 | ||
242 | return data | 247 | return data |
243 | 248 | ||