diff options
author | Chris Larson <clarson@kergoth.com> | 2004-05-09 05:26:34 +0000 |
---|---|---|
committer | Chris Larson <clarson@kergoth.com> | 2004-05-09 05:26:34 +0000 |
commit | 9bc652e675c9f1d3e278bbcb9bf671bd50f4dac2 (patch) | |
tree | 4f4896faad757cfebf163b229f646863efda348f /bin/oe/parse | |
parent | 38cf5e2107120c31f87d788175b9af1b72de2fab (diff) | |
download | bitbake-9bc652e675c9f1d3e278bbcb9bf671bd50f4dac2.tar.gz |
Whitespace changes. Reformat things to better match the usual python indentation style, and add vim & emacs modelines to make it painless.
Diffstat (limited to 'bin/oe/parse')
-rw-r--r-- | bin/oe/parse/ConfHandler.py | 291 | ||||
-rw-r--r-- | bin/oe/parse/OEHandler.py | 603 | ||||
-rw-r--r-- | bin/oe/parse/SRPMHandler.py | 193 | ||||
-rw-r--r-- | bin/oe/parse/__init__.py | 55 |
4 files changed, 577 insertions, 565 deletions
diff --git a/bin/oe/parse/ConfHandler.py b/bin/oe/parse/ConfHandler.py index bed599470..0637d14df 100644 --- a/bin/oe/parse/ConfHandler.py +++ b/bin/oe/parse/ConfHandler.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """class for handling configuration data files Reads the file and obtains its metadata""" @@ -10,167 +13,167 @@ __config_regexp__ = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${} __include_regexp__ = re.compile( r"include\s+(.+)" ) def init(data): - if not oe.data.getVar('TOPDIR', data): - oe.data.setVar('TOPDIR', os.getcwd(), data) - if not oe.data.getVar('OEPATH', data): - oebuild = os.path.abspath(sys.argv[0]) - oebin = os.path.dirname(oebuild) - oedir = os.path.dirname(oebin) - oe.data.setVar('OEPATH', "${TOPDIR}:%s:%s:${HOME}/.oe:${OEDIR}/bin:${OEDIR}:%s/share/oe" % (oebin, oedir, sys.prefix), data) + if not oe.data.getVar('TOPDIR', data): + oe.data.setVar('TOPDIR', os.getcwd(), data) + if not oe.data.getVar('OEPATH', data): + oebuild = os.path.abspath(sys.argv[0]) + oebin = os.path.dirname(oebuild) + oedir = os.path.dirname(oebin) + oe.data.setVar('OEPATH', "${TOPDIR}:%s:%s:${HOME}/.oe:${OEDIR}/bin:${OEDIR}:%s/share/oe" % (oebin, oedir, sys.prefix), data) def supports(fn, d): - return localpath(fn, d)[-5:] == ".conf" + return localpath(fn, d)[-5:] == ".conf" def localpath(fn, d): - if os.path.exists(fn): - return fn + if os.path.exists(fn): + return fn - localfn = None - try: - localfn = oe.fetch.localpath(fn, d) - except oe.MalformedUrl: - pass + localfn = None + try: + localfn = oe.fetch.localpath(fn, d) + except oe.MalformedUrl: + pass - if not localfn: - localfn = fn - return localfn + if not localfn: + localfn = fn + return localfn def obtain(fn, data = {}): - import sys, oe - fn = oe.data.expand(fn, data) - localfn = oe.data.expand(localpath(fn, data), data) - - if localfn != fn: - dldir = oe.data.getVar('DL_DIR', data, 1) - if not dldir: - debug(1, "obtain: DL_DIR not defined") - return localfn - oe.mkdirhier(dldir) - try: - oe.fetch.init([fn]) - except oe.fetch.NoMethodError: - (type, value, traceback) = sys.exc_info() - debug(1, "obtain: no method: %s" % value) - return localfn - - try: - oe.fetch.go(data) - except oe.fetch.MissingParameterError: - (type, value, traceback) = sys.exc_info() - debug(1, "obtain: missing parameters: %s" % value) - return localfn - except oe.fetch.FetchError: - (type, value, traceback) = sys.exc_info() - debug(1, "obtain: failed: %s" % value) - return localfn - return localfn + import sys, oe + fn = oe.data.expand(fn, data) + localfn = oe.data.expand(localpath(fn, data), data) + + if localfn != fn: + dldir = oe.data.getVar('DL_DIR', data, 1) + if not dldir: + debug(1, "obtain: DL_DIR not defined") + return localfn + oe.mkdirhier(dldir) + try: + oe.fetch.init([fn]) + except oe.fetch.NoMethodError: + (type, value, traceback) = sys.exc_info() + debug(1, "obtain: no method: %s" % value) + return localfn + + try: + oe.fetch.go(data) + except oe.fetch.MissingParameterError: + (type, value, traceback) = sys.exc_info() + debug(1, "obtain: missing parameters: %s" % value) + return localfn + except oe.fetch.FetchError: + (type, value, traceback) = sys.exc_info() + debug(1, "obtain: failed: %s" % value) + return localfn + return localfn def include(oldfn, fn, data = {}): - if oldfn == fn: # prevent infinate recursion - return None + if oldfn == fn: # prevent infinate recursion + return None - import oe - fn = oe.data.expand(fn, data) - oldfn = oe.data.expand(oldfn, data) + import oe + fn = oe.data.expand(fn, data) + oldfn = oe.data.expand(oldfn, data) - from oe.parse import handle - try: - ret = handle(fn, data, 1) - except IOError: - debug(2, "CONF file '%s' not found" % fn) + from oe.parse import handle + try: + ret = handle(fn, data, 1) + except IOError: + debug(2, "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: - oe.data.inheritFromOS(data) - oldfile = None - else: - oldfile = oe.data.getVar('FILE', data) - - fn = obtain(fn, data) - oepath = ['.'] - if not os.path.isabs(fn): - f = None - voepath = oe.data.getVar("OEPATH", data) - if voepath: - oepath += voepath.split(":") - for p in oepath: - currname = os.path.join(oe.data.expand(p, data), fn) - if os.access(currname, os.R_OK): - f = open(currname, 'r') - abs_fn = currname - debug(1, "CONF %s %s" % (inc_string, currname)) - break - if f is None: - raise IOError("file not found") - else: - f = open(fn,'r') - debug(1, "CONF %s %s" % (inc_string,fn)) - abs_fn = fn - - if include: - oe.parse.mark_dependency(data, abs_fn) - - lineno = 0 - oe.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: - oe.data.setVar('FILE', oldfile, data) - return data + if include: + inc_string = "including" + else: + inc_string = "reading" + init(data) + + if include == 0: + oe.data.inheritFromOS(data) + oldfile = None + else: + oldfile = oe.data.getVar('FILE', data) + + fn = obtain(fn, data) + oepath = ['.'] + if not os.path.isabs(fn): + f = None + voepath = oe.data.getVar("OEPATH", data) + if voepath: + oepath += voepath.split(":") + for p in oepath: + currname = os.path.join(oe.data.expand(p, data), fn) + if os.access(currname, os.R_OK): + f = open(currname, 'r') + abs_fn = currname + debug(1, "CONF %s %s" % (inc_string, currname)) + break + if f is None: + raise IOError("file not found") + else: + f = open(fn,'r') + debug(1, "CONF %s %s" % (inc_string,fn)) + abs_fn = fn + + if include: + oe.parse.mark_dependency(data, abs_fn) + + lineno = 0 + oe.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: + oe.data.setVar('FILE', oldfile, data) + return data def feeder(lineno, s, fn, data = {}): - m = __config_regexp__.match(s) - if m: - groupd = m.groupdict() - key = groupd["var"] - if "exp" in groupd and groupd["exp"] != None: - oe.data.setVarFlag(key, "export", 1, data) - if "ques" in groupd and groupd["ques"] != None: - val = oe.data.getVar(key, data) - if not val: - val = groupd["value"] - elif "colon" in groupd and groupd["colon"] != None: - val = oe.data.expand(groupd["value"], data) - elif "append" in groupd and groupd["append"] != None: - val = (oe.data.getVar(key, data) or "") + groupd["value"] - elif "prepend" in groupd and groupd["prepend"] != None: - val = groupd["value"] + (oe.data.getVar(key, data) or "") - else: - val = groupd["value"] - if 'flag' in groupd and groupd['flag'] != None: - #oe.note("setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val)) - oe.data.setVarFlag(key, groupd['flag'], val, data) - else: - oe.data.setVar(key, val, data) - return - - m = __include_regexp__.match(s) - if m: - s = oe.data.expand(m.group(1), data) - #debug(2, "CONF %s:%d: including %s" % (fn, lineno, s)) - include(fn, s, data) - return - - raise ParseError("%s:%d: unparsed line" % (fn, lineno)); + m = __config_regexp__.match(s) + if m: + groupd = m.groupdict() + key = groupd["var"] + if "exp" in groupd and groupd["exp"] != None: + oe.data.setVarFlag(key, "export", 1, data) + if "ques" in groupd and groupd["ques"] != None: + val = oe.data.getVar(key, data) + if not val: + val = groupd["value"] + elif "colon" in groupd and groupd["colon"] != None: + val = oe.data.expand(groupd["value"], data) + elif "append" in groupd and groupd["append"] != None: + val = (oe.data.getVar(key, data) or "") + groupd["value"] + elif "prepend" in groupd and groupd["prepend"] != None: + val = groupd["value"] + (oe.data.getVar(key, data) or "") + else: + val = groupd["value"] + if 'flag' in groupd and groupd['flag'] != None: +# oe.note("setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val)) + oe.data.setVarFlag(key, groupd['flag'], val, data) + else: + oe.data.setVar(key, val, data) + return + + m = __include_regexp__.match(s) + if m: + s = oe.data.expand(m.group(1), data) +# debug(2, "CONF %s:%d: including %s" % (fn, lineno, s)) + include(fn, s, data) + return + + raise ParseError("%s:%d: unparsed line" % (fn, lineno)); # Add us to the handlers list from oe.parse import handlers diff --git a/bin/oe/parse/OEHandler.py b/bin/oe/parse/OEHandler.py index 9eb181e3c..63075e8a2 100644 --- a/bin/oe/parse/OEHandler.py +++ b/bin/oe/parse/OEHandler.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """class for handling .oe files Reads the file and obtains its metadata""" @@ -13,7 +16,7 @@ __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+.*:" ) +__def_regexp__ = re.compile( r"def\s+.*:" ) __python_func_regexp__ = re.compile( r"\s+.*" ) __word__ = re.compile(r"\S+") @@ -25,318 +28,318 @@ __classname__ = "" classes = [ None, ] def supports(fn, d): - localfn = localpath(fn, d) - return localfn[-3:] == ".oe" or localfn[-8:] == ".oeclass" + localfn = localpath(fn, d) + return localfn[-3:] == ".oe" or localfn[-8:] == ".oeclass" def inherit(files, d): - __inherit_cache = data.getVar('__inherit_cache', d) or "" - fn = "" - lineno = 0 - for f in files: - file = data.expand(f, d) - if file[0] != "/" and file[-8:] != ".oeclass": - file = "classes/%s.oeclass" % file + __inherit_cache = data.getVar('__inherit_cache', d) or "" + fn = "" + lineno = 0 + for f in files: + file = data.expand(f, d) + if file[0] != "/" and file[-8:] != ".oeclass": + file = "classes/%s.oeclass" % file - if not file in __inherit_cache.split(): - debug(2, "OE %s:%d: inheriting %s" % (fn, lineno, file)) - __inherit_cache += " %s" % file - include(fn, file, d) - data.setVar('__inherit_cache', __inherit_cache, d) + if not file in __inherit_cache.split(): + debug(2, "OE %s:%d: inheriting %s" % (fn, lineno, file)) + __inherit_cache += " %s" % file + include(fn, file, d) + data.setVar('__inherit_cache', __inherit_cache, d) def handle(fn, d = {}, include = 0): - global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __oepath_found__ - __body__ = [] - __oepath_found__ = 0 - __infunc__ = "" - __classname__ = "" - - if include == 0: - debug(2, "OE " + fn + ": handle(data)") - else: - debug(2, "OE " + fn + ": handle(data, include)") - - (root, ext) = os.path.splitext(os.path.basename(fn)) - init(d) - - if ext == ".oeclass": - __classname__ = root - classes.append(__classname__) - - if include != 0: - oldfile = data.getVar('FILE', d) - else: - oldfile = None - - fn = obtain(fn, d) - oepath = ['.'] - if not os.path.isabs(fn): - f = None - voepath = data.getVar("OEPATH", d) - if voepath: - oepath += voepath.split(":") - for p in oepath: - p = data.expand(p, d) - 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 not found") - else: - f = open(fn,'r') - abs_fn = fn - - if include: - oe.parse.mark_dependency(d, abs_fn) - - if ext != ".oeclass": - data.setVar('FILE', fn, d) - i = (data.getVar("INHERIT", d, 1) or "").split() - if not "base" in i and __classname__ != "base": - i[0:0] = ["base"] - inherit(i, d) - - lineno = 0 - 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() - while s[-1] == '\\': - s2 = f.readline()[:-1].strip() - s = s[:-1] + s2 - feeder(lineno, s, fn, d) - if ext == ".oeclass": - classes.remove(__classname__) - else: - if include == 0: - data.expandKeys(d) - data.update_data(d) - set_additional_vars(fn, d, include) - anonqueue = data.getVar("__anonqueue", d, 1) or [] - for anon in anonqueue: - data.setVar("__anonfunc", anon["content"], d) - data.setVarFlags("__anonfunc", anon["flags"], d) - from oe import build - try: - t = data.getVar('T', d) - data.setVar('T', '${TMPDIR}/', d) - build.exec_func("__anonfunc", d) - data.delVar('T', d) - if t: - data.setVar('T', t, d) - except Exception, e: - oe.debug(1, "executing anonymous function: %s" % e) - raise - data.delVar("__anonqueue", d) - data.delVar("__anonfunc", d) - - for var in d.keys(): - if data.getVarFlag(var, 'handler', d): - oe.event.register(data.getVar(var, d)) - continue - - if not data.getVarFlag(var, 'task', d): - continue - - deps = data.getVarFlag(var, 'deps', d) or [] - postdeps = data.getVarFlag(var, 'postdeps', d) or [] - oe.build.add_task(var, deps, d) - for p in postdeps: - pdeps = data.getVarFlag(p, 'deps', d) or [] - pdeps.append(var) - data.setVarFlag(p, 'deps', pdeps, d) - oe.build.add_task(p, pdeps, d) - if oldfile: - oe.data.setVar("FILE", oldfile, d) - return d + global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __oepath_found__ + __body__ = [] + __oepath_found__ = 0 + __infunc__ = "" + __classname__ = "" + + if include == 0: + debug(2, "OE " + fn + ": handle(data)") + else: + debug(2, "OE " + fn + ": handle(data, include)") + + (root, ext) = os.path.splitext(os.path.basename(fn)) + init(d) + + if ext == ".oeclass": + __classname__ = root + classes.append(__classname__) + + if include != 0: + oldfile = data.getVar('FILE', d) + else: + oldfile = None + + fn = obtain(fn, d) + oepath = ['.'] + if not os.path.isabs(fn): + f = None + voepath = data.getVar("OEPATH", d) + if voepath: + oepath += voepath.split(":") + for p in oepath: + p = data.expand(p, d) + 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 not found") + else: + f = open(fn,'r') + abs_fn = fn + + if include: + oe.parse.mark_dependency(d, abs_fn) + + if ext != ".oeclass": + data.setVar('FILE', fn, d) + i = (data.getVar("INHERIT", d, 1) or "").split() + if not "base" in i and __classname__ != "base": + i[0:0] = ["base"] + inherit(i, d) + + lineno = 0 + 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() + while s[-1] == '\\': + s2 = f.readline()[:-1].strip() + s = s[:-1] + s2 + feeder(lineno, s, fn, d) + if ext == ".oeclass": + classes.remove(__classname__) + else: + if include == 0: + data.expandKeys(d) + data.update_data(d) + set_additional_vars(fn, d, include) + anonqueue = data.getVar("__anonqueue", d, 1) or [] + for anon in anonqueue: + data.setVar("__anonfunc", anon["content"], d) + data.setVarFlags("__anonfunc", anon["flags"], d) + from oe import build + try: + t = data.getVar('T', d) + data.setVar('T', '${TMPDIR}/', d) + build.exec_func("__anonfunc", d) + data.delVar('T', d) + if t: + data.setVar('T', t, d) + except Exception, e: + oe.debug(1, "executing anonymous function: %s" % e) + raise + data.delVar("__anonqueue", d) + data.delVar("__anonfunc", d) + + for var in d.keys(): + if data.getVarFlag(var, 'handler', d): + oe.event.register(data.getVar(var, d)) + continue + + if not data.getVarFlag(var, 'task', d): + continue + + deps = data.getVarFlag(var, 'deps', d) or [] + postdeps = data.getVarFlag(var, 'postdeps', d) or [] + oe.build.add_task(var, deps, d) + for p in postdeps: + pdeps = data.getVarFlag(p, 'deps', d) or [] + pdeps.append(var) + data.setVarFlag(p, 'deps', pdeps, d) + oe.build.add_task(p, pdeps, d) + if oldfile: + oe.data.setVar("FILE", oldfile, d) + return d def feeder(lineno, s, fn, d): - global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, __oepath_found__, classes, oe - if __infunc__: - if s == '}': - __body__.append('') - data.setVar(__infunc__, '\n'.join(__body__), d) - data.setVarFlag(__infunc__, "func", 1, d) - if __infunc__ == "__anonymous": - anonqueue = oe.data.getVar("__anonqueue", d) or [] - anonitem = {} - anonitem["content"] = oe.data.getVar("__anonymous", d) - anonitem["flags"] = oe.data.getVarFlags("__anonymous", d) - anonqueue.append(anonitem) - oe.data.setVar("__anonqueue", anonqueue, d) - oe.data.delVarFlags("__anonymous", d) - oe.data.delVar("__anonymous", d) - __infunc__ = "" - __body__ = [] - else: - __body__.append(s) - return - - if __inpython__: - m = __python_func_regexp__.match(s) - if m: - __body__.append(s) - return - else: - text = '\n'.join(__body__) - comp = compile(text, "<oe>", "exec") - exec comp in __builtins__ - __body__ = [] - __inpython__ = False - # fall through - - if s[0] == '#': return # skip comments - - 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, "\treturn oe.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) - - if after is not None: - # set up deps for function - data.setVarFlag(var, "deps", after.split(), d) - if before is not None: - # set up things that depend on this func - data.setVarFlag(var, "postdeps", before.split(), d) - return - - m = __addhandler_regexp__.match(s) - if m: - fns = m.group(1) - hs = __word__.findall(fns) - for h in hs: - data.setVarFlag(h, "handler", 1, d) - return - - m = __inherit_regexp__.match(s) - if m: - - files = m.group(1) - n = __word__.findall(files) - inherit(n, d) - return - - from oe.parse import ConfHandler - return ConfHandler.feeder(lineno, s, fn, d) + global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, __oepath_found__, classes, oe + if __infunc__: + if s == '}': + __body__.append('') + data.setVar(__infunc__, '\n'.join(__body__), d) + data.setVarFlag(__infunc__, "func", 1, d) + if __infunc__ == "__anonymous": + anonqueue = oe.data.getVar("__anonqueue", d) or [] + anonitem = {} + anonitem["content"] = oe.data.getVar("__anonymous", d) + anonitem["flags"] = oe.data.getVarFlags("__anonymous", d) + anonqueue.append(anonitem) + oe.data.setVar("__anonqueue", anonqueue, d) + oe.data.delVarFlags("__anonymous", d) + oe.data.delVar("__anonymous", d) + __infunc__ = "" + __body__ = [] + else: + __body__.append(s) + return + + if __inpython__: + m = __python_func_regexp__.match(s) + if m: + __body__.append(s) + return + else: + text = '\n'.join(__body__) + comp = compile(text, "<oe>", "exec") + exec comp in __builtins__ + __body__ = [] + __inpython__ = False +# fall through + + if s[0] == '#': return # skip comments + + 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, "\treturn oe.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) + + if after is not None: +# set up deps for function + data.setVarFlag(var, "deps", after.split(), d) + if before is not None: +# set up things that depend on this func + data.setVarFlag(var, "postdeps", before.split(), d) + return + + m = __addhandler_regexp__.match(s) + if m: + fns = m.group(1) + hs = __word__.findall(fns) + for h in hs: + data.setVarFlag(h, "handler", 1, d) + return + + m = __inherit_regexp__.match(s) + if m: + + files = m.group(1) + n = __word__.findall(files) + inherit(n, d) + return + + from oe.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 - exp = 3 - len(parts) - tmplist = [] - while exp != 0: - exp -= 1 - tmplist.append(None) - parts.extend(tmplist) - return parts + 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 + 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}""" - - debug(2,"OE %s: set_additional_vars" % file) - - src_uri = data.getVar('SRC_URI', d) - if not src_uri: - return - src_uri = data.expand(src_uri, d) - - a = data.getVar('A', d) - if a: - a = data.expand(a, d).split() - else: - a = [] - - from oe import fetch - try: - fetch.init(src_uri.split()) - except fetch.NoMethodError: - pass - - a += fetch.localpaths(d) - del fetch - data.setVar('A', "".join(a), d) + """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}""" + + debug(2,"OE %s: set_additional_vars" % file) + + src_uri = data.getVar('SRC_URI', d) + if not src_uri: + return + src_uri = data.expand(src_uri, d) + + a = data.getVar('A', d) + if a: + a = data.expand(a, d).split() + else: + a = [] + + from oe import fetch + try: + fetch.init(src_uri.split()) + except fetch.NoMethodError: + pass + + a += fetch.localpaths(d) + del fetch + data.setVar('A', "".join(a), d) # Add us to the handlers list diff --git a/bin/oe/parse/SRPMHandler.py b/bin/oe/parse/SRPMHandler.py index 596ad727f..2864f673f 100644 --- a/bin/oe/parse/SRPMHandler.py +++ b/bin/oe/parse/SRPMHandler.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """class for handling .src.rpm files Accesses the file and obtains its metadata""" @@ -14,107 +17,107 @@ _srpm_vartranslate = { } def supports(fn, d): - return fn[-8:] == ".src.rpm" + return fn[-8:] == ".src.rpm" def handle(fn, d = {}, include = 0): - init(d) - oepath = ['.'] - if not os.path.isabs(fn): - f = None - voepath = data.getVar("OEPATH", d) - if voepath: - oepath += voepath.split(":") - for p in oepath: - p = data.expand(p, d) - if os.access(os.path.join(p, fn), os.R_OK): - f = open(os.path.join(p, fn), 'r') - if f is None: - raise IOError("file not found") - else: - f = open(fn,'r') - - srpm_vars = os.popen('rpm --querytags').read().split('\n') - for v in srpm_vars: - if v in _srpm_vartranslate: - var = _srpm_vartranslate[v] - else: - var = v - querycmd = 'rpm -qp --qf \'%%{%s}\' %s 2>/dev/null' % (v, fn) - value = os.popen(querycmd).read().strip() - if value == "(none)": - value = None - if value: - data.setVar(var, value, d) - - data.setVar("SRPMFILE", fn, d) - - inheritclasses = data.getVar("INHERIT", d) - if inheritclasses: - i = inheritclasses.split() - else: - i = [] - - if not "base_srpm" in i: - i[0:0] = ["base_srpm"] - - for c in i: - oe.parse.handle('classes/%s.oeclass' % c, d) - - set_automatic_vars(fn, d, include) - set_additional_vars(fn, d, include) - data.update_data(d) - return d + init(d) + oepath = ['.'] + if not os.path.isabs(fn): + f = None + voepath = data.getVar("OEPATH", d) + if voepath: + oepath += voepath.split(":") + for p in oepath: + p = data.expand(p, d) + if os.access(os.path.join(p, fn), os.R_OK): + f = open(os.path.join(p, fn), 'r') + if f is None: + raise IOError("file not found") + else: + f = open(fn,'r') + + srpm_vars = os.popen('rpm --querytags').read().split('\n') + for v in srpm_vars: + if v in _srpm_vartranslate: + var = _srpm_vartranslate[v] + else: + var = v + querycmd = 'rpm -qp --qf \'%%{%s}\' %s 2>/dev/null' % (v, fn) + value = os.popen(querycmd).read().strip() + if value == "(none)": + value = None + if value: + data.setVar(var, value, d) + + data.setVar("SRPMFILE", fn, d) + + inheritclasses = data.getVar("INHERIT", d) + if inheritclasses: + i = inheritclasses.split() + else: + i = [] + + if not "base_srpm" in i: + i[0:0] = ["base_srpm"] + + for c in i: + oe.parse.handle('classes/%s.oeclass' % c, d) + + set_automatic_vars(fn, d, include) + set_additional_vars(fn, d, include) + data.update_data(d) + return d def set_automatic_vars(file, d, include): - """Deduce per-package environment variables""" - - debug(2, "setting automatic vars") - - data.setVar('CATEGORY', 'srpm', d) - data.setVar('P', '${PN}-${PV}', d) - data.setVar('PF', '${P}-${PR}', d) - - for s in ['${TOPDIR}/${CATEGORY}/${PF}', - '${TOPDIR}/${CATEGORY}/${PN}-${PV}', - '${TOPDIR}/${CATEGORY}/files', - '${TOPDIR}/${CATEGORY}']: - s = data.expand(s, d) - if os.access(s, os.R_OK): - data.setVar('FILESDIR', s, d) - break - - data.setVar('WORKDIR', '${TMPDIR}/${CATEGORY}/${PF}', d) - data.setVar('T', '${WORKDIR}/temp', d) - data.setVar('D', '${WORKDIR}/image', d) - if not data.getVar('S', d): - data.setVar('S', '${WORKDIR}/${P}', d) - data.setVar('SLOT', '0', d) + """Deduce per-package environment variables""" + + debug(2, "setting automatic vars") + + data.setVar('CATEGORY', 'srpm', d) + data.setVar('P', '${PN}-${PV}', d) + data.setVar('PF', '${P}-${PR}', d) + + for s in ['${TOPDIR}/${CATEGORY}/${PF}', + '${TOPDIR}/${CATEGORY}/${PN}-${PV}', + '${TOPDIR}/${CATEGORY}/files', + '${TOPDIR}/${CATEGORY}']: + s = data.expand(s, d) + if os.access(s, os.R_OK): + data.setVar('FILESDIR', s, d) + break + + data.setVar('WORKDIR', '${TMPDIR}/${CATEGORY}/${PF}', d) + data.setVar('T', '${WORKDIR}/temp', d) + data.setVar('D', '${WORKDIR}/image', d) + if not data.getVar('S', d): + data.setVar('S', '${WORKDIR}/${P}', d) + data.setVar('SLOT', '0', d) def set_additional_vars(file, d, include): - """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}""" - - debug(2,"set_additional_vars") - - src_uri = data.getVar('SRC_URI', d) - if not src_uri: - return - src_uri = data.expand(src_uri, d) - - a = data.getVar('A', d) - if a: - a = data.expand(a, d).split() - else: - a = [] - - from oe import fetch - try: - fetch.init(src_uri.split()) - except fetch.NoMethodError: - pass - - a += fetch.localpaths(d) - del fetch - data.setVar('A', ''.join(a), d) + """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}""" + + debug(2,"set_additional_vars") + + src_uri = data.getVar('SRC_URI', d) + if not src_uri: + return + src_uri = data.expand(src_uri, d) + + a = data.getVar('A', d) + if a: + a = data.expand(a, d).split() + else: + a = [] + + from oe import fetch + try: + fetch.init(src_uri.split()) + except fetch.NoMethodError: + pass + + a += fetch.localpaths(d) + del fetch + data.setVar('A', ''.join(a), d) # Add us to the handlers list diff --git a/bin/oe/parse/__init__.py b/bin/oe/parse/__init__.py index e147b8ffd..c4f0cb02e 100644 --- a/bin/oe/parse/__init__.py +++ b/bin/oe/parse/__init__.py @@ -1,7 +1,10 @@ +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """ OpenEmbedded Parsers -File parsers for the OpenEmbedded +File parsers for the OpenEmbedded (http://openembedded.org) build infrastructure. Copyright: (c) 2003 Chris Larson @@ -14,10 +17,10 @@ __all__ = [ 'handlers', 'supports', 'handle', 'init', 'ConfHandler', 'OEHandler' handlers = [] class ParseError(Exception): - """Exception raised when parsing fails""" + """Exception raised when parsing fails""" class SkipPackage(Exception): - """Exception raised to skip this package""" + """Exception raised to skip this package""" import ConfHandler ConfHandler.ParseError = ParseError @@ -29,34 +32,34 @@ SRPMHandler.ParseError = ParseError __mtime_cache = {} def cached_mtime(f): - import os - if not __mtime_cache.has_key(f): - __mtime_cache[f] = os.stat(f)[8] - return __mtime_cache[f] + import os + if not __mtime_cache.has_key(f): + __mtime_cache[f] = os.stat(f)[8] + return __mtime_cache[f] def mark_dependency(d, f): - import oe, os - if f.startswith('./'): - f = "%s/%s" % (os.getcwd(), f[2:]) - deps = (oe.data.getVar('__depends', d) or "").split() - deps.append("%s@%s" % (f, cached_mtime(f))) - oe.data.setVar('__depends', " ".join(deps), d) + import oe, os + if f.startswith('./'): + f = "%s/%s" % (os.getcwd(), f[2:]) + deps = (oe.data.getVar('__depends', d) or "").split() + deps.append("%s@%s" % (f, cached_mtime(f))) + oe.data.setVar('__depends', " ".join(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 + """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) - return None + """Call the handler that is appropriate for this file""" + for h in handlers: + if h['supports'](fn, data): + return h['handle'](fn, data, include) + return None def init(fn, data): - for h in handlers: - if h['supports'](fn): - return h['init'](data) + for h in handlers: + if h['supports'](fn): + return h['init'](data) |