diff options
-rw-r--r-- | scripts/lib/wic/utils/oe/misc.py | 91 |
1 files changed, 53 insertions, 38 deletions
diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py index 9c8f52dd0d..3537a2e711 100644 --- a/scripts/lib/wic/utils/oe/misc.py +++ b/scripts/lib/wic/utils/oe/misc.py | |||
@@ -124,48 +124,63 @@ def exec_native_cmd(cmd_and_args, native_sysroot, catch=3): | |||
124 | 124 | ||
125 | BOOTDD_EXTRA_SPACE = 16384 | 125 | BOOTDD_EXTRA_SPACE = 16384 |
126 | 126 | ||
127 | _BITBAKE_VARS = defaultdict(dict) | 127 | class BitbakeVars(defaultdict): |
128 | """ | ||
129 | Container for Bitbake variables. | ||
130 | """ | ||
131 | def __init__(self): | ||
132 | defaultdict.__init__(self, dict) | ||
133 | |||
134 | def get_var(self, var, image=None): | ||
135 | """ | ||
136 | Get bitbake variable value lazy way, i.e. run | ||
137 | 'bitbake -e' only when variable is requested. | ||
138 | """ | ||
139 | if image not in self: | ||
140 | # Get bitbake -e output | ||
141 | cmd = "bitbake -e" | ||
142 | if image: | ||
143 | cmd += " %s" % image | ||
144 | |||
145 | log_level = msger.get_loglevel() | ||
146 | msger.set_loglevel('normal') | ||
147 | ret, lines = _exec_cmd(cmd) | ||
148 | msger.set_loglevel(log_level) | ||
149 | |||
150 | if ret: | ||
151 | print "Couldn't get '%s' output." % cmd | ||
152 | print "Bitbake failed with error:\n%s\n" % lines | ||
153 | return | ||
154 | |||
155 | # Parse bitbake -e output | ||
156 | for line in lines.split('\n'): | ||
157 | if "=" not in line: | ||
158 | continue | ||
159 | try: | ||
160 | key, val = line.split("=") | ||
161 | except ValueError: | ||
162 | continue | ||
163 | key = key.strip() | ||
164 | val = val.strip() | ||
165 | if key.replace('_', '').isalnum(): | ||
166 | self[image][key] = val.strip('"') | ||
167 | |||
168 | # Make first image a default set of variables | ||
169 | images = [key for key in self if key] | ||
170 | if len(images) == 1: | ||
171 | self[None] = self[image] | ||
172 | |||
173 | return self[image].get(var) | ||
174 | |||
175 | # Create BB_VARS singleton | ||
176 | BB_VARS = BitbakeVars() | ||
128 | 177 | ||
129 | def get_bitbake_var(var, image=None): | 178 | def get_bitbake_var(var, image=None): |
130 | """ | 179 | """ |
131 | Get bitbake variable value lazy way, i.e. run | 180 | Provide old get_bitbake_var API by wrapping |
132 | 'bitbake -e' only when variable is requested. | 181 | get_var method of BB_VARS singleton. |
133 | """ | 182 | """ |
134 | if image not in _BITBAKE_VARS: | 183 | return BB_VARS.get_var(var, image) |
135 | # Get bitbake -e output | ||
136 | cmd = "bitbake -e" | ||
137 | if image: | ||
138 | cmd += " %s" % image | ||
139 | |||
140 | log_level = msger.get_loglevel() | ||
141 | msger.set_loglevel('normal') | ||
142 | ret, lines = _exec_cmd(cmd) | ||
143 | msger.set_loglevel(log_level) | ||
144 | |||
145 | if ret: | ||
146 | print "Couldn't get '%s' output." % cmd | ||
147 | print "Bitbake failed with error:\n%s\n" % lines | ||
148 | return | ||
149 | |||
150 | # Parse bitbake -e output | ||
151 | for line in lines.split('\n'): | ||
152 | if "=" not in line: | ||
153 | continue | ||
154 | try: | ||
155 | key, val = line.split("=") | ||
156 | except ValueError: | ||
157 | continue | ||
158 | key = key.strip() | ||
159 | val = val.strip() | ||
160 | if key.replace('_', '').isalnum(): | ||
161 | _BITBAKE_VARS[image][key] = val.strip('"') | ||
162 | |||
163 | # Make first image a default set of variables | ||
164 | images = [key for key in _BITBAKE_VARS if key] | ||
165 | if len(images) == 1: | ||
166 | _BITBAKE_VARS[None] = _BITBAKE_VARS[image] | ||
167 | |||
168 | return _BITBAKE_VARS[image].get(var) | ||
169 | 184 | ||
170 | def parse_sourceparams(sourceparams): | 185 | def parse_sourceparams(sourceparams): |
171 | """ | 186 | """ |