Auto merged
[vuplus_bitbake] / bin / oebuild
1 #!/usr/bin/env python
2 # ex:ts=4:sw=4:sts=4:et
3 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4
5 import os, sys, getopt, copy
6 sys.path.append('/usr/share/oe')
7 from oe import *
8 import oe
9
10 def usage(errorlevel=0, txt=''):
11     print
12     if txt:
13         print txt
14
15     print "Usage: oebuild [options]... [task] [oefile]"
16     print
17     print "Run task (defaults to 'build') on oefile (defaults to first"
18     print "*.oe file found in current dir)"
19     print
20     print "Options:"
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")
23     print
24     print "Example: oebuild build content/glibc-2.3.1.oe"
25     print
26     sys.exit(0)
27
28 __version__ = 1.0
29 def version():
30     print "OpenEmbedded Build Infrastructure Core version %s" % oe.__version__
31     print "OEBuild version %s" % __version__
32
33 def get_oefile():
34     """Returns the first *.oe file found in current directory"""
35     dirs = os.listdir(os.getcwd())
36     dirs.sort()
37     for f in dirs:
38         if os.path.splitext(f)[1] == ".oe":
39             return os.path.abspath(os.path.join(os.getcwd(),f))
40     return None
41
42 def get_cmd():
43     """Get default command, currently always 'build'"""
44     return "build"
45
46 #
47 # Handle options:
48 #
49 try:
50     (opts, args) = getopt.getopt(sys.argv[1:], 'Vhf', [ 'version', 'help', 'force' ])
51 except getopt.GetoptError:
52     usage(1)
53
54 optsonly = [ opt for (opt,val) in opts]
55 if '--version' in optsonly or '-V' in optsonly:
56     version()
57     sys.exit(0)
58
59 if '--help' in optsonly or '-h' in optsonly:
60     usage(1)
61
62
63
64 #
65 # variable initialization
66 #
67
68 oefile = None
69 cmd = None
70 oedata = None
71
72 try:
73     make.cfg = parse.handle("conf/oe.conf", make.cfg)
74 except IOError:
75     (type, value, traceback) = sys.exc_info()
76     fatal("Unable to open oe.conf: %s" % value)
77
78 if len(args) == 0:
79     # user didnt specify command or .oe
80     # see if we can find a .oe file in the current dir
81     oefile = get_oefile()
82     cmd = get_cmd()
83 elif len(args) == 1:
84     # one of two cases:
85     #   1) oebuild COMMAND
86     #   2) oebuild OEFILE
87     # First, see if this is a valid task.
88     try:
89         oedata, cached = oe.make.load_oefile(args[0])
90     except Exception, e:
91         fatal("unable to read %s: %s" % (args[0], e))
92     if not oedata:
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()
96         cmd = args[0]
97     else:
98         # If not, assume a .oe file.
99         oefile = args[0]
100
101     if not cmd:
102         cmd = get_cmd()
103
104     if not oefile:
105         oefile = get_oefile()
106 elif len(args) == 2:
107     # user specified both
108     cmd = args[0]
109     oefile = args[1]
110 else:
111     # invalid
112     usage(1)
113
114 if not cmd:
115     usage(1)
116
117 if not oefile:
118     usage(1)
119
120 try:
121     if not oedata:
122         oedata, cached = make.load_oefile(oefile)
123
124     if not oedata:
125         fatal("Unable to open %s" % oefile)
126
127     if '--force' in optsonly or '-f' in optsonly:
128         data.setVarFlag('do_%s' % cmd, 'force', 1, oedata)
129
130
131 #
132 # Finally exec the requested task
133 #
134
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()
140     e = value.event
141     fatal("%s event exception, aborting" % event.getName(e))
142 except Exception, e:
143     fatal("%s" % e)