diff options
author | Richard Purdie <rpurdie@linux.intel.com> | 2010-01-20 18:46:02 +0000 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-01-20 18:46:02 +0000 |
commit | 22c29d8651668195f72e2f6a8e059d625eb511c3 (patch) | |
tree | dd1dd43f0ec47a9964c8a766eb8b3ad75cf51a64 /bitbake-dev/lib/bb/parse | |
parent | 1bfd6edef9db9c9175058ae801d1b601e4f15263 (diff) | |
download | poky-22c29d8651668195f72e2f6a8e059d625eb511c3.tar.gz |
bitbake: Switch to bitbake-dev version (bitbake master upstream)
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake-dev/lib/bb/parse')
-rw-r--r-- | bitbake-dev/lib/bb/parse/__init__.py | 84 | ||||
-rw-r--r-- | bitbake-dev/lib/bb/parse/parse_py/BBHandler.py | 410 | ||||
-rw-r--r-- | bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py | 241 | ||||
-rw-r--r-- | bitbake-dev/lib/bb/parse/parse_py/__init__.py | 33 |
4 files changed, 0 insertions, 768 deletions
diff --git a/bitbake-dev/lib/bb/parse/__init__.py b/bitbake-dev/lib/bb/parse/__init__.py deleted file mode 100644 index 5dd96c4136..0000000000 --- a/bitbake-dev/lib/bb/parse/__init__.py +++ /dev/null | |||
@@ -1,84 +0,0 @@ | |||
1 | """ | ||
2 | BitBake Parsers | ||
3 | |||
4 | File parsers for the BitBake build tools. | ||
5 | |||
6 | """ | ||
7 | |||
8 | |||
9 | # Copyright (C) 2003, 2004 Chris Larson | ||
10 | # Copyright (C) 2003, 2004 Phil Blundell | ||
11 | # | ||
12 | # This program is free software; you can redistribute it and/or modify | ||
13 | # it under the terms of the GNU General Public License version 2 as | ||
14 | # published by the Free Software Foundation. | ||
15 | # | ||
16 | # This program is distributed in the hope that it will be useful, | ||
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | # GNU General Public License for more details. | ||
20 | # | ||
21 | # You should have received a copy of the GNU General Public License along | ||
22 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
23 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
24 | # | ||
25 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig | ||
26 | |||
27 | __all__ = [ 'ParseError', 'SkipPackage', 'cached_mtime', 'mark_dependency', | ||
28 | 'supports', 'handle', 'init' ] | ||
29 | handlers = [] | ||
30 | |||
31 | import bb, os | ||
32 | |||
33 | class ParseError(Exception): | ||
34 | """Exception raised when parsing fails""" | ||
35 | |||
36 | class SkipPackage(Exception): | ||
37 | """Exception raised to skip this package""" | ||
38 | |||
39 | __mtime_cache = {} | ||
40 | def cached_mtime(f): | ||
41 | if not __mtime_cache.has_key(f): | ||
42 | __mtime_cache[f] = os.stat(f)[8] | ||
43 | return __mtime_cache[f] | ||
44 | |||
45 | def cached_mtime_noerror(f): | ||
46 | if not __mtime_cache.has_key(f): | ||
47 | try: | ||
48 | __mtime_cache[f] = os.stat(f)[8] | ||
49 | except OSError: | ||
50 | return 0 | ||
51 | return __mtime_cache[f] | ||
52 | |||
53 | def update_mtime(f): | ||
54 | __mtime_cache[f] = os.stat(f)[8] | ||
55 | return __mtime_cache[f] | ||
56 | |||
57 | def mark_dependency(d, f): | ||
58 | if f.startswith('./'): | ||
59 | f = "%s/%s" % (os.getcwd(), f[2:]) | ||
60 | deps = bb.data.getVar('__depends', d) or [] | ||
61 | deps.append( (f, cached_mtime(f)) ) | ||
62 | bb.data.setVar('__depends', deps, d) | ||
63 | |||
64 | def supports(fn, data): | ||
65 | """Returns true if we have a handler for this file, false otherwise""" | ||
66 | for h in handlers: | ||
67 | if h['supports'](fn, data): | ||
68 | return 1 | ||
69 | return 0 | ||
70 | |||
71 | def handle(fn, data, include = 0): | ||
72 | """Call the handler that is appropriate for this file""" | ||
73 | for h in handlers: | ||
74 | if h['supports'](fn, data): | ||
75 | return h['handle'](fn, data, include) | ||
76 | raise ParseError("%s is not a BitBake file" % fn) | ||
77 | |||
78 | def init(fn, data): | ||
79 | for h in handlers: | ||
80 | if h['supports'](fn): | ||
81 | return h['init'](data) | ||
82 | |||
83 | |||
84 | from parse_py import __version__, ConfHandler, BBHandler | ||
diff --git a/bitbake-dev/lib/bb/parse/parse_py/BBHandler.py b/bitbake-dev/lib/bb/parse/parse_py/BBHandler.py deleted file mode 100644 index 86fa18ebd2..0000000000 --- a/bitbake-dev/lib/bb/parse/parse_py/BBHandler.py +++ /dev/null | |||
@@ -1,410 +0,0 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | """ | ||
5 | class for handling .bb files | ||
6 | |||
7 | Reads a .bb file and obtains its metadata | ||
8 | |||
9 | """ | ||
10 | |||
11 | |||
12 | # Copyright (C) 2003, 2004 Chris Larson | ||
13 | # Copyright (C) 2003, 2004 Phil Blundell | ||
14 | # | ||
15 | # This program is free software; you can redistribute it and/or modify | ||
16 | # it under the terms of the GNU General Public License version 2 as | ||
17 | # published by the Free Software Foundation. | ||
18 | # | ||
19 | # This program is distributed in the hope that it will be useful, | ||
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | # GNU General Public License for more details. | ||
23 | # | ||
24 | # You should have received a copy of the GNU General Public License along | ||
25 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
26 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
27 | |||
28 | import re, bb, os, sys, time, string | ||
29 | import bb.fetch, bb.build, bb.utils | ||
30 | from bb import data, fetch, methodpool | ||
31 | |||
32 | from ConfHandler import include, localpath, obtain, init | ||
33 | from bb.parse import ParseError | ||
34 | |||
35 | __func_start_regexp__ = re.compile( r"(((?P<py>python)|(?P<fr>fakeroot))\s*)*(?P<func>[\w\.\-\+\{\}\$]+)?\s*\(\s*\)\s*{$" ) | ||
36 | __inherit_regexp__ = re.compile( r"inherit\s+(.+)" ) | ||
37 | __export_func_regexp__ = re.compile( r"EXPORT_FUNCTIONS\s+(.+)" ) | ||
38 | __addtask_regexp__ = re.compile("addtask\s+(?P<func>\w+)\s*((before\s*(?P<before>((.*(?=after))|(.*))))|(after\s*(?P<after>((.*(?=before))|(.*)))))*") | ||
39 | __addhandler_regexp__ = re.compile( r"addhandler\s+(.+)" ) | ||
40 | __def_regexp__ = re.compile( r"def\s+(\w+).*:" ) | ||
41 | __python_func_regexp__ = re.compile( r"(\s+.*)|(^$)" ) | ||
42 | __word__ = re.compile(r"\S+") | ||
43 | |||
44 | __infunc__ = "" | ||
45 | __inpython__ = False | ||
46 | __body__ = [] | ||
47 | __classname__ = "" | ||
48 | classes = [ None, ] | ||
49 | |||
50 | # We need to indicate EOF to the feeder. This code is so messy that | ||
51 | # factoring it out to a close_parse_file method is out of question. | ||
52 | # We will use the IN_PYTHON_EOF as an indicator to just close the method | ||
53 | # | ||
54 | # The two parts using it are tightly integrated anyway | ||
55 | IN_PYTHON_EOF = -9999999999999 | ||
56 | |||
57 | __parsed_methods__ = methodpool.get_parsed_dict() | ||
58 | |||
59 | def supports(fn, d): | ||
60 | localfn = localpath(fn, d) | ||
61 | return localfn[-3:] == ".bb" or localfn[-8:] == ".bbclass" or localfn[-4:] == ".inc" | ||
62 | |||
63 | def inherit(files, d): | ||
64 | __inherit_cache = data.getVar('__inherit_cache', d) or [] | ||
65 | fn = "" | ||
66 | lineno = 0 | ||
67 | files = data.expand(files, d) | ||
68 | for file in files: | ||
69 | if file[0] != "/" and file[-8:] != ".bbclass": | ||
70 | file = os.path.join('classes', '%s.bbclass' % file) | ||
71 | |||
72 | if not file in __inherit_cache: | ||
73 | bb.msg.debug(2, bb.msg.domain.Parsing, "BB %s:%d: inheriting %s" % (fn, lineno, file)) | ||
74 | __inherit_cache.append( file ) | ||
75 | data.setVar('__inherit_cache', __inherit_cache, d) | ||
76 | include(fn, file, d, "inherit") | ||
77 | __inherit_cache = data.getVar('__inherit_cache', d) or [] | ||
78 | |||
79 | |||
80 | def finalise(fn, d): | ||
81 | data.expandKeys(d) | ||
82 | data.update_data(d) | ||
83 | anonqueue = data.getVar("__anonqueue", d, 1) or [] | ||
84 | body = [x['content'] for x in anonqueue] | ||
85 | flag = { 'python' : 1, 'func' : 1 } | ||
86 | data.setVar("__anonfunc", "\n".join(body), d) | ||
87 | data.setVarFlags("__anonfunc", flag, d) | ||
88 | from bb import build | ||
89 | try: | ||
90 | t = data.getVar('T', d) | ||
91 | data.setVar('T', '${TMPDIR}/anonfunc/', d) | ||
92 | anonfuncs = data.getVar('__BBANONFUNCS', d) or [] | ||
93 | code = "" | ||
94 | for f in anonfuncs: | ||
95 | code = code + " %s(d)\n" % f | ||
96 | data.setVar("__anonfunc", code, d) | ||
97 | build.exec_func("__anonfunc", d) | ||
98 | data.delVar('T', d) | ||
99 | if t: | ||
100 | data.setVar('T', t, d) | ||
101 | except Exception, e: | ||
102 | bb.msg.debug(1, bb.msg.domain.Parsing, "Exception when executing anonymous function: %s" % e) | ||
103 | raise | ||
104 | data.delVar("__anonqueue", d) | ||
105 | data.delVar("__anonfunc", d) | ||
106 | data.update_data(d) | ||
107 | |||
108 | all_handlers = {} | ||
109 | for var in data.getVar('__BBHANDLERS', d) or []: | ||
110 | # try to add the handler | ||
111 | handler = data.getVar(var,d) | ||
112 | bb.event.register(var, handler) | ||
113 | |||
114 | tasklist = data.getVar('__BBTASKS', d) or [] | ||
115 | bb.build.add_tasks(tasklist, d) | ||
116 | |||
117 | bb.event.fire(bb.event.RecipeParsed(fn), d) | ||
118 | |||
119 | |||
120 | def handle(fn, d, include = 0): | ||
121 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __residue__ | ||
122 | __body__ = [] | ||
123 | __infunc__ = "" | ||
124 | __classname__ = "" | ||
125 | __residue__ = [] | ||
126 | |||
127 | if include == 0: | ||
128 | bb.msg.debug(2, bb.msg.domain.Parsing, "BB " + fn + ": handle(data)") | ||
129 | else: | ||
130 | bb.msg.debug(2, bb.msg.domain.Parsing, "BB " + fn + ": handle(data, include)") | ||
131 | |||
132 | (root, ext) = os.path.splitext(os.path.basename(fn)) | ||
133 | base_name = "%s%s" % (root,ext) | ||
134 | init(d) | ||
135 | |||
136 | if ext == ".bbclass": | ||
137 | __classname__ = root | ||
138 | classes.append(__classname__) | ||
139 | __inherit_cache = data.getVar('__inherit_cache', d) or [] | ||
140 | if not fn in __inherit_cache: | ||
141 | __inherit_cache.append(fn) | ||
142 | data.setVar('__inherit_cache', __inherit_cache, d) | ||
143 | |||
144 | if include != 0: | ||
145 | oldfile = data.getVar('FILE', d) | ||
146 | else: | ||
147 | oldfile = None | ||
148 | |||
149 | fn = obtain(fn, d) | ||
150 | bbpath = (data.getVar('BBPATH', d, 1) or '').split(':') | ||
151 | if not os.path.isabs(fn): | ||
152 | f = None | ||
153 | for p in bbpath: | ||
154 | j = os.path.join(p, fn) | ||
155 | if os.access(j, os.R_OK): | ||
156 | abs_fn = j | ||
157 | f = open(j, 'r') | ||
158 | break | ||
159 | if f is None: | ||
160 | raise IOError("file %s not found" % fn) | ||
161 | else: | ||
162 | f = open(fn,'r') | ||
163 | abs_fn = fn | ||
164 | |||
165 | if include: | ||
166 | bb.parse.mark_dependency(d, abs_fn) | ||
167 | |||
168 | if ext != ".bbclass": | ||
169 | data.setVar('FILE', fn, d) | ||
170 | |||
171 | lineno = 0 | ||
172 | while 1: | ||
173 | lineno = lineno + 1 | ||
174 | s = f.readline() | ||
175 | if not s: break | ||
176 | s = s.rstrip() | ||
177 | feeder(lineno, s, fn, base_name, d) | ||
178 | if __inpython__: | ||
179 | # add a blank line to close out any python definition | ||
180 | feeder(IN_PYTHON_EOF, "", fn, base_name, d) | ||
181 | if ext == ".bbclass": | ||
182 | classes.remove(__classname__) | ||
183 | else: | ||
184 | if include == 0: | ||
185 | multi = data.getVar('BBCLASSEXTEND', d, 1) | ||
186 | if multi: | ||
187 | based = bb.data.createCopy(d) | ||
188 | else: | ||
189 | based = d | ||
190 | try: | ||
191 | finalise(fn, based) | ||
192 | except bb.parse.SkipPackage: | ||
193 | bb.data.setVar("__SKIPPED", True, based) | ||
194 | darray = {"": based} | ||
195 | |||
196 | for cls in (multi or "").split(): | ||
197 | pn = data.getVar('PN', d, True) | ||
198 | based = bb.data.createCopy(d) | ||
199 | data.setVar('PN', pn + '-' + cls, based) | ||
200 | inherit([cls], based) | ||
201 | try: | ||
202 | finalise(fn, based) | ||
203 | except bb.parse.SkipPackage: | ||
204 | bb.data.setVar("__SKIPPED", True, based) | ||
205 | darray[cls] = based | ||
206 | return darray | ||
207 | |||
208 | bbpath.pop(0) | ||
209 | if oldfile: | ||
210 | bb.data.setVar("FILE", oldfile, d) | ||
211 | |||
212 | # we have parsed the bb class now | ||
213 | if ext == ".bbclass" or ext == ".inc": | ||
214 | __parsed_methods__[base_name] = 1 | ||
215 | |||
216 | return d | ||
217 | |||
218 | def feeder(lineno, s, fn, root, d): | ||
219 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, classes, bb, __residue__ | ||
220 | if __infunc__: | ||
221 | if s == '}': | ||
222 | __body__.append('') | ||
223 | if __infunc__ == "__anonymous": | ||
224 | funcname = ("__anon_%s_%s" % (lineno, fn.translate(string.maketrans('/.+-', '____')))) | ||
225 | if not funcname in methodpool._parsed_fns: | ||
226 | text = "def %s(d):\n" % (funcname) + '\n'.join(__body__) | ||
227 | methodpool.insert_method(funcname, text, fn) | ||
228 | anonfuncs = data.getVar('__BBANONFUNCS', d) or [] | ||
229 | anonfuncs.append(funcname) | ||
230 | data.setVar('__BBANONFUNCS', anonfuncs, d) | ||
231 | else: | ||
232 | data.setVarFlag(__infunc__, "func", 1, d) | ||
233 | data.setVar(__infunc__, '\n'.join(__body__), d) | ||
234 | __infunc__ = "" | ||
235 | __body__ = [] | ||
236 | else: | ||
237 | __body__.append(s) | ||
238 | return | ||
239 | |||
240 | if __inpython__: | ||
241 | m = __python_func_regexp__.match(s) | ||
242 | if m and lineno != IN_PYTHON_EOF: | ||
243 | __body__.append(s) | ||
244 | return | ||
245 | else: | ||
246 | # Note we will add root to parsedmethods after having parse | ||
247 | # 'this' file. This means we will not parse methods from | ||
248 | # bb classes twice | ||
249 | if not root in __parsed_methods__: | ||
250 | text = '\n'.join(__body__) | ||
251 | methodpool.insert_method( root, text, fn ) | ||
252 | __body__ = [] | ||
253 | __inpython__ = False | ||
254 | |||
255 | if lineno == IN_PYTHON_EOF: | ||
256 | return | ||
257 | |||
258 | # fall through | ||
259 | |||
260 | if s == '' or s[0] == '#': return # skip comments and empty lines | ||
261 | |||
262 | if s[-1] == '\\': | ||
263 | __residue__.append(s[:-1]) | ||
264 | return | ||
265 | |||
266 | s = "".join(__residue__) + s | ||
267 | __residue__ = [] | ||
268 | |||
269 | m = __func_start_regexp__.match(s) | ||
270 | if m: | ||
271 | __infunc__ = m.group("func") or "__anonymous" | ||
272 | key = __infunc__ | ||
273 | if data.getVar(key, d): | ||
274 | # clean up old version of this piece of metadata, as its | ||
275 | # flags could cause problems | ||
276 | data.setVarFlag(key, 'python', None, d) | ||
277 | data.setVarFlag(key, 'fakeroot', None, d) | ||
278 | if m.group("py") is not None: | ||
279 | data.setVarFlag(key, "python", "1", d) | ||
280 | else: | ||
281 | data.delVarFlag(key, "python", d) | ||
282 | if m.group("fr") is not None: | ||
283 | data.setVarFlag(key, "fakeroot", "1", d) | ||
284 | else: | ||
285 | data.delVarFlag(key, "fakeroot", d) | ||
286 | return | ||
287 | |||
288 | m = __def_regexp__.match(s) | ||
289 | if m: | ||
290 | __body__.append(s) | ||
291 | __inpython__ = True | ||
292 | return | ||
293 | |||
294 | m = __export_func_regexp__.match(s) | ||
295 | if m: | ||
296 | fns = m.group(1) | ||
297 | n = __word__.findall(fns) | ||
298 | for f in n: | ||
299 | allvars = [] | ||
300 | allvars.append(f) | ||
301 | allvars.append(classes[-1] + "_" + f) | ||
302 | |||
303 | vars = [[ allvars[0], allvars[1] ]] | ||
304 | if len(classes) > 1 and classes[-2] is not None: | ||
305 | allvars.append(classes[-2] + "_" + f) | ||
306 | vars = [] | ||
307 | vars.append([allvars[2], allvars[1]]) | ||
308 | vars.append([allvars[0], allvars[2]]) | ||
309 | |||
310 | for (var, calledvar) in vars: | ||
311 | if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d): | ||
312 | continue | ||
313 | |||
314 | if data.getVar(var, d): | ||
315 | data.setVarFlag(var, 'python', None, d) | ||
316 | data.setVarFlag(var, 'func', None, d) | ||
317 | |||
318 | for flag in [ "func", "python" ]: | ||
319 | if data.getVarFlag(calledvar, flag, d): | ||
320 | data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d) | ||
321 | for flag in [ "dirs" ]: | ||
322 | if data.getVarFlag(var, flag, d): | ||
323 | data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d) | ||
324 | |||
325 | if data.getVarFlag(calledvar, "python", d): | ||
326 | data.setVar(var, "\tbb.build.exec_func('" + calledvar + "', d)\n", d) | ||
327 | else: | ||
328 | data.setVar(var, "\t" + calledvar + "\n", d) | ||
329 | data.setVarFlag(var, 'export_func', '1', d) | ||
330 | |||
331 | return | ||
332 | |||
333 | m = __addtask_regexp__.match(s) | ||
334 | if m: | ||
335 | func = m.group("func") | ||
336 | before = m.group("before") | ||
337 | after = m.group("after") | ||
338 | if func is None: | ||
339 | return | ||
340 | if func[:3] != "do_": | ||
341 | var = "do_" + func | ||
342 | |||
343 | data.setVarFlag(var, "task", 1, d) | ||
344 | |||
345 | bbtasks = data.getVar('__BBTASKS', d) or [] | ||
346 | if not var in bbtasks: | ||
347 | bbtasks.append(var) | ||
348 | data.setVar('__BBTASKS', bbtasks, d) | ||
349 | |||
350 | existing = data.getVarFlag(var, "deps", d) or [] | ||
351 | if after is not None: | ||
352 | # set up deps for function | ||
353 | for entry in after.split(): | ||
354 | if entry not in existing: | ||
355 | existing.append(entry) | ||
356 | data.setVarFlag(var, "deps", existing, d) | ||
357 | if before is not None: | ||
358 | # set up things that depend on this func | ||
359 | for entry in before.split(): | ||
360 | existing = data.getVarFlag(entry, "deps", d) or [] | ||
361 | if var not in existing: | ||
362 | data.setVarFlag(entry, "deps", [var] + existing, d) | ||
363 | return | ||
364 | |||
365 | m = __addhandler_regexp__.match(s) | ||
366 | if m: | ||
367 | fns = m.group(1) | ||
368 | hs = __word__.findall(fns) | ||
369 | bbhands = data.getVar('__BBHANDLERS', d) or [] | ||
370 | for h in hs: | ||
371 | bbhands.append(h) | ||
372 | data.setVarFlag(h, "handler", 1, d) | ||
373 | data.setVar('__BBHANDLERS', bbhands, d) | ||
374 | return | ||
375 | |||
376 | m = __inherit_regexp__.match(s) | ||
377 | if m: | ||
378 | |||
379 | files = m.group(1) | ||
380 | n = __word__.findall(files) | ||
381 | inherit(n, d) | ||
382 | return | ||
383 | |||
384 | from bb.parse import ConfHandler | ||
385 | return ConfHandler.feeder(lineno, s, fn, d) | ||
386 | |||
387 | __pkgsplit_cache__={} | ||
388 | def vars_from_file(mypkg, d): | ||
389 | if not mypkg: | ||
390 | return (None, None, None) | ||
391 | if mypkg in __pkgsplit_cache__: | ||
392 | return __pkgsplit_cache__[mypkg] | ||
393 | |||
394 | myfile = os.path.splitext(os.path.basename(mypkg)) | ||
395 | parts = myfile[0].split('_') | ||
396 | __pkgsplit_cache__[mypkg] = parts | ||
397 | if len(parts) > 3: | ||
398 | raise ParseError("Unable to generate default variables from the filename: %s (too many underscores)" % mypkg) | ||
399 | exp = 3 - len(parts) | ||
400 | tmplist = [] | ||
401 | while exp != 0: | ||
402 | exp -= 1 | ||
403 | tmplist.append(None) | ||
404 | parts.extend(tmplist) | ||
405 | return parts | ||
406 | |||
407 | # Add us to the handlers list | ||
408 | from bb.parse import handlers | ||
409 | handlers.append({'supports': supports, 'handle': handle, 'init': init}) | ||
410 | del handlers | ||
diff --git a/bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py b/bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py deleted file mode 100644 index 23316ada58..0000000000 --- a/bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py +++ /dev/null | |||
@@ -1,241 +0,0 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | """ | ||
5 | class for handling configuration data files | ||
6 | |||
7 | Reads a .conf file and obtains its metadata | ||
8 | |||
9 | """ | ||
10 | |||
11 | # Copyright (C) 2003, 2004 Chris Larson | ||
12 | # Copyright (C) 2003, 2004 Phil Blundell | ||
13 | # | ||
14 | # This program is free software; you can redistribute it and/or modify | ||
15 | # it under the terms of the GNU General Public License version 2 as | ||
16 | # published by the Free Software Foundation. | ||
17 | # | ||
18 | # This program is distributed in the hope that it will be useful, | ||
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | # GNU General Public License for more details. | ||
22 | # | ||
23 | # You should have received a copy of the GNU General Public License along | ||
24 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
25 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
26 | |||
27 | import re, bb.data, os, sys | ||
28 | from bb.parse import ParseError | ||
29 | |||
30 | #__config_regexp__ = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${}]+)\s*(?P<colon>:)?(?P<ques>\?)?=\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$") | ||
31 | __config_regexp__ = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${}/]+)(\[(?P<flag>[a-zA-Z0-9\-_+.]+)\])?\s*((?P<colon>:=)|(?P<ques>\?=)|(?P<append>\+=)|(?P<prepend>=\+)|(?P<predot>=\.)|(?P<postdot>\.=)|=)\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$") | ||
32 | __include_regexp__ = re.compile( r"include\s+(.+)" ) | ||
33 | __require_regexp__ = re.compile( r"require\s+(.+)" ) | ||
34 | __export_regexp__ = re.compile( r"export\s+(.+)" ) | ||
35 | |||
36 | def init(data): | ||
37 | topdir = bb.data.getVar('TOPDIR', data) | ||
38 | if not topdir: | ||
39 | topdir = os.getcwd() | ||
40 | bb.data.setVar('TOPDIR', topdir, data) | ||
41 | if not bb.data.getVar('BBPATH', data): | ||
42 | from pkg_resources import Requirement, resource_filename | ||
43 | bitbake = Requirement.parse("bitbake") | ||
44 | datadir = resource_filename(bitbake, "../share/bitbake") | ||
45 | basedir = resource_filename(bitbake, "..") | ||
46 | bb.data.setVar('BBPATH', '%s:%s:%s' % (topdir, datadir, basedir), data) | ||
47 | |||
48 | |||
49 | def supports(fn, d): | ||
50 | return localpath(fn, d)[-5:] == ".conf" | ||
51 | |||
52 | def localpath(fn, d): | ||
53 | if os.path.exists(fn): | ||
54 | return fn | ||
55 | |||
56 | if "://" not in fn: | ||
57 | return fn | ||
58 | |||
59 | localfn = None | ||
60 | try: | ||
61 | localfn = bb.fetch.localpath(fn, d, False) | ||
62 | except bb.MalformedUrl: | ||
63 | pass | ||
64 | |||
65 | if not localfn: | ||
66 | return fn | ||
67 | return localfn | ||
68 | |||
69 | def obtain(fn, data): | ||
70 | import sys, bb | ||
71 | fn = bb.data.expand(fn, data) | ||
72 | localfn = bb.data.expand(localpath(fn, data), data) | ||
73 | |||
74 | if localfn != fn: | ||
75 | dldir = bb.data.getVar('DL_DIR', data, 1) | ||
76 | if not dldir: | ||
77 | bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: DL_DIR not defined") | ||
78 | return localfn | ||
79 | bb.mkdirhier(dldir) | ||
80 | try: | ||
81 | bb.fetch.init([fn], data) | ||
82 | except bb.fetch.NoMethodError: | ||
83 | (type, value, traceback) = sys.exc_info() | ||
84 | bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: no method: %s" % value) | ||
85 | return localfn | ||
86 | |||
87 | try: | ||
88 | bb.fetch.go(data) | ||
89 | except bb.fetch.MissingParameterError: | ||
90 | (type, value, traceback) = sys.exc_info() | ||
91 | bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: missing parameters: %s" % value) | ||
92 | return localfn | ||
93 | except bb.fetch.FetchError: | ||
94 | (type, value, traceback) = sys.exc_info() | ||
95 | bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: failed: %s" % value) | ||
96 | return localfn | ||
97 | return localfn | ||
98 | |||
99 | |||
100 | def include(oldfn, fn, data, error_out): | ||
101 | """ | ||
102 | |||
103 | error_out If True a ParseError will be reaised if the to be included | ||
104 | """ | ||
105 | if oldfn == fn: # prevent infinate recursion | ||
106 | return None | ||
107 | |||
108 | import bb | ||
109 | fn = bb.data.expand(fn, data) | ||
110 | oldfn = bb.data.expand(oldfn, data) | ||
111 | |||
112 | if not os.path.isabs(fn): | ||
113 | dname = os.path.dirname(oldfn) | ||
114 | bbpath = "%s:%s" % (dname, bb.data.getVar("BBPATH", data, 1)) | ||
115 | abs_fn = bb.which(bbpath, fn) | ||
116 | if abs_fn: | ||
117 | fn = abs_fn | ||
118 | |||
119 | from bb.parse import handle | ||
120 | try: | ||
121 | ret = handle(fn, data, True) | ||
122 | except IOError: | ||
123 | if error_out: | ||
124 | raise ParseError("Could not %(error_out)s file %(fn)s" % vars() ) | ||
125 | bb.msg.debug(2, bb.msg.domain.Parsing, "CONF file '%s' not found" % fn) | ||
126 | |||
127 | def handle(fn, data, include = 0): | ||
128 | if include: | ||
129 | inc_string = "including" | ||
130 | else: | ||
131 | inc_string = "reading" | ||
132 | init(data) | ||
133 | |||
134 | if include == 0: | ||
135 | oldfile = None | ||
136 | else: | ||
137 | oldfile = bb.data.getVar('FILE', data) | ||
138 | |||
139 | fn = obtain(fn, data) | ||
140 | if not os.path.isabs(fn): | ||
141 | f = None | ||
142 | bbpath = bb.data.getVar("BBPATH", data, 1) or [] | ||
143 | for p in bbpath.split(":"): | ||
144 | currname = os.path.join(p, fn) | ||
145 | if os.access(currname, os.R_OK): | ||
146 | f = open(currname, 'r') | ||
147 | abs_fn = currname | ||
148 | bb.msg.debug(2, bb.msg.domain.Parsing, "CONF %s %s" % (inc_string, currname)) | ||
149 | break | ||
150 | if f is None: | ||
151 | raise IOError("file '%s' not found" % fn) | ||
152 | else: | ||
153 | f = open(fn,'r') | ||
154 | bb.msg.debug(1, bb.msg.domain.Parsing, "CONF %s %s" % (inc_string,fn)) | ||
155 | abs_fn = fn | ||
156 | |||
157 | if include: | ||
158 | bb.parse.mark_dependency(data, abs_fn) | ||
159 | |||
160 | lineno = 0 | ||
161 | bb.data.setVar('FILE', fn, data) | ||
162 | while 1: | ||
163 | lineno = lineno + 1 | ||
164 | s = f.readline() | ||
165 | if not s: break | ||
166 | w = s.strip() | ||
167 | if not w: continue # skip empty lines | ||
168 | s = s.rstrip() | ||
169 | if s[0] == '#': continue # skip comments | ||
170 | while s[-1] == '\\': | ||
171 | s2 = f.readline()[:-1].strip() | ||
172 | lineno = lineno + 1 | ||
173 | s = s[:-1] + s2 | ||
174 | feeder(lineno, s, fn, data) | ||
175 | |||
176 | if oldfile: | ||
177 | bb.data.setVar('FILE', oldfile, data) | ||
178 | return data | ||
179 | |||
180 | def feeder(lineno, s, fn, data): | ||
181 | def getFunc(groupd, key, data): | ||
182 | if 'flag' in groupd and groupd['flag'] != None: | ||
183 | return bb.data.getVarFlag(key, groupd['flag'], data) | ||
184 | else: | ||
185 | return bb.data.getVar(key, data) | ||
186 | |||
187 | m = __config_regexp__.match(s) | ||
188 | if m: | ||
189 | groupd = m.groupdict() | ||
190 | key = groupd["var"] | ||
191 | if "exp" in groupd and groupd["exp"] != None: | ||
192 | bb.data.setVarFlag(key, "export", 1, data) | ||
193 | if "ques" in groupd and groupd["ques"] != None: | ||
194 | val = getFunc(groupd, key, data) | ||
195 | if val == None: | ||
196 | val = groupd["value"] | ||
197 | elif "colon" in groupd and groupd["colon"] != None: | ||
198 | e = data.createCopy() | ||
199 | bb.data.update_data(e) | ||
200 | val = bb.data.expand(groupd["value"], e) | ||
201 | elif "append" in groupd and groupd["append"] != None: | ||
202 | val = "%s %s" % ((getFunc(groupd, key, data) or ""), groupd["value"]) | ||
203 | elif "prepend" in groupd and groupd["prepend"] != None: | ||
204 | val = "%s %s" % (groupd["value"], (getFunc(groupd, key, data) or "")) | ||
205 | elif "postdot" in groupd and groupd["postdot"] != None: | ||
206 | val = "%s%s" % ((getFunc(groupd, key, data) or ""), groupd["value"]) | ||
207 | elif "predot" in groupd and groupd["predot"] != None: | ||
208 | val = "%s%s" % (groupd["value"], (getFunc(groupd, key, data) or "")) | ||
209 | else: | ||
210 | val = groupd["value"] | ||
211 | if 'flag' in groupd and groupd['flag'] != None: | ||
212 | bb.msg.debug(3, bb.msg.domain.Parsing, "setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val)) | ||
213 | bb.data.setVarFlag(key, groupd['flag'], val, data) | ||
214 | else: | ||
215 | bb.data.setVar(key, val, data) | ||
216 | return | ||
217 | |||
218 | m = __include_regexp__.match(s) | ||
219 | if m: | ||
220 | s = bb.data.expand(m.group(1), data) | ||
221 | bb.msg.debug(3, bb.msg.domain.Parsing, "CONF %s:%d: including %s" % (fn, lineno, s)) | ||
222 | include(fn, s, data, False) | ||
223 | return | ||
224 | |||
225 | m = __require_regexp__.match(s) | ||
226 | if m: | ||
227 | s = bb.data.expand(m.group(1), data) | ||
228 | include(fn, s, data, "include required") | ||
229 | return | ||
230 | |||
231 | m = __export_regexp__.match(s) | ||
232 | if m: | ||
233 | bb.data.setVarFlag(m.group(1), "export", 1, data) | ||
234 | return | ||
235 | |||
236 | raise ParseError("%s:%d: unparsed line: '%s'" % (fn, lineno, s)); | ||
237 | |||
238 | # Add us to the handlers list | ||
239 | from bb.parse import handlers | ||
240 | handlers.append({'supports': supports, 'handle': handle, 'init': init}) | ||
241 | del handlers | ||
diff --git a/bitbake-dev/lib/bb/parse/parse_py/__init__.py b/bitbake-dev/lib/bb/parse/parse_py/__init__.py deleted file mode 100644 index 9e0e00adda..0000000000 --- a/bitbake-dev/lib/bb/parse/parse_py/__init__.py +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | """ | ||
5 | BitBake Parsers | ||
6 | |||
7 | File parsers for the BitBake build tools. | ||
8 | |||
9 | """ | ||
10 | |||
11 | # Copyright (C) 2003, 2004 Chris Larson | ||
12 | # Copyright (C) 2003, 2004 Phil Blundell | ||
13 | # | ||
14 | # This program is free software; you can redistribute it and/or modify | ||
15 | # it under the terms of the GNU General Public License version 2 as | ||
16 | # published by the Free Software Foundation. | ||
17 | # | ||
18 | # This program is distributed in the hope that it will be useful, | ||
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | # GNU General Public License for more details. | ||
22 | # | ||
23 | # You should have received a copy of the GNU General Public License along | ||
24 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
25 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
26 | # | ||
27 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig | ||
28 | __version__ = '1.0' | ||
29 | |||
30 | __all__ = [ 'ConfHandler', 'BBHandler'] | ||
31 | |||
32 | import ConfHandler | ||
33 | import BBHandler | ||