diff options
| author | Richard Purdie <richard@openedhand.com> | 2008-09-30 15:08:33 +0000 |
|---|---|---|
| committer | Richard Purdie <richard@openedhand.com> | 2008-09-30 15:08:33 +0000 |
| commit | c30eddb243e7e65f67f656e62848a033cf6f2e5c (patch) | |
| tree | 110dd95788b76f55d31cb8d30aac2de8400b6f4a /bitbake-dev/lib/bb/parse | |
| parent | 5ef0510474004eeb2ae8a99b64e2febb1920e077 (diff) | |
| download | poky-c30eddb243e7e65f67f656e62848a033cf6f2e5c.tar.gz | |
Add bitbake-dev to allow ease of testing and development of bitbake trunk
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@5337 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'bitbake-dev/lib/bb/parse')
| -rw-r--r-- | bitbake-dev/lib/bb/parse/__init__.py | 80 | ||||
| -rw-r--r-- | bitbake-dev/lib/bb/parse/parse_py/BBHandler.py | 416 | ||||
| -rw-r--r-- | bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py | 228 | ||||
| -rw-r--r-- | bitbake-dev/lib/bb/parse/parse_py/__init__.py | 33 |
4 files changed, 757 insertions, 0 deletions
diff --git a/bitbake-dev/lib/bb/parse/__init__.py b/bitbake-dev/lib/bb/parse/__init__.py new file mode 100644 index 0000000000..3c9ba8e6da --- /dev/null +++ b/bitbake-dev/lib/bb/parse/__init__.py | |||
| @@ -0,0 +1,80 @@ | |||
| 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 mark_dependency(d, f): | ||
| 54 | if f.startswith('./'): | ||
| 55 | f = "%s/%s" % (os.getcwd(), f[2:]) | ||
| 56 | deps = bb.data.getVar('__depends', d) or [] | ||
| 57 | deps.append( (f, cached_mtime(f)) ) | ||
| 58 | bb.data.setVar('__depends', deps, d) | ||
| 59 | |||
| 60 | def supports(fn, data): | ||
| 61 | """Returns true if we have a handler for this file, false otherwise""" | ||
| 62 | for h in handlers: | ||
| 63 | if h['supports'](fn, data): | ||
| 64 | return 1 | ||
| 65 | return 0 | ||
| 66 | |||
| 67 | def handle(fn, data, include = 0): | ||
| 68 | """Call the handler that is appropriate for this file""" | ||
| 69 | for h in handlers: | ||
| 70 | if h['supports'](fn, data): | ||
| 71 | return h['handle'](fn, data, include) | ||
| 72 | raise ParseError("%s is not a BitBake file" % fn) | ||
| 73 | |||
| 74 | def init(fn, data): | ||
| 75 | for h in handlers: | ||
| 76 | if h['supports'](fn): | ||
| 77 | return h['init'](data) | ||
| 78 | |||
| 79 | |||
| 80 | 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 new file mode 100644 index 0000000000..e9b950acbd --- /dev/null +++ b/bitbake-dev/lib/bb/parse/parse_py/BBHandler.py | |||
| @@ -0,0 +1,416 @@ | |||
| 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 | ||
| 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 | def handle(fn, d, include = 0): | ||
| 80 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __residue__ | ||
| 81 | __body__ = [] | ||
| 82 | __infunc__ = "" | ||
| 83 | __classname__ = "" | ||
| 84 | __residue__ = [] | ||
| 85 | |||
| 86 | if include == 0: | ||
| 87 | bb.msg.debug(2, bb.msg.domain.Parsing, "BB " + fn + ": handle(data)") | ||
| 88 | else: | ||
| 89 | bb.msg.debug(2, bb.msg.domain.Parsing, "BB " + fn + ": handle(data, include)") | ||
| 90 | |||
| 91 | (root, ext) = os.path.splitext(os.path.basename(fn)) | ||
| 92 | base_name = "%s%s" % (root,ext) | ||
| 93 | init(d) | ||
| 94 | |||
| 95 | if ext == ".bbclass": | ||
| 96 | __classname__ = root | ||
| 97 | classes.append(__classname__) | ||
| 98 | __inherit_cache = data.getVar('__inherit_cache', d) or [] | ||
| 99 | if not fn in __inherit_cache: | ||
| 100 | __inherit_cache.append(fn) | ||
| 101 | data.setVar('__inherit_cache', __inherit_cache, d) | ||
| 102 | |||
| 103 | if include != 0: | ||
| 104 | oldfile = data.getVar('FILE', d) | ||
| 105 | else: | ||
| 106 | oldfile = None | ||
| 107 | |||
| 108 | fn = obtain(fn, d) | ||
| 109 | bbpath = (data.getVar('BBPATH', d, 1) or '').split(':') | ||
| 110 | if not os.path.isabs(fn): | ||
| 111 | f = None | ||
| 112 | for p in bbpath: | ||
| 113 | j = os.path.join(p, fn) | ||
| 114 | if os.access(j, os.R_OK): | ||
| 115 | abs_fn = j | ||
| 116 | f = open(j, 'r') | ||
| 117 | break | ||
| 118 | if f is None: | ||
| 119 | raise IOError("file %s not found" % fn) | ||
| 120 | else: | ||
| 121 | f = open(fn,'r') | ||
| 122 | abs_fn = fn | ||
| 123 | |||
| 124 | if ext != ".bbclass": | ||
| 125 | dname = os.path.dirname(abs_fn) | ||
| 126 | if dname not in bbpath: | ||
| 127 | bbpath.insert(0, dname) | ||
| 128 | data.setVar('BBPATH', ":".join(bbpath), d) | ||
| 129 | |||
| 130 | if include: | ||
| 131 | bb.parse.mark_dependency(d, abs_fn) | ||
| 132 | |||
| 133 | if ext != ".bbclass": | ||
| 134 | data.setVar('FILE', fn, d) | ||
| 135 | |||
| 136 | lineno = 0 | ||
| 137 | while 1: | ||
| 138 | lineno = lineno + 1 | ||
| 139 | s = f.readline() | ||
| 140 | if not s: break | ||
| 141 | s = s.rstrip() | ||
| 142 | feeder(lineno, s, fn, base_name, d) | ||
| 143 | if __inpython__: | ||
| 144 | # add a blank line to close out any python definition | ||
| 145 | feeder(IN_PYTHON_EOF, "", fn, base_name, d) | ||
| 146 | if ext == ".bbclass": | ||
| 147 | classes.remove(__classname__) | ||
| 148 | else: | ||
| 149 | if include == 0: | ||
| 150 | data.expandKeys(d) | ||
| 151 | data.update_data(d) | ||
| 152 | anonqueue = data.getVar("__anonqueue", d, 1) or [] | ||
| 153 | body = [x['content'] for x in anonqueue] | ||
| 154 | flag = { 'python' : 1, 'func' : 1 } | ||
| 155 | data.setVar("__anonfunc", "\n".join(body), d) | ||
| 156 | data.setVarFlags("__anonfunc", flag, d) | ||
| 157 | from bb import build | ||
| 158 | try: | ||
| 159 | t = data.getVar('T', d) | ||
| 160 | data.setVar('T', '${TMPDIR}/anonfunc/', d) | ||
| 161 | build.exec_func("__anonfunc", d) | ||
| 162 | data.delVar('T', d) | ||
| 163 | if t: | ||
| 164 | data.setVar('T', t, d) | ||
| 165 | except Exception, e: | ||
| 166 | bb.msg.debug(1, bb.msg.domain.Parsing, "Exception when executing anonymous function: %s" % e) | ||
| 167 | raise | ||
| 168 | data.delVar("__anonqueue", d) | ||
| 169 | data.delVar("__anonfunc", d) | ||
| 170 | set_additional_vars(fn, d, include) | ||
| 171 | data.update_data(d) | ||
| 172 | |||
| 173 | all_handlers = {} | ||
| 174 | for var in data.getVar('__BBHANDLERS', d) or []: | ||
| 175 | # try to add the handler | ||
| 176 | handler = data.getVar(var,d) | ||
| 177 | bb.event.register(var, handler) | ||
| 178 | |||
| 179 | tasklist = data.getVar('__BBTASKS', d) or [] | ||
| 180 | bb.build.add_tasks(tasklist, d) | ||
| 181 | |||
| 182 | bbpath.pop(0) | ||
| 183 | if oldfile: | ||
| 184 | bb.data.setVar("FILE", oldfile, d) | ||
| 185 | |||
| 186 | # we have parsed the bb class now | ||
| 187 | if ext == ".bbclass" or ext == ".inc": | ||
| 188 | __parsed_methods__[base_name] = 1 | ||
| 189 | |||
| 190 | return d | ||
| 191 | |||
| 192 | def feeder(lineno, s, fn, root, d): | ||
| 193 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, classes, bb, __residue__ | ||
| 194 | if __infunc__: | ||
| 195 | if s == '}': | ||
| 196 | __body__.append('') | ||
| 197 | data.setVar(__infunc__, '\n'.join(__body__), d) | ||
| 198 | data.setVarFlag(__infunc__, "func", 1, d) | ||
| 199 | if __infunc__ == "__anonymous": | ||
| 200 | anonqueue = bb.data.getVar("__anonqueue", d) or [] | ||
| 201 | anonitem = {} | ||
| 202 | anonitem["content"] = bb.data.getVar("__anonymous", d) | ||
| 203 | anonitem["flags"] = bb.data.getVarFlags("__anonymous", d) | ||
| 204 | anonqueue.append(anonitem) | ||
| 205 | bb.data.setVar("__anonqueue", anonqueue, d) | ||
| 206 | bb.data.delVarFlags("__anonymous", d) | ||
| 207 | bb.data.delVar("__anonymous", d) | ||
| 208 | __infunc__ = "" | ||
| 209 | __body__ = [] | ||
| 210 | else: | ||
| 211 | __body__.append(s) | ||
| 212 | return | ||
| 213 | |||
| 214 | if __inpython__: | ||
| 215 | m = __python_func_regexp__.match(s) | ||
| 216 | if m and lineno != IN_PYTHON_EOF: | ||
| 217 | __body__.append(s) | ||
| 218 | return | ||
| 219 | else: | ||
| 220 | # Note we will add root to parsedmethods after having parse | ||
| 221 | # 'this' file. This means we will not parse methods from | ||
| 222 | # bb classes twice | ||
| 223 | if not root in __parsed_methods__: | ||
| 224 | text = '\n'.join(__body__) | ||
| 225 | methodpool.insert_method( root, text, fn ) | ||
| 226 | funcs = data.getVar('__functions__', d) or {} | ||
| 227 | if not funcs.has_key( root ): | ||
| 228 | funcs[root] = text | ||
| 229 | else: | ||
| 230 | funcs[root] = "%s\n%s" % (funcs[root], text) | ||
| 231 | |||
| 232 | data.setVar('__functions__', funcs, d) | ||
| 233 | __body__ = [] | ||
| 234 | __inpython__ = False | ||
| 235 | |||
| 236 | if lineno == IN_PYTHON_EOF: | ||
| 237 | return | ||
| 238 | |||
| 239 | # fall through | ||
| 240 | |||
| 241 | if s == '' or s[0] == '#': return # skip comments and empty lines | ||
| 242 | |||
| 243 | if s[-1] == '\\': | ||
| 244 | __residue__.append(s[:-1]) | ||
| 245 | return | ||
| 246 | |||
| 247 | s = "".join(__residue__) + s | ||
| 248 | __residue__ = [] | ||
| 249 | |||
| 250 | m = __func_start_regexp__.match(s) | ||
| 251 | if m: | ||
| 252 | __infunc__ = m.group("func") or "__anonymous" | ||
| 253 | key = __infunc__ | ||
| 254 | if data.getVar(key, d): | ||
| 255 | # clean up old version of this piece of metadata, as its | ||
| 256 | # flags could cause problems | ||
| 257 | data.setVarFlag(key, 'python', None, d) | ||
| 258 | data.setVarFlag(key, 'fakeroot', None, d) | ||
| 259 | if m.group("py") is not None: | ||
| 260 | data.setVarFlag(key, "python", "1", d) | ||
| 261 | else: | ||
| 262 | data.delVarFlag(key, "python", d) | ||
| 263 | if m.group("fr") is not None: | ||
| 264 | data.setVarFlag(key, "fakeroot", "1", d) | ||
| 265 | else: | ||
| 266 | data.delVarFlag(key, "fakeroot", d) | ||
| 267 | return | ||
| 268 | |||
| 269 | m = __def_regexp__.match(s) | ||
| 270 | if m: | ||
| 271 | __body__.append(s) | ||
| 272 | __inpython__ = True | ||
| 273 | return | ||
| 274 | |||
| 275 | m = __export_func_regexp__.match(s) | ||
| 276 | if m: | ||
| 277 | fns = m.group(1) | ||
| 278 | n = __word__.findall(fns) | ||
| 279 | for f in n: | ||
| 280 | allvars = [] | ||
| 281 | allvars.append(f) | ||
| 282 | allvars.append(classes[-1] + "_" + f) | ||
| 283 | |||
| 284 | vars = [[ allvars[0], allvars[1] ]] | ||
| 285 | if len(classes) > 1 and classes[-2] is not None: | ||
| 286 | allvars.append(classes[-2] + "_" + f) | ||
| 287 | vars = [] | ||
| 288 | vars.append([allvars[2], allvars[1]]) | ||
| 289 | vars.append([allvars[0], allvars[2]]) | ||
| 290 | |||
| 291 | for (var, calledvar) in vars: | ||
| 292 | if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d): | ||
| 293 | continue | ||
| 294 | |||
| 295 | if data.getVar(var, d): | ||
| 296 | data.setVarFlag(var, 'python', None, d) | ||
| 297 | data.setVarFlag(var, 'func', None, d) | ||
| 298 | |||
| 299 | for flag in [ "func", "python" ]: | ||
| 300 | if data.getVarFlag(calledvar, flag, d): | ||
| 301 | data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d) | ||
| 302 | for flag in [ "dirs" ]: | ||
| 303 | if data.getVarFlag(var, flag, d): | ||
| 304 | data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d) | ||
| 305 | |||
| 306 | if data.getVarFlag(calledvar, "python", d): | ||
| 307 | data.setVar(var, "\tbb.build.exec_func('" + calledvar + "', d)\n", d) | ||
| 308 | else: | ||
| 309 | data.setVar(var, "\t" + calledvar + "\n", d) | ||
| 310 | data.setVarFlag(var, 'export_func', '1', d) | ||
| 311 | |||
| 312 | return | ||
| 313 | |||
| 314 | m = __addtask_regexp__.match(s) | ||
| 315 | if m: | ||
| 316 | func = m.group("func") | ||
| 317 | before = m.group("before") | ||
| 318 | after = m.group("after") | ||
| 319 | if func is None: | ||
| 320 | return | ||
| 321 | var = "do_" + func | ||
| 322 | |||
| 323 | data.setVarFlag(var, "task", 1, d) | ||
| 324 | |||
| 325 | bbtasks = data.getVar('__BBTASKS', d) or [] | ||
| 326 | if not var in bbtasks: | ||
| 327 | bbtasks.append(var) | ||
| 328 | data.setVar('__BBTASKS', bbtasks, d) | ||
| 329 | |||
| 330 | existing = data.getVarFlag(var, "deps", d) or [] | ||
| 331 | if after is not None: | ||
| 332 | # set up deps for function | ||
| 333 | for entry in after.split(): | ||
| 334 | if entry not in existing: | ||
| 335 | existing.append(entry) | ||
| 336 | data.setVarFlag(var, "deps", existing, d) | ||
| 337 | if before is not None: | ||
| 338 | # set up things that depend on this func | ||
| 339 | for entry in before.split(): | ||
| 340 | existing = data.getVarFlag(entry, "deps", d) or [] | ||
| 341 | if var not in existing: | ||
| 342 | data.setVarFlag(entry, "deps", [var] + existing, d) | ||
| 343 | return | ||
| 344 | |||
| 345 | m = __addhandler_regexp__.match(s) | ||
| 346 | if m: | ||
| 347 | fns = m.group(1) | ||
| 348 | hs = __word__.findall(fns) | ||
| 349 | bbhands = data.getVar('__BBHANDLERS', d) or [] | ||
| 350 | for h in hs: | ||
| 351 | bbhands.append(h) | ||
| 352 | data.setVarFlag(h, "handler", 1, d) | ||
| 353 | data.setVar('__BBHANDLERS', bbhands, d) | ||
| 354 | return | ||
| 355 | |||
| 356 | m = __inherit_regexp__.match(s) | ||
| 357 | if m: | ||
| 358 | |||
| 359 | files = m.group(1) | ||
| 360 | n = __word__.findall(files) | ||
| 361 | inherit(n, d) | ||
| 362 | return | ||
| 363 | |||
| 364 | from bb.parse import ConfHandler | ||
| 365 | return ConfHandler.feeder(lineno, s, fn, d) | ||
| 366 | |||
| 367 | __pkgsplit_cache__={} | ||
| 368 | def vars_from_file(mypkg, d): | ||
| 369 | if not mypkg: | ||
| 370 | return (None, None, None) | ||
| 371 | if mypkg in __pkgsplit_cache__: | ||
| 372 | return __pkgsplit_cache__[mypkg] | ||
| 373 | |||
| 374 | myfile = os.path.splitext(os.path.basename(mypkg)) | ||
| 375 | parts = myfile[0].split('_') | ||
| 376 | __pkgsplit_cache__[mypkg] = parts | ||
| 377 | if len(parts) > 3: | ||
| 378 | raise ParseError("Unable to generate default variables from the filename: %s (too many underscores)" % mypkg) | ||
| 379 | exp = 3 - len(parts) | ||
| 380 | tmplist = [] | ||
| 381 | while exp != 0: | ||
| 382 | exp -= 1 | ||
| 383 | tmplist.append(None) | ||
| 384 | parts.extend(tmplist) | ||
| 385 | return parts | ||
| 386 | |||
| 387 | def set_additional_vars(file, d, include): | ||
| 388 | """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}""" | ||
| 389 | |||
| 390 | return | ||
| 391 | # Nothing seems to use this variable | ||
| 392 | #bb.msg.debug(2, bb.msg.domain.Parsing, "BB %s: set_additional_vars" % file) | ||
| 393 | |||
| 394 | #src_uri = data.getVar('SRC_URI', d, 1) | ||
| 395 | #if not src_uri: | ||
| 396 | # return | ||
| 397 | |||
| 398 | #a = (data.getVar('A', d, 1) or '').split() | ||
| 399 | |||
| 400 | #from bb import fetch | ||
| 401 | #try: | ||
| 402 | # ud = fetch.init(src_uri.split(), d) | ||
| 403 | # a += fetch.localpaths(d, ud) | ||
| 404 | #except fetch.NoMethodError: | ||
| 405 | # pass | ||
| 406 | #except bb.MalformedUrl,e: | ||
| 407 | # raise ParseError("Unable to generate local paths for SRC_URI due to malformed uri: %s" % e) | ||
| 408 | #del fetch | ||
| 409 | |||
| 410 | #data.setVar('A', " ".join(a), d) | ||
| 411 | |||
| 412 | |||
| 413 | # Add us to the handlers list | ||
| 414 | from bb.parse import handlers | ||
| 415 | handlers.append({'supports': supports, 'handle': handle, 'init': init}) | ||
| 416 | del handlers | ||
diff --git a/bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py b/bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py new file mode 100644 index 0000000000..e6488bbe11 --- /dev/null +++ b/bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py | |||
| @@ -0,0 +1,228 @@ | |||
| 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 | if not bb.data.getVar('TOPDIR', data): | ||
| 38 | bb.data.setVar('TOPDIR', os.getcwd(), data) | ||
| 39 | if not bb.data.getVar('BBPATH', data): | ||
| 40 | bb.data.setVar('BBPATH', os.path.join(sys.prefix, 'share', 'bitbake'), data) | ||
| 41 | |||
| 42 | def supports(fn, d): | ||
| 43 | return localpath(fn, d)[-5:] == ".conf" | ||
| 44 | |||
| 45 | def localpath(fn, d): | ||
| 46 | if os.path.exists(fn): | ||
| 47 | return fn | ||
| 48 | |||
| 49 | if "://" not in fn: | ||
| 50 | return fn | ||
| 51 | |||
| 52 | localfn = None | ||
| 53 | try: | ||
| 54 | localfn = bb.fetch.localpath(fn, d, False) | ||
| 55 | except bb.MalformedUrl: | ||
| 56 | pass | ||
| 57 | |||
| 58 | if not localfn: | ||
| 59 | return fn | ||
| 60 | return localfn | ||
| 61 | |||
| 62 | def obtain(fn, data): | ||
| 63 | import sys, bb | ||
| 64 | fn = bb.data.expand(fn, data) | ||
| 65 | localfn = bb.data.expand(localpath(fn, data), data) | ||
| 66 | |||
| 67 | if localfn != fn: | ||
| 68 | dldir = bb.data.getVar('DL_DIR', data, 1) | ||
| 69 | if not dldir: | ||
| 70 | bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: DL_DIR not defined") | ||
| 71 | return localfn | ||
| 72 | bb.mkdirhier(dldir) | ||
| 73 | try: | ||
| 74 | bb.fetch.init([fn], data) | ||
| 75 | except bb.fetch.NoMethodError: | ||
| 76 | (type, value, traceback) = sys.exc_info() | ||
| 77 | bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: no method: %s" % value) | ||
| 78 | return localfn | ||
| 79 | |||
| 80 | try: | ||
| 81 | bb.fetch.go(data) | ||
| 82 | except bb.fetch.MissingParameterError: | ||
| 83 | (type, value, traceback) = sys.exc_info() | ||
| 84 | bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: missing parameters: %s" % value) | ||
| 85 | return localfn | ||
| 86 | except bb.fetch.FetchError: | ||
| 87 | (type, value, traceback) = sys.exc_info() | ||
| 88 | bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: failed: %s" % value) | ||
| 89 | return localfn | ||
| 90 | return localfn | ||
| 91 | |||
| 92 | |||
| 93 | def include(oldfn, fn, data, error_out): | ||
| 94 | """ | ||
| 95 | |||
| 96 | error_out If True a ParseError will be reaised if the to be included | ||
| 97 | """ | ||
| 98 | if oldfn == fn: # prevent infinate recursion | ||
| 99 | return None | ||
| 100 | |||
| 101 | import bb | ||
| 102 | fn = bb.data.expand(fn, data) | ||
| 103 | oldfn = bb.data.expand(oldfn, data) | ||
| 104 | |||
| 105 | from bb.parse import handle | ||
| 106 | try: | ||
| 107 | ret = handle(fn, data, True) | ||
| 108 | except IOError: | ||
| 109 | if error_out: | ||
| 110 | raise ParseError("Could not %(error_out)s file %(fn)s" % vars() ) | ||
| 111 | bb.msg.debug(2, bb.msg.domain.Parsing, "CONF file '%s' not found" % fn) | ||
| 112 | |||
| 113 | def handle(fn, data, include = 0): | ||
| 114 | if include: | ||
| 115 | inc_string = "including" | ||
| 116 | else: | ||
| 117 | inc_string = "reading" | ||
| 118 | init(data) | ||
| 119 | |||
| 120 | if include == 0: | ||
| 121 | bb.data.inheritFromOS(data) | ||
| 122 | oldfile = None | ||
| 123 | else: | ||
| 124 | oldfile = bb.data.getVar('FILE', data) | ||
| 125 | |||
| 126 | fn = obtain(fn, data) | ||
| 127 | if not os.path.isabs(fn): | ||
| 128 | f = None | ||
| 129 | bbpath = bb.data.getVar("BBPATH", data, 1) or [] | ||
| 130 | for p in bbpath.split(":"): | ||
| 131 | currname = os.path.join(p, fn) | ||
| 132 | if os.access(currname, os.R_OK): | ||
| 133 | f = open(currname, 'r') | ||
| 134 | abs_fn = currname | ||
| 135 | bb.msg.debug(2, bb.msg.domain.Parsing, "CONF %s %s" % (inc_string, currname)) | ||
| 136 | break | ||
| 137 | if f is None: | ||
| 138 | raise IOError("file '%s' not found" % fn) | ||
| 139 | else: | ||
| 140 | f = open(fn,'r') | ||
| 141 | bb.msg.debug(1, bb.msg.domain.Parsing, "CONF %s %s" % (inc_string,fn)) | ||
| 142 | abs_fn = fn | ||
| 143 | |||
| 144 | if include: | ||
| 145 | bb.parse.mark_dependency(data, abs_fn) | ||
| 146 | |||
| 147 | lineno = 0 | ||
| 148 | bb.data.setVar('FILE', fn, data) | ||
| 149 | while 1: | ||
| 150 | lineno = lineno + 1 | ||
| 151 | s = f.readline() | ||
| 152 | if not s: break | ||
| 153 | w = s.strip() | ||
| 154 | if not w: continue # skip empty lines | ||
| 155 | s = s.rstrip() | ||
| 156 | if s[0] == '#': continue # skip comments | ||
| 157 | while s[-1] == '\\': | ||
| 158 | s2 = f.readline()[:-1].strip() | ||
| 159 | lineno = lineno + 1 | ||
| 160 | s = s[:-1] + s2 | ||
| 161 | feeder(lineno, s, fn, data) | ||
| 162 | |||
| 163 | if oldfile: | ||
| 164 | bb.data.setVar('FILE', oldfile, data) | ||
| 165 | return data | ||
| 166 | |||
| 167 | def feeder(lineno, s, fn, data): | ||
| 168 | def getFunc(groupd, key, data): | ||
| 169 | if 'flag' in groupd and groupd['flag'] != None: | ||
| 170 | return bb.data.getVarFlag(key, groupd['flag'], data) | ||
| 171 | else: | ||
| 172 | return bb.data.getVar(key, data) | ||
| 173 | |||
| 174 | m = __config_regexp__.match(s) | ||
| 175 | if m: | ||
| 176 | groupd = m.groupdict() | ||
| 177 | key = groupd["var"] | ||
| 178 | if "exp" in groupd and groupd["exp"] != None: | ||
| 179 | bb.data.setVarFlag(key, "export", 1, data) | ||
| 180 | if "ques" in groupd and groupd["ques"] != None: | ||
| 181 | val = getFunc(groupd, key, data) | ||
| 182 | if val == None: | ||
| 183 | val = groupd["value"] | ||
| 184 | elif "colon" in groupd and groupd["colon"] != None: | ||
| 185 | e = data.createCopy() | ||
| 186 | bb.data.update_data(e) | ||
| 187 | val = bb.data.expand(groupd["value"], e) | ||
| 188 | elif "append" in groupd and groupd["append"] != None: | ||
| 189 | val = "%s %s" % ((getFunc(groupd, key, data) or ""), groupd["value"]) | ||
| 190 | elif "prepend" in groupd and groupd["prepend"] != None: | ||
| 191 | val = "%s %s" % (groupd["value"], (getFunc(groupd, key, data) or "")) | ||
| 192 | elif "postdot" in groupd and groupd["postdot"] != None: | ||
| 193 | val = "%s%s" % ((getFunc(groupd, key, data) or ""), groupd["value"]) | ||
| 194 | elif "predot" in groupd and groupd["predot"] != None: | ||
| 195 | val = "%s%s" % (groupd["value"], (getFunc(groupd, key, data) or "")) | ||
| 196 | else: | ||
| 197 | val = groupd["value"] | ||
| 198 | if 'flag' in groupd and groupd['flag'] != None: | ||
| 199 | bb.msg.debug(3, bb.msg.domain.Parsing, "setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val)) | ||
| 200 | bb.data.setVarFlag(key, groupd['flag'], val, data) | ||
| 201 | else: | ||
| 202 | bb.data.setVar(key, val, data) | ||
| 203 | return | ||
| 204 | |||
| 205 | m = __include_regexp__.match(s) | ||
| 206 | if m: | ||
| 207 | s = bb.data.expand(m.group(1), data) | ||
| 208 | bb.msg.debug(3, bb.msg.domain.Parsing, "CONF %s:%d: including %s" % (fn, lineno, s)) | ||
| 209 | include(fn, s, data, False) | ||
| 210 | return | ||
| 211 | |||
| 212 | m = __require_regexp__.match(s) | ||
| 213 | if m: | ||
| 214 | s = bb.data.expand(m.group(1), data) | ||
| 215 | include(fn, s, data, "include required") | ||
| 216 | return | ||
| 217 | |||
| 218 | m = __export_regexp__.match(s) | ||
| 219 | if m: | ||
| 220 | bb.data.setVarFlag(m.group(1), "export", 1, data) | ||
| 221 | return | ||
| 222 | |||
| 223 | raise ParseError("%s:%d: unparsed line: '%s'" % (fn, lineno, s)); | ||
| 224 | |||
| 225 | # Add us to the handlers list | ||
| 226 | from bb.parse import handlers | ||
| 227 | handlers.append({'supports': supports, 'handle': handle, 'init': init}) | ||
| 228 | del handlers | ||
diff --git a/bitbake-dev/lib/bb/parse/parse_py/__init__.py b/bitbake-dev/lib/bb/parse/parse_py/__init__.py new file mode 100644 index 0000000000..9e0e00adda --- /dev/null +++ b/bitbake-dev/lib/bb/parse/parse_py/__init__.py | |||
| @@ -0,0 +1,33 @@ | |||
| 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 | ||
