3 import os, sys, getopt, copy
4 sys.path.append('/usr/share/oe')
8 def usage(errorlevel=0, txt=''):
13 print "Usage: oebuild [options]... [task] [oefile]"
15 print "Run task (defaults to 'build') on oefile (defaults to first"
16 print "*.oe file found in current dir)"
19 print " %s\t\t%s" % ("-V, --version", "output version information and exit")
20 print " %s\t\t%s" % ("-f, --force", "forces execution of specified task")
22 print "Example: oebuild build content/glibc-2.3.1.oe"
28 print "OpenEmbedded Build Infrastructure Core version %s" % oe.__version__
29 print "OEBuild version %s" % __version__
32 """Returns the first *.oe file found in current directory"""
33 dirs = os.listdir(os.getcwd())
36 if os.path.splitext(f)[1] == ".oe":
37 return os.path.abspath(os.path.join(os.getcwd(),f))
41 """Get default command, currently always 'build'"""
44 def load_oefile(oefile, cfgdata):
45 """Loads one *.oe file and returns the contents as a dictionary"""
46 oepath = data.getVar('OEPATH', cfg)
47 topdir = data.getVar('TOPDIR', cfg)
49 topdir = os.path.abspath(os.getcwd())
51 data.setVar('TOPDIR', topdir, cfg)
52 oefile = os.path.abspath(oefile)
53 oefile_loc = os.path.abspath(os.path.dirname(oefile))
54 # expand tmpdir to include this topdir
55 data.setVar('TMPDIR', data.getVar('TMPDIR', cfg, 1) or "", cfg)
56 # add topdir to oepath
57 oepath += ":%s" % topdir
58 # set topdir to location of .oe file
60 #data.setVar('TOPDIR', topdir, cfg)
61 # add that topdir to oepath
62 oepath += ":%s" % topdir
65 data.setVar('OEPATH', oepath, cfg)
66 oe = copy.copy(cfgdata)
67 from oe.parse import ParseError
69 oe = parse.handle(oefile, oe) # read .oe data
80 (opts, args) = getopt.getopt(sys.argv[1:], 'Vhf', [ 'version', 'help', 'force' ])
81 except getopt.GetoptError:
84 optsonly = [ opt for (opt,val) in opts]
85 if '--version' in optsonly or '-V' in optsonly:
89 if '--help' in optsonly or '-h' in optsonly:
95 # variable initialization
105 cfg = parse.handle("conf/oe.conf", cfg)
107 (type, value, traceback) = sys.exc_info()
108 fatal("Unable to open oe.conf: %s" % value)
111 # user didnt specify command or .oe
112 # see if we can find a .oe file in the current dir
113 oefile = get_oefile()
119 # First, see if this is a valid task.
120 oedata = load_oefile(args[0], cfg)
122 # If so, assume its a command.
123 # If its a command, but we cant get a .oe file
124 # in the current dir, usage()
127 # If not, assume a .oe file.
134 oefile = get_oefile()
136 # user specified both
150 oedata = load_oefile(oefile, cfg)
153 fatal("Unable to open %s" % oefile)
155 if '--force' in optsonly or '-f' in optsonly:
156 data.setVarFlag('do_%s' % cmd, 'force', 1, oedata)
160 # Finally exec the requested task
164 build.exec_task('do_%s' % cmd, oedata)
165 except build.FuncFailed:
166 fatal("task stack execution failed")
167 except build.EventException:
168 (type, value, traceback) = sys.exc_info()
170 fatal("%s event exception, aborting" % event.getName(e))