summaryrefslogtreecommitdiff
path: root/bitbake-dev/lib/bb/parse
diff options
context:
space:
mode:
authorRichard Purdie <richard@openedhand.com>2008-09-30 15:08:33 +0000
committerRichard Purdie <richard@openedhand.com>2008-09-30 15:08:33 +0000
commitc30eddb243e7e65f67f656e62848a033cf6f2e5c (patch)
tree110dd95788b76f55d31cb8d30aac2de8400b6f4a /bitbake-dev/lib/bb/parse
parent5ef0510474004eeb2ae8a99b64e2febb1920e077 (diff)
downloadopenembedded-core-c30eddb243e7e65f67f656e62848a033cf6f2e5c.tar.gz
openembedded-core-c30eddb243e7e65f67f656e62848a033cf6f2e5c.tar.bz2
openembedded-core-c30eddb243e7e65f67f656e62848a033cf6f2e5c.zip
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__.py80
-rw-r--r--bitbake-dev/lib/bb/parse/parse_py/BBHandler.py416
-rw-r--r--bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py228
-rw-r--r--bitbake-dev/lib/bb/parse/parse_py/__init__.py33
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 @@
+"""
+BitBake Parsers
+
+File parsers for the BitBake build tools.
+
+"""
+
+
+# Copyright (C) 2003, 2004 Chris Larson
+# Copyright (C) 2003, 2004 Phil Blundell
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Based on functions from the base bb module, Copyright 2003 Holger Schurig
+
+__all__ = [ 'ParseError', 'SkipPackage', 'cached_mtime', 'mark_dependency',
+ 'supports', 'handle', 'init' ]
+handlers = []
+
+import bb, os
+
+class ParseError(Exception):
+ """Exception raised when parsing fails"""
+
+class SkipPackage(Exception):
+ """Exception raised to skip this package"""
+
+__mtime_cache = {}
+def cached_mtime(f):
+ if not __mtime_cache.has_key(f):
+ __mtime_cache[f] = os.stat(f)[8]
+ return __mtime_cache[f]
+
+def cached_mtime_noerror(f):
+ if not __mtime_cache.has_key(f):
+ try:
+ __mtime_cache[f] = os.stat(f)[8]
+ except OSError:
+ return 0
+ return __mtime_cache[f]
+
+def mark_dependency(d, f):
+ if f.startswith('./'):
+ f = "%s/%s" % (os.getcwd(), f[2:])
+ deps = bb.data.getVar('__depends', d) or []
+ deps.append( (f, cached_mtime(f)) )
+ bb.data.setVar('__depends', deps, d)
+
+def supports(fn, data):
+ """Returns true if we have a handler for this file, false otherwise"""
+ for h in handlers:
+ if h['supports'](fn, data):
+ return 1
+ return 0
+
+def handle(fn, data, include = 0):
+ """Call the handler that is appropriate for this file"""
+ for h in handlers:
+ if h['supports'](fn, data):
+ return h['handle'](fn, data, include)
+ raise ParseError("%s is not a BitBake file" % fn)
+
+def init(fn, data):
+ for h in handlers:
+ if h['supports'](fn):
+ return h['init'](data)
+
+
+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 @@
+#!/usr/bin/env python
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+"""
+ class for handling .bb files
+
+ Reads a .bb file and obtains its metadata
+
+"""
+
+
+# Copyright (C) 2003, 2004 Chris Larson
+# Copyright (C) 2003, 2004 Phil Blundell
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import re, bb, os, sys, time
+import bb.fetch, bb.build, bb.utils
+from bb import data, fetch, methodpool
+
+from ConfHandler import include, localpath, obtain, init
+from bb.parse import ParseError
+
+__func_start_regexp__ = re.compile( r"(((?P<py>python)|(?P<fr>fakeroot))\s*)*(?P<func>[\w\.\-\+\{\}\$]+)?\s*\(\s*\)\s*{$" )
+__inherit_regexp__ = re.compile( r"inherit\s+(.+)" )
+__export_func_regexp__ = re.compile( r"EXPORT_FUNCTIONS\s+(.+)" )
+__addtask_regexp__ = re.compile("addtask\s+(?P<func>\w+)\s*((before\s*(?P<before>((.*(?=after))|(.*))))|(after\s*(?P<after>((.*(?=before))|(.*)))))*")
+__addhandler_regexp__ = re.compile( r"addhandler\s+(.+)" )
+__def_regexp__ = re.compile( r"def\s+(\w+).*:" )
+__python_func_regexp__ = re.compile( r"(\s+.*)|(^$)" )
+__word__ = re.compile(r"\S+")
+
+__infunc__ = ""
+__inpython__ = False
+__body__ = []
+__classname__ = ""
+classes = [ None, ]
+
+# We need to indicate EOF to the feeder. This code is so messy that
+# factoring it out to a close_parse_file method is out of question.
+# We will use the IN_PYTHON_EOF as an indicator to just close the method
+#
+# The two parts using it are tightly integrated anyway
+IN_PYTHON_EOF = -9999999999999
+
+__parsed_methods__ = methodpool.get_parsed_dict()
+
+def supports(fn, d):
+ localfn = localpath(fn, d)
+ return localfn[-3:] == ".bb" or localfn[-8:] == ".bbclass" or localfn[-4:] == ".inc"
+
+def inherit(files, d):
+ __inherit_cache = data.getVar('__inherit_cache', d) or []
+ fn = ""
+ lineno = 0
+ files = data.expand(files, d)
+ for file in files:
+ if file[0] != "/" and file[-8:] != ".bbclass":
+ file = os.path.join('classes', '%s.bbclass' % file)
+
+ if not file in __inherit_cache:
+ bb.msg.debug(2, bb.msg.domain.Parsing, "BB %s:%d: inheriting %s" % (fn, lineno, file))
+ __inherit_cache.append( file )
+ data.setVar('__inherit_cache', __inherit_cache, d)
+ include(fn, file, d, "inherit")
+ __inherit_cache = data.getVar('__inherit_cache', d) or []
+
+def handle(fn, d, include = 0):
+ global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __residue__
+ __body__ = []
+ __infunc__ = ""
+ __classname__ = ""
+ __residue__ = []
+
+ if include == 0:
+ bb.msg.debug(2, bb.msg.domain.Parsing, "BB " + fn + ": handle(data)")
+ else:
+ bb.msg.debug(2, bb.msg.domain.Parsing, "BB " + fn + ": handle(data, include)")
+
+ (root, ext) = os.path.splitext(os.path.basename(fn))
+ base_name = "%s%s" % (root,ext)
+ init(d)
+
+ if ext == ".bbclass":
+ __classname__ = root
+ classes.append(__classname__)
+ __inherit_cache = data.getVar('__inherit_cache', d) or []
+ if not fn in __inherit_cache:
+ __inherit_cache.append(fn)
+ data.setVar('__inherit_cache', __inherit_cache, d)
+
+ if include != 0:
+ oldfile = data.getVar('FILE', d)
+ else:
+ oldfile = None
+
+ fn = obtain(fn, d)
+ bbpath = (data.getVar('BBPATH', d, 1) or '').split(':')
+ if not os.path.isabs(fn):
+ f = None
+ for p in bbpath:
+ j = os.path.join(p, fn)
+ if os.access(j, os.R_OK):
+ abs_fn = j
+ f = open(j, 'r')
+ break
+ if f is None:
+ raise IOError("file %s not found" % fn)
+ else:
+ f = open(fn,'r')
+ abs_fn = fn
+
+ if ext != ".bbclass":
+ dname = os.path.dirname(abs_fn)
+ if dname not in bbpath:
+ bbpath.insert(0, dname)
+ data.setVar('BBPATH', ":".join(bbpath), d)
+
+ if include:
+ bb.parse.mark_dependency(d, abs_fn)
+
+ if ext != ".bbclass":
+ data.setVar('FILE', fn, d)
+
+ lineno = 0
+ while 1:
+ lineno = lineno + 1
+ s = f.readline()
+ if not s: break
+ s = s.rstrip()
+ feeder(lineno, s, fn, base_name, d)
+ if __inpython__:
+ # add a blank line to close out any python definition
+ feeder(IN_PYTHON_EOF, "", fn, base_name, d)
+ if ext == ".bbclass":
+ classes.remove(__classname__)
+ else:
+ if include == 0:
+ data.expandKeys(d)
+ data.update_data(d)
+ anonqueue = data.getVar("__anonqueue", d, 1) or []
+ body = [x['content'] for x in anonqueue]
+ flag = { 'python' : 1, 'func' : 1 }
+ data.setVar("__anonfunc", "\n".join(body), d)
+ data.setVarFlags("__anonfunc", flag, d)
+ from bb import build
+ try:
+ t = data.getVar('T', d)
+ data.setVar('T', '${TMPDIR}/anonfunc/', d)
+ build.exec_func("__anonfunc", d)
+ data.delVar('T', d)
+ if t:
+ data.setVar('T', t, d)
+ except Exception, e:
+ bb.msg.debug(1, bb.msg.domain.Parsing, "Exception when executing anonymous function: %s" % e)
+ raise
+ data.delVar("__anonqueue", d)
+ data.delVar("__anonfunc", d)
+ set_additional_vars(fn, d, include)
+ data.update_data(d)
+
+ all_handlers = {}
+ for var in data.getVar('__BBHANDLERS', d) or []:
+ # try to add the handler
+ handler = data.getVar(var,d)
+ bb.event.register(var, handler)
+
+ tasklist = data.getVar('__BBTASKS', d) or []
+ bb.build.add_tasks(tasklist, d)
+
+ bbpath.pop(0)
+ if oldfile:
+ bb.data.setVar("FILE", oldfile, d)
+
+ # we have parsed the bb class now
+ if ext == ".bbclass" or ext == ".inc":
+ __parsed_methods__[base_name] = 1
+
+ return d
+
+def feeder(lineno, s, fn, root, d):
+ global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, classes, bb, __residue__
+ if __infunc__:
+ if s == '}':
+ __body__.append('')
+ data.setVar(__infunc__, '\n'.join(__body__), d)
+ data.setVarFlag(__infunc__, "func", 1, d)
+ if __infunc__ == "__anonymous":
+ anonqueue = bb.data.getVar("__anonqueue", d) or []
+ anonitem = {}
+ anonitem["content"] = bb.data.getVar("__anonymous", d)
+ anonitem["flags"] = bb.data.getVarFlags("__anonymous", d)
+ anonqueue.append(anonitem)
+ bb.data.setVar("__anonqueue", anonqueue, d)
+ bb.data.delVarFlags("__anonymous", d)
+ bb.data.delVar("__anonymous", d)
+ __infunc__ = ""
+ __body__ = []
+ else:
+ __body__.append(s)
+ return
+
+ if __inpython__:
+ m = __python_func_regexp__.match(s)
+ if m and lineno != IN_PYTHON_EOF:
+ __body__.append(s)
+ return
+ else:
+ # Note we will add root to parsedmethods after having parse
+ # 'this' file. This means we will not parse methods from
+ # bb classes twice
+ if not root in __parsed_methods__:
+ text = '\n'.join(__body__)
+ methodpool.insert_method( root, text, fn )
+ funcs = data.getVar('__functions__', d) or {}
+ if not funcs.has_key( root ):
+ funcs[root] = text
+ else:
+ funcs[root] = "%s\n%s" % (funcs[root], text)
+
+ data.setVar('__functions__', funcs, d)
+ __body__ = []
+ __inpython__ = False
+
+ if lineno == IN_PYTHON_EOF:
+ return
+
+# fall through
+
+ if s == '' or s[0] == '#': return # skip comments and empty lines
+
+ if s[-1] == '\\':
+ __residue__.append(s[:-1])
+ return
+
+ s = "".join(__residue__) + s
+ __residue__ = []
+
+ m = __func_start_regexp__.match(s)
+ if m:
+ __infunc__ = m.group("func") or "__anonymous"
+ key = __infunc__
+ if data.getVar(key, d):
+# clean up old version of this piece of metadata, as its
+# flags could cause problems
+ data.setVarFlag(key, 'python', None, d)
+ data.setVarFlag(key, 'fakeroot', None, d)
+ if m.group("py") is not None:
+ data.setVarFlag(key, "python", "1", d)
+ else:
+ data.delVarFlag(key, "python", d)
+ if m.group("fr") is not None:
+ data.setVarFlag(key, "fakeroot", "1", d)
+ else:
+ data.delVarFlag(key, "fakeroot", d)
+ return
+
+ m = __def_regexp__.match(s)
+ if m:
+ __body__.append(s)
+ __inpython__ = True
+ return
+
+ m = __export_func_regexp__.match(s)
+ if m:
+ fns = m.group(1)
+ n = __word__.findall(fns)
+ for f in n:
+ allvars = []
+ allvars.append(f)
+ allvars.append(classes[-1] + "_" + f)
+
+ vars = [[ allvars[0], allvars[1] ]]
+ if len(classes) > 1 and classes[-2] is not None:
+ allvars.append(classes[-2] + "_" + f)
+ vars = []
+ vars.append([allvars[2], allvars[1]])
+ vars.append([allvars[0], allvars[2]])
+
+ for (var, calledvar) in vars:
+ if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d):
+ continue
+
+ if data.getVar(var, d):
+ data.setVarFlag(var, 'python', None, d)
+ data.setVarFlag(var, 'func', None, d)
+
+ for flag in [ "func", "python" ]:
+ if data.getVarFlag(calledvar, flag, d):
+ data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d)
+ for flag in [ "dirs" ]:
+ if data.getVarFlag(var, flag, d):
+ data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d)
+
+ if data.getVarFlag(calledvar, "python", d):
+ data.setVar(var, "\tbb.build.exec_func('" + calledvar + "', d)\n", d)
+ else:
+ data.setVar(var, "\t" + calledvar + "\n", d)
+ data.setVarFlag(var, 'export_func', '1', d)
+
+ return
+
+ m = __addtask_regexp__.match(s)
+ if m:
+ func = m.group("func")
+ before = m.group("before")
+ after = m.group("after")
+ if func is None:
+ return
+ var = "do_" + func
+
+ data.setVarFlag(var, "task", 1, d)
+
+ bbtasks = data.getVar('__BBTASKS', d) or []
+ if not var in bbtasks:
+ bbtasks.append(var)
+ data.setVar('__BBTASKS', bbtasks, d)
+
+ existing = data.getVarFlag(var, "deps", d) or []
+ if after is not None:
+ # set up deps for function
+ for entry in after.split():
+ if entry not in existing:
+ existing.append(entry)
+ data.setVarFlag(var, "deps", existing, d)
+ if before is not None:
+ # set up things that depend on this func
+ for entry in before.split():
+ existing = data.getVarFlag(entry, "deps", d) or []
+ if var not in existing:
+ data.setVarFlag(entry, "deps", [var] + existing, d)
+ return
+
+ m = __addhandler_regexp__.match(s)
+ if m:
+ fns = m.group(1)
+ hs = __word__.findall(fns)
+ bbhands = data.getVar('__BBHANDLERS', d) or []
+ for h in hs:
+ bbhands.append(h)
+ data.setVarFlag(h, "handler", 1, d)
+ data.setVar('__BBHANDLERS', bbhands, d)
+ return
+
+ m = __inherit_regexp__.match(s)
+ if m:
+
+ files = m.group(1)
+ n = __word__.findall(files)
+ inherit(n, d)
+ return
+
+ from bb.parse import ConfHandler
+ return ConfHandler.feeder(lineno, s, fn, d)
+
+__pkgsplit_cache__={}
+def vars_from_file(mypkg, d):
+ if not mypkg:
+ return (None, None, None)
+ if mypkg in __pkgsplit_cache__:
+ return __pkgsplit_cache__[mypkg]
+
+ myfile = os.path.splitext(os.path.basename(mypkg))
+ parts = myfile[0].split('_')
+ __pkgsplit_cache__[mypkg] = parts
+ if len(parts) > 3:
+ raise ParseError("Unable to generate default variables from the filename: %s (too many underscores)" % mypkg)
+ exp = 3 - len(parts)
+ tmplist = []
+ while exp != 0:
+ exp -= 1
+ tmplist.append(None)
+ parts.extend(tmplist)
+ return parts
+
+def set_additional_vars(file, d, include):
+ """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}"""
+
+ return
+ # Nothing seems to use this variable
+ #bb.msg.debug(2, bb.msg.domain.Parsing, "BB %s: set_additional_vars" % file)
+
+ #src_uri = data.getVar('SRC_URI', d, 1)
+ #if not src_uri:
+ # return
+
+ #a = (data.getVar('A', d, 1) or '').split()
+
+ #from bb import fetch
+ #try:
+ # ud = fetch.init(src_uri.split(), d)
+ # a += fetch.localpaths(d, ud)
+ #except fetch.NoMethodError:
+ # pass
+ #except bb.MalformedUrl,e:
+ # raise ParseError("Unable to generate local paths for SRC_URI due to malformed uri: %s" % e)
+ #del fetch
+
+ #data.setVar('A', " ".join(a), d)
+
+
+# Add us to the handlers list
+from bb.parse import handlers
+handlers.append({'supports': supports, 'handle': handle, 'init': init})
+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 @@
+#!/usr/bin/env python
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+"""
+ class for handling configuration data files
+
+ Reads a .conf file and obtains its metadata
+
+"""
+
+# Copyright (C) 2003, 2004 Chris Larson
+# Copyright (C) 2003, 2004 Phil Blundell
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import re, bb.data, os, sys
+from bb.parse import ParseError
+
+#__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)$")
+__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)$")
+__include_regexp__ = re.compile( r"include\s+(.+)" )
+__require_regexp__ = re.compile( r"require\s+(.+)" )
+__export_regexp__ = re.compile( r"export\s+(.+)" )
+
+def init(data):
+ if not bb.data.getVar('TOPDIR', data):
+ bb.data.setVar('TOPDIR', os.getcwd(), data)
+ if not bb.data.getVar('BBPATH', data):
+ bb.data.setVar('BBPATH', os.path.join(sys.prefix, 'share', 'bitbake'), data)
+
+def supports(fn, d):
+ return localpath(fn, d)[-5:] == ".conf"
+
+def localpath(fn, d):
+ if os.path.exists(fn):
+ return fn
+
+ if "://" not in fn:
+ return fn
+
+ localfn = None
+ try:
+ localfn = bb.fetch.localpath(fn, d, False)
+ except bb.MalformedUrl:
+ pass
+
+ if not localfn:
+ return fn
+ return localfn
+
+def obtain(fn, data):
+ import sys, bb
+ fn = bb.data.expand(fn, data)
+ localfn = bb.data.expand(localpath(fn, data), data)
+
+ if localfn != fn:
+ dldir = bb.data.getVar('DL_DIR', data, 1)
+ if not dldir:
+ bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: DL_DIR not defined")
+ return localfn
+ bb.mkdirhier(dldir)
+ try:
+ bb.fetch.init([fn], data)
+ except bb.fetch.NoMethodError:
+ (type, value, traceback) = sys.exc_info()
+ bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: no method: %s" % value)
+ return localfn
+
+ try:
+ bb.fetch.go(data)
+ except bb.fetch.MissingParameterError:
+ (type, value, traceback) = sys.exc_info()
+ bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: missing parameters: %s" % value)
+ return localfn
+ except bb.fetch.FetchError:
+ (type, value, traceback) = sys.exc_info()
+ bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: failed: %s" % value)
+ return localfn
+ return localfn
+
+
+def include(oldfn, fn, data, error_out):
+ """
+
+ error_out If True a ParseError will be reaised if the to be included
+ """
+ if oldfn == fn: # prevent infinate recursion
+ return None
+
+ import bb
+ fn = bb.data.expand(fn, data)
+ oldfn = bb.data.expand(oldfn, data)
+
+ from bb.parse import handle
+ try:
+ ret = handle(fn, data, True)
+ except IOError:
+ if error_out:
+ raise ParseError("Could not %(error_out)s file %(fn)s" % vars() )
+ bb.msg.debug(2, bb.msg.domain.Parsing, "CONF file '%s' not found" % fn)
+
+def handle(fn, data, include = 0):
+ if include:
+ inc_string = "including"
+ else:
+ inc_string = "reading"
+ init(data)
+
+ if include == 0:
+ bb.data.inheritFromOS(data)
+ oldfile = None
+ else:
+ oldfile = bb.data.getVar('FILE', data)
+
+ fn = obtain(fn, data)
+ if not os.path.isabs(fn):
+ f = None
+ bbpath = bb.data.getVar("BBPATH", data, 1) or []
+ for p in bbpath.split(":"):
+ currname = os.path.join(p, fn)
+ if os.access(currname, os.R_OK):
+ f = open(currname, 'r')
+ abs_fn = currname
+ bb.msg.debug(2, bb.msg.domain.Parsing, "CONF %s %s" % (inc_string, currname))
+ break
+ if f is None:
+ raise IOError("file '%s' not found" % fn)
+ else:
+ f = open(fn,'r')
+ bb.msg.debug(1, bb.msg.domain.Parsing, "CONF %s %s" % (inc_string,fn))
+ abs_fn = fn
+
+ if include:
+ bb.parse.mark_dependency(data, abs_fn)
+
+ lineno = 0
+ bb.data.setVar('FILE', fn, data)
+ while 1:
+ lineno = lineno + 1
+ s = f.readline()
+ if not s: break
+ w = s.strip()
+ if not w: continue # skip empty lines
+ s = s.rstrip()
+ if s[0] == '#': continue # skip comments
+ while s[-1] == '\\':
+ s2 = f.readline()[:-1].strip()
+ lineno = lineno + 1
+ s = s[:-1] + s2
+ feeder(lineno, s, fn, data)
+
+ if oldfile:
+ bb.data.setVar('FILE', oldfile, data)
+ return data
+
+def feeder(lineno, s, fn, data):
+ def getFunc(groupd, key, data):
+ if 'flag' in groupd and groupd['flag'] != None:
+ return bb.data.getVarFlag(key, groupd['flag'], data)
+ else:
+ return bb.data.getVar(key, data)
+
+ m = __config_regexp__.match(s)
+ if m:
+ groupd = m.groupdict()
+ key = groupd["var"]
+ if "exp" in groupd and groupd["exp"] != None:
+ bb.data.setVarFlag(key, "export", 1, data)
+ if "ques" in groupd and groupd["ques"] != None:
+ val = getFunc(groupd, key, data)
+ if val == None:
+ val = groupd["value"]
+ elif "colon" in groupd and groupd["colon"] != None:
+ e = data.createCopy()
+ bb.data.update_data(e)
+ val = bb.data.expand(groupd["value"], e)
+ elif "append" in groupd and groupd["append"] != None:
+ val = "%s %s" % ((getFunc(groupd, key, data) or ""), groupd["value"])
+ elif "prepend" in groupd and groupd["prepend"] != None:
+ val = "%s %s" % (groupd["value"], (getFunc(groupd, key, data) or ""))
+ elif "postdot" in groupd and groupd["postdot"] != None:
+ val = "%s%s" % ((getFunc(groupd, key, data) or ""), groupd["value"])
+ elif "predot" in groupd and groupd["predot"] != None:
+ val = "%s%s" % (groupd["value"], (getFunc(groupd, key, data) or ""))
+ else:
+ val = groupd["value"]
+ if 'flag' in groupd and groupd['flag'] != None:
+ bb.msg.debug(3, bb.msg.domain.Parsing, "setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val))
+ bb.data.setVarFlag(key, groupd['flag'], val, data)
+ else:
+ bb.data.setVar(key, val, data)
+ return
+
+ m = __include_regexp__.match(s)
+ if m:
+ s = bb.data.expand(m.group(1), data)
+ bb.msg.debug(3, bb.msg.domain.Parsing, "CONF %s:%d: including %s" % (fn, lineno, s))
+ include(fn, s, data, False)
+ return
+
+ m = __require_regexp__.match(s)
+ if m:
+ s = bb.data.expand(m.group(1), data)
+ include(fn, s, data, "include required")
+ return
+
+ m = __export_regexp__.match(s)
+ if m:
+ bb.data.setVarFlag(m.group(1), "export", 1, data)
+ return
+
+ raise ParseError("%s:%d: unparsed line: '%s'" % (fn, lineno, s));
+
+# Add us to the handlers list
+from bb.parse import handlers
+handlers.append({'supports': supports, 'handle': handle, 'init': init})
+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 @@
+#!/usr/bin/env python
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+"""
+BitBake Parsers
+
+File parsers for the BitBake build tools.
+
+"""
+
+# Copyright (C) 2003, 2004 Chris Larson
+# Copyright (C) 2003, 2004 Phil Blundell
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Based on functions from the base bb module, Copyright 2003 Holger Schurig
+__version__ = '1.0'
+
+__all__ = [ 'ConfHandler', 'BBHandler']
+
+import ConfHandler
+import BBHandler