summaryrefslogtreecommitdiffstats
path: root/bin/oebuild
blob: 1d0abe91a8a0cfba1ba410f039719ddfae698477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-

import os, sys, getopt, copy
sys.path.append('/usr/share/oe')
from oe import *
import oe

def usage(errorlevel=0, txt=''):
    print
    if txt:
        print txt

    print "Usage: oebuild [options]... [task] [oefile]"
    print
    print "Run task (defaults to 'build') on oefile (defaults to first"
    print "*.oe file found in current dir)"
    print
    print "Options:"
    print "  %s\t\t%s" % ("-V, --version", "output version information and exit")
    print "  %s\t\t%s" % ("-f, --force", "forces execution of specified task")
    print
    print "Example: oebuild build content/glibc-2.3.1.oe"
    print
    sys.exit(0)

__version__ = 1.0
def version():
    print "OpenEmbedded Build Infrastructure Core version %s" % oe.__version__
    print "OEBuild version %s" % __version__

def get_oefile():
    """Returns the first *.oe file found in current directory"""
    dirs = os.listdir(os.getcwd())
    dirs.sort()
    for f in dirs:
        if os.path.splitext(f)[1] == ".oe":
            return os.path.abspath(os.path.join(os.getcwd(),f))
    return None

def get_cmd():
    """Get default command, currently always 'build'"""
    return "build"

#
# Handle options:
#
try:
    (opts, args) = getopt.getopt(sys.argv[1:], 'Vhf', [ 'version', 'help', 'force' ])
except getopt.GetoptError:
    usage(1)

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

try:
    make.cfg = parse.handle("conf/oe.conf", make.cfg)
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.
    try:
        oedata, cached = oe.make.load_oefile(args[0])
    except Exception, e:
        fatal("unable to read %s: %s" % (args[0], e))
    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)

try:
    if not oedata:
        oedata, cached = make.load_oefile(oefile)

    if not oedata:
        fatal("Unable to open %s" % oefile)

    if '--force' in optsonly or '-f' in optsonly:
        data.setVarFlag('do_%s' % cmd, 'force', 1, oedata)


#
# Finally exec the requested task
#

    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))
except Exception, e:
    fatal("%s" % e)