#!/usr/bin/python import sys sys.path.append('/usr/share/oe') from oe import * import oe import os def usage(errorlevel=0, txt=''): global tasks if txt: print print txt print "Usage: oebuild [options]... [task] [oefile]" # print "Run TASK on OEFILE or standard input if OEFILE is -." print "Run task on oefile. Default task is 'build'." print "Default .oe file is the first .oe file found in the" print "current directory, if one exists." print "Example: oebuild build content/glibc-2.3.1.oe" print "" print " %s\t\t%s" % ("-v, --version", "output version information and exit") sys.exit(0) __version__ = 1.0 def version(): print "OpenEmbedded Build Infrastructure Core version %s" % oe.__version__ print "OEBuild version %s" % __version__ import getopt try: (opts, args) = getopt.getopt(sys.argv[1:], 'vh', [ 'version', 'help' ]) except getopt.GetoptError: usage(1) def get_oefiles(): """Get default oefiles""" dirs = os.listdir(os.getcwd()) oefiles = [] for f in dirs: (root, ext) = os.path.splitext(f) if ext == ".oe": oefiles.append(os.path.abspath(os.path.join(os.getcwd(),f))) return oefiles def get_oefile(): """Get default oefile""" oefiles = get_oefiles() if len(oefiles): return oefiles[0] else: return None def get_cmd(): """Get default command""" return "build" def load_oefile(oefile, cfgdata): oepath = data.getVar('OEPATH', cfg) topdir = data.getVar('TOPDIR', cfg) if not topdir: topdir = os.path.abspath(os.getcwd()) # set topdir to here data.setVar('TOPDIR', topdir, cfg) oefile = os.path.abspath(oefile) oefile_loc = os.path.abspath(os.path.dirname(oefile)) # expand tmpdir to include this topdir data.setVar('TMPDIR', data.getVar('TMPDIR', cfg, 1) or "", cfg) # add topdir to oepath oepath += ":%s" % topdir # set topdir to location of .oe file topdir = oefile_loc #data.setVar('TOPDIR', topdir, cfg) # add that topdir to oepath oepath += ":%s" % topdir # go there os.chdir(topdir) data.setVar('OEPATH', oepath, cfg) from copy import copy oe = copy(cfgdata) try: oe = parse.handle(oefile, oe) # read .oe data return oe except IOError, OSError: return None # handle opts optsonly = [ opt for (opt,val) in opts] if '--version' in optsonly or '-v' in optsonly: version() sys.exit(0) if '--help' in optsonly or '-h' in optsonly: usage(1) # variable initialization oefile = None cmd = None oedata = None cfg = data.init() graph = digraph() try: cfg = parse.handle("conf/oe.conf", cfg) # Read configuration except IOError: (type, value, traceback) = sys.exc_info() fatal("Unable to open oe.conf: %s" % value) if len(args) == 0: # user didnt specify command or .oe # see if we can find a .oe file in the current dir oefile = get_oefile() cmd = get_cmd() elif len(args) == 1: # one of two cases: # 1) oebuild COMMAND # 2) oebuild OEFILE # First, see if this is a valid task. oedata = load_oefile(args[0], cfg) if not oedata: # If so, assume its a command. # If its a command, but we cant get a .oe file # in the current dir, usage() cmd = args[0] else: # If not, assume a .oe file. oefile = args[0] if not cmd: cmd = get_cmd() if not oefile: oefile = get_oefile() elif len(args) == 2: # user specified both cmd = args[0] oefile = args[1] else: # invalid usage(1) if not cmd: usage(1) if not oefile: usage(1) if not oedata: oedata = load_oefile(oefile, cfg) if not oedata: fatal("Unable to open %s" % oefile) for var in oedata.keys(): if data.getVarFlag(var, 'handler', oedata): event.register(data.getVar(var, oedata)) continue if not data.getVarFlag(var, 'task', oedata): continue deps = data.getVarFlag(var, 'deps', oedata) or [] postdeps = data.getVarFlag(var, 'postdeps', oedata) or [] build.add_task(var, var, deps) for p in postdeps: d = build.get_task_data() pcontent = data.getVar(p, d) or p pdeps = data.getVarFlag(pcontent, 'deps', oedata) or [] pdeps.append(var) data.setVarFlag(pcontent, 'deps', pdeps, oedata) build.add_task(p, pcontent, pdeps) try: build.exec_task('do_%s' % cmd, oedata) except build.FuncFailed: fatal("task stack execution failed") except build.EventException: (type, value, traceback) = sys.exc_info() e = value.event fatal("%s event exception, aborting" % event.getName(e))