2 # ex:ts=4:sw=4:sts=4:et
3 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
5 import os, sys, getopt, copy
6 sys.path.append('/usr/share/oe')
10 def usage(errorlevel=0, txt=''):
15 print "Usage: oebuild [options]... [task] [oefile]"
17 print "Run task (defaults to 'build') on oefile (defaults to first"
18 print "*.oe file found in current dir)"
21 print " %s\t\t%s" % ("-V, --version", "output version information and exit")
22 print " %s\t\t%s" % ("-f, --force", "forces execution of specified task")
24 print "Example: oebuild build content/glibc-2.3.1.oe"
30 print "OpenEmbedded Build Infrastructure Core version %s" % oe.__version__
31 print "OEBuild version %s" % __version__
34 """Returns the first *.oe file found in current directory"""
35 dirs = os.listdir(os.getcwd())
38 if os.path.splitext(f)[1] == ".oe":
39 return os.path.abspath(os.path.join(os.getcwd(),f))
43 """Get default command, currently always 'build'"""
50 (opts, args) = getopt.getopt(sys.argv[1:], 'Vhf', [ 'version', 'help', 'force' ])
51 except getopt.GetoptError:
54 optsonly = [ opt for (opt,val) in opts]
55 if '--version' in optsonly or '-V' in optsonly:
59 if '--help' in optsonly or '-h' in optsonly:
65 # variable initialization
73 make.cfg = parse.handle("conf/oe.conf", make.cfg)
75 (type, value, traceback) = sys.exc_info()
76 fatal("Unable to open oe.conf: %s" % value)
79 # user didnt specify command or .oe
80 # see if we can find a .oe file in the current dir
87 # First, see if this is a valid task.
89 oedata, cached = oe.make.load_oefile(args[0])
91 fatal("unable to read %s: %s" % (args[0], e))
93 # If so, assume its a command.
94 # If its a command, but we cant get a .oe file
95 # in the current dir, usage()
98 # If not, assume a .oe file.
105 oefile = get_oefile()
107 # user specified both
122 oedata, cached = make.load_oefile(oefile)
125 fatal("Unable to open %s" % oefile)
127 if '--force' in optsonly or '-f' in optsonly:
128 data.setVarFlag('do_%s' % cmd, 'force', 1, oedata)
132 # Finally exec the requested task
135 build.exec_task('do_%s' % cmd, oedata)
136 except build.FuncFailed:
137 fatal("task stack execution failed")
138 except build.EventException:
139 (type, value, traceback) = sys.exc_info()
141 fatal("%s event exception, aborting" % event.getName(e))