Teach the oe tools to catch Exception so they fail a bit cleaner on exceptions it...
[vuplus_bitbake] / bin / oebuild
1 #!/usr/bin/env python
2
3 import os, sys, getopt, copy
4 sys.path.append('/usr/share/oe')
5 from oe import *
6 import oe
7
8 def usage(errorlevel=0, txt=''):
9         print
10         if txt:
11                 print txt
12
13         print "Usage: oebuild [options]... [task] [oefile]"
14         print
15         print "Run task (defaults to 'build') on oefile (defaults to first"
16         print "*.oe file found in current dir)"
17         print
18         print "Options:"
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")
21         print
22         print "Example: oebuild build content/glibc-2.3.1.oe"
23         print
24         sys.exit(0)
25
26 __version__ = 1.0
27 def version():
28         print "OpenEmbedded Build Infrastructure Core version %s" % oe.__version__
29         print "OEBuild version %s" % __version__
30
31 def get_oefile():
32         """Returns the first *.oe file found in current directory"""
33         dirs = os.listdir(os.getcwd())
34         dirs.sort()
35         for f in dirs:
36                 if os.path.splitext(f)[1] == ".oe":
37                         return os.path.abspath(os.path.join(os.getcwd(),f))
38         return None
39
40 def get_cmd():
41         """Get default command, currently always 'build'"""
42         return "build"
43
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)
48         if not topdir:
49                 topdir = os.path.abspath(os.getcwd())
50                 # set topdir to here
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
59         topdir = oefile_loc
60         #data.setVar('TOPDIR', topdir, cfg)
61         # add that topdir to oepath
62         oepath += ":%s" % topdir
63         # go there
64         os.chdir(topdir)
65         data.setVar('OEPATH', oepath, cfg)
66         oe = copy.copy(cfgdata)
67         from oe.parse import ParseError
68         try:
69                 oe = parse.handle(oefile, oe) # read .oe data
70                 return oe
71         except Exception, e:
72                 error("%s" % e)
73                 return None
74
75
76 #
77 # Handle options:
78 #
79 try:
80         (opts, args) = getopt.getopt(sys.argv[1:], 'Vhf', [ 'version', 'help', 'force' ])
81 except getopt.GetoptError:
82         usage(1)
83
84 optsonly = [ opt for (opt,val) in opts]
85 if '--version' in optsonly or '-V' in optsonly:
86         version()
87         sys.exit(0)
88
89 if '--help' in optsonly or '-h' in optsonly:
90         usage(1)
91
92
93
94 #
95 # variable initialization
96 #
97
98 oefile = None
99 cmd = None
100 oedata = None
101 cfg = data.init()
102 graph = digraph()
103
104 try:
105         cfg = parse.handle("conf/oe.conf", cfg)
106 except IOError:
107         (type, value, traceback) = sys.exc_info()
108         fatal("Unable to open oe.conf: %s" % value)
109
110 if len(args) == 0:
111         # user didnt specify command or .oe
112         # see if we can find a .oe file in the current dir
113         oefile = get_oefile()
114         cmd = get_cmd()
115 elif len(args) == 1:
116         # one of two cases:
117         #       1) oebuild COMMAND
118         #       2) oebuild OEFILE
119         # First, see if this is a valid task.
120         oedata = load_oefile(args[0], cfg)
121         if not oedata:
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()
125                 cmd = args[0]
126         else:
127                 # If not, assume a .oe file.
128                 oefile = args[0]
129
130         if not cmd:
131                 cmd = get_cmd()
132
133         if not oefile:
134                 oefile = get_oefile()
135 elif len(args) == 2:
136         # user specified both
137         cmd = args[0]
138         oefile = args[1]
139 else:
140         # invalid
141         usage(1)
142
143 if not cmd:
144         usage(1)
145
146 if not oefile:
147         usage(1)
148
149 if not oedata:
150         oedata = load_oefile(oefile, cfg)
151
152 if not oedata:
153         fatal("Unable to open %s" % oefile)
154
155 if '--force' in optsonly or '-f' in optsonly:
156         data.setVarFlag('do_%s' % cmd, 'force', 1, oedata)
157
158
159 #
160 # Finally exec the requested task
161 #
162
163 try:
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()
169         e = value.event
170         fatal("%s event exception, aborting" % event.getName(e))
171 except Exception, e:
172         fatal("%s" % e)