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) if not os.path.isabs(fn): dname = os.path.dirname(oldfn) bbpath = "%s:%s" % (dname, bb.data.getVar("BBPATH", data, 1)) abs_fn = bb.which(bbpath, fn) if abs_fn: fn = abs_fn 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 fetch_uri(uri, basename, dl, md5, d): if os.path.exists(dl): # file exists, but we didnt complete it.. trying again.. fetchcmd = bb.data.getVar("RESUMECOMMAND", d, 1) else: fetchcmd = bb.data.getVar("FETCHCOMMAND", d, 1) bb.note("fetch " + uri) fetchcmd = fetchcmd.replace("${URI}", uri) fetchcmd = fetchcmd.replace("${FILE}", basename) bb.debug(2, "executing " + fetchcmd) ret = os.system(fetchcmd) if ret != 0: return False # supposedly complete.. write out md5sum if bb.which(bb.data.getVar("PATH", d), "md5sum"): try: md5pipe = os.popen("md5sum " + dl) md5data = (md5pipe.readline().split() or [""])[0] md5pipe.close() except OSError: md5data = "" md5out = file(md5, "w") md5out.write(md5data) md5out.close() else: md5out = file(md5, "w") md5out.write("") md5out.close() return True
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) if not os.path.isabs(fn): dname = os.path.dirname(oldfn) bbpath = "%s:%s" % (dname, bb.data.getVar("BBPATH", data, 1)) abs_fn = bb.which(bbpath, fn) if abs_fn: fn = abs_fn 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 resolve_file(fn, d): if not os.path.isabs(fn): bbpath = bb.data.getVar("BBPATH", d, True) newfn = bb.which(bbpath, fn) if not newfn: raise IOError("file %s not found in %s" % (fn, bbpath)) fn = newfn logger.debug(2, "LOAD %s", fn) return fn
def resolve_file(fn, d): if not os.path.isabs(fn): bbpath = bb.data.getVar("BBPATH", d, True) newfn = bb.which(bbpath, fn) if not newfn: raise IOError("file %s not found in %s" % (fn, bbpath)) fn = newfn bb.msg.debug(2, bb.msg.domain.Parsing, "LOAD %s" % fn) return fn
def main(): cache = nodecache.NodeCache(bitbakec.parsefile) # Read the Configuration my_init = bb.data.init() bb.data.inheritFromOS(my_init) my_init.setVar('TOPDIR', os.getcwd() ) conf = bitbakec.parsefile(bb.which(os.environ['BBPATH'], "conf/bitbake.conf"), True) conf.eval( my_init, cache ) # micro optimisation INHERIT the bases once... import ast root = ast.Root("none") inherits = (my_init.getVar('INHERIT', True) or "").split() inherits.insert(0, "base") for inherit in inherits: print "Inheriting %s" % inherit root.add_statement( ast.Inherit( inherit ) ) root.eval( my_init, cache ) cache.base_classes = root.classes cache.task_base = root.tasks cache.queue_base = root.anonqueue print cache.base_classes print root.handler add_handler( root, my_init ) #sys.exit(-1) # Initialize the fetcher stuff def set_additional_vars(the_data): """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}""" src_uri = bb.data.getVar('SRC_URI', the_data) if not src_uri: return src_uri = bb.data.expand(src_uri, the_data) a = bb.data.getVar('A', the_data) if a: a = bb.data.expand(a, the_data).split() else: a = [] from bb import fetch try: fetch.init(src_uri.split(), the_data) except fetch.NoMethodError: pass except bb.MalformedUrl,e: raise bb.parse.ParseError("Unable to generate local paths for SRC_URI due to malformed uri: %s" % e) a += fetch.localpaths(the_data) del fetch bb.data.setVar('A', " ".join(a), the_data)
def visitRequire(self, data, nodecache): node.get_direct_root().expand( data, nodecache ) bbpath = os.environ['BBPATH'] if node.has_root(): bbpath = "%s:%s" % (os.path.dirname(node.root.filename), bbpath) require = bb.which(bbpath, data.expand(node.file, None)) #print "Require", node.file, require, node.root.filename ast = nodecache.parse_include(require) root = EvaluateRoot(self) root.accept( ast, data, nodecache ) bb.parse.mark_dependency(data, require)
def localpath(url, d): """Return the local filename of a given url assuming a successful fetch. """ path = url.split("://")[1] newpath = path if path[0] != "/": filespath = bb.data.getVar("FILESPATH", d, 1) if filespath: newpath = bb.which(filespath, path) if not newpath: filesdir = bb.data.getVar("FILESDIR", d, 1) if filesdir: newpath = os.path.join(filesdir, path) return newpath
def visitInherit(self, node, data, nodecache): self.master.expand( data, nodecache ) if node.file in self.classes or node.file in nodecache.base_classes: return node.get_direct_root().classes[node.file] = 1 inherit = data.expand(node.file, None) # Remember what we inherites ast = nodecache.parse_class( node.file, bb.which(os.environ['BBPATH'], "classes/%s.bbclass" % node.file ) ) ast.root = node.root root = EvaluateRoot(self) root.accept( ast, data, nodecache )
def localpath(self, url, urldata, d): """Return the local filename of a given url assuming a successful fetch. """ path = url.split("://")[1] newpath = path if path[0] != "/": filespath = data.getVar('FILESPATH', d, 1) if filespath: newpath = bb.which(filespath, path) if not newpath: filesdir = data.getVar('FILESDIR', d, 1) if filesdir: newpath = os.path.join(filesdir, path) # We don't set localfile as for this fetcher the file is already local! return newpath
def visitInclude(self, data, nodecache): node.get_direct_root().expand( data, nodecache ) bbpath = os.environ['BBPATH'] if node.has_root(): bbpath = "%s:%s" % (os.path.dirname(node.root.filename), bbpath) include = bb.which(bbpath, data.expand(node.file, None)) try: ast = nodecache.parse_include(include) root = EvaluateRoot(self) root.accept( ast, data, nodecache ) bb.parse.mark_dependency(data, include) except Exception, e: print "Didn't work %s %s" % (node.file, include)
def write_md5sum(url, ud, d): if bb.which(data.getVar('PATH', d), 'md5sum'): try: md5pipe = os.popen('md5sum ' + ud.localpath) md5data = (md5pipe.readline().split() or [ "" ])[0] md5pipe.close() except OSError: md5data = "" # verify the md5sum if not Fetch.verify_md5sum(ud, md5data): raise MD5SumError(url) md5out = file(ud.md5, 'w') md5out.write(md5data) md5out.close()
def localpath(self, url, urldata, d): """ Return the local filename of a given url assuming a successful fetch. """ path = url.split("://")[1] path = path.split(";")[0] newpath = path if path[0] != "/": filespath = data.getVar('FILESPATH', d, 1) if filespath: newpath = bb.which(filespath, path) if not newpath: filesdir = data.getVar('FILESDIR', d, 1) if filesdir: newpath = os.path.join(filesdir, path) # We don't set localfile as for this fetcher the file is already local! return newpath
def fetch_uri(uri, basename, dl, md5, parm, d): # the MD5 sum we want to verify wanted_md5sum = md5_sum(parm, d) if os.path.exists(dl): # file exists, but we didnt complete it.. trying again.. fetchcmd = data.getVar("RESUMECOMMAND", d, 1) else: fetchcmd = data.getVar("FETCHCOMMAND", d, 1) bb.note("fetch " + uri) fetchcmd = fetchcmd.replace("${URI}", uri) fetchcmd = fetchcmd.replace("${FILE}", basename) bb.debug(2, "executing " + fetchcmd) ret = os.system(fetchcmd) if ret != 0: return False # check if sourceforge did send us to the mirror page dl_dir = data.getVar("DL_DIR", d, True) if not os.path.exists(dl): os.system("rm %s*" % dl) # FIXME shell quote it bb.debug(2,"sourceforge.net send us to the mirror on %s" % basename) return False # supposedly complete.. write out md5sum if bb.which(data.getVar('PATH', d), 'md5sum'): try: md5pipe = os.popen('md5sum ' + dl) md5data = (md5pipe.readline().split() or [ "" ])[0] md5pipe.close() except OSError: md5data = "" # verify the md5sum if not verify_md5sum(wanted_md5sum, md5data): raise MD5SumError(uri) md5out = file(md5, 'w') md5out.write(md5data) md5out.close() return True
def handle(fn, d, include): print "" print "fn: %s" % fn print "data: %s" % d print dir(d) print d.getVar.__doc__ print "include: %s" % include # check if we include or are the beginning if include: oldfile = d.getVar('FILE') else: #d.inheritFromOS() oldfile = None # find the file if not os.path.isabs(fn): bb.error("No Absolute FILE name") abs_fn = bb.which(d.getVar('BBPATH'), fn) else: abs_fn = fn # check if the file exists if not os.path.exists(abs_fn): raise IOError("file '%(fn)' not found" % locals() ) # now we know the file is around mark it as dep if include: parse.mark_dependency(d, abs_fn) # now parse this file - by defering it to C++ parsefile(fn, d) # restore the original FILE if oldfile: d.setVar('FILE', oldfile) return d
def handle(fn, d, include): from bb import data, parse (root, ext) = os.path.splitext(os.path.basename(fn)) base_name = "%s%s" % (root,ext) # initialize with some data init(fn,d) # check if we include or are the beginning oldfile = None if include: oldfile = d.getVar('FILE', False) is_conf = False elif ext == ".conf": is_conf = True data.inheritFromOS(d) # find the file if not os.path.isabs(fn): abs_fn = bb.which(d.getVar('BBPATH', True), fn) else: abs_fn = fn # check if the file exists if not os.path.exists(abs_fn): raise IOError("file '%(fn)s' not found" % locals() ) # now we know the file is around mark it as dep if include: parse.mark_dependency(d, abs_fn) # manipulate the bbpath if ext != ".bbclass" and ext != ".conf": old_bb_path = data.getVar('BBPATH', d) data.setVar('BBPATH', os.path.dirname(abs_fn) + (":%s" %old_bb_path) , d) # handle INHERITS and base inherit if ext != ".bbclass" and ext != ".conf": data.setVar('FILE', fn, d) handle_interit(d) # now parse this file - by defering it to C++ parsefile(abs_fn, d, is_conf) # Finish it up if include == 0: data.expandKeys(d) data.update_data(d) #### !!! XXX Finish it up by executing the anonfunc # restore the original FILE if oldfile: d.setVar('FILE', oldfile) # restore bbpath if ext != ".bbclass" and ext != ".conf": data.setVar('BBPATH', old_bb_path, d ) return d