aboutsummaryrefslogtreecommitdiffstats
path: root/bin/bitbake
blob: 525150e5e41a9570edc7ff9281489062f49c6edd (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env python
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
#
# Copyright (C) 2003, 2004  Chris Larson
# Copyright (C) 2003, 2004  Phil Blundell
# Copyright (C) 2003 - 2005 Michael 'Mickey' Lauer
# Copyright (C) 2005        Holger Hans Peter Freyther
# Copyright (C) 2005        ROAD GmbH
# Copyright (C) 2006        Richard Purdie
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import sys, os, getopt, re, time, optparse, xmlrpclib
sys.path.insert(0,os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
import bb
from bb import cooker
from bb import daemonize
from bb import ui
from bb.ui import uievent

__version__ = "1.9.0"

#============================================================================#
# BBOptions
#============================================================================#
class BBConfiguration( object ):
    """
    Manages build options and configurations for one run
    """
    def __init__( self, options ):
        for key, val in options.__dict__.items():
            setattr( self, key, val )


#============================================================================#
# main
#============================================================================#

def main():
    return_value = 0
    pythonver = sys.version_info
    if pythonver[0] < 2 or (pythonver[0] == 2 and pythonver[1] < 5):
        print "Sorry, bitbake needs python 2.5 or later."
        sys.exit(1)

    parser = optparse.OptionParser( version = "BitBake Build Tool Core version %s, %%prog version %s" % ( bb.__version__, __version__ ),
    usage = """%prog [options] [package ...]

Executes the specified task (default is 'build') for a given set of BitBake files.
It expects that BBFILES is defined, which is a space separated list of files to
be executed.  BBFILES does support wildcards.
Default BBFILES are the .bb files in the current directory.""" )

    parser.add_option( "-b", "--buildfile", help = "execute the task against this .bb file, rather than a package from BBFILES.",
               action = "store", dest = "buildfile", default = None )

    parser.add_option( "-k", "--continue", help = "continue as much as possible after an error. While the target that failed, and those that depend on it, cannot be remade, the other dependencies of these targets can be processed all the same.",
               action = "store_false", dest = "abort", default = True )

    parser.add_option( "-a", "--tryaltconfigs", help = "continue with builds by trying to use alternative providers where possible.",
               action = "store_true", dest = "tryaltconfigs", default = False )

    parser.add_option( "-f", "--force", help = "force run of specified cmd, regardless of stamp status",
               action = "store_true", dest = "force", default = False )

    parser.add_option( "-i", "--interactive", help = "drop into the interactive mode also called the BitBake shell.",
               action = "store_true", dest = "interactive", default = False )

    parser.add_option( "-c", "--cmd", help = "Specify task to execute. Note that this only executes the specified task for the providee and the packages it depends on, i.e. 'compile' does not implicitly call stage for the dependencies (IOW: use only if you know what you are doing). Depending on the base.bbclass a listtasks tasks is defined and will show available tasks",
               action = "store", dest = "cmd" )

    parser.add_option( "-r", "--read", help = "read the specified file before bitbake.conf",
               action = "append", dest = "file", default = [] )

    parser.add_option( "-v", "--verbose", help = "output more chit-chat to the terminal",
               action = "store_true", dest = "verbose", default = False )

    parser.add_option( "-D", "--debug", help = "Increase the debug level. You can specify this more than once.",
               action = "count", dest="debug", default = 0)

    parser.add_option( "-n", "--dry-run", help = "don't execute, just go through the motions",
               action = "store_true", dest = "dry_run", default = False )

    parser.add_option( "-p", "--parse-only", help = "quit after parsing the BB files (developers only)",
               action = "store_true", dest = "parse_only", default = False )

    parser.add_option( "-d", "--disable-psyco", help = "disable using the psyco just-in-time compiler (not recommended)",
               action = "store_true", dest = "disable_psyco", default = False )

    parser.add_option( "-s", "--show-versions", help = "show current and preferred versions of all packages",
               action = "store_true", dest = "show_versions", default = False )

    parser.add_option( "-e", "--environment", help = "show the global or per-package environment (this is what used to be bbread)",
               action = "store_true", dest = "show_environment", default = False )

    parser.add_option( "-g", "--graphviz", help = "emit the dependency trees of the specified packages in the dot syntax",
                action = "store_true", dest = "dot_graph", default = False )

    parser.add_option( "-I", "--ignore-deps", help = """Assume these dependencies don't exist and are already provided (equivalent to ASSUME_PROVIDED). Useful to make dependency graphs more appealing""",
                action = "append", dest = "extra_assume_provided", default = [] )

    parser.add_option( "-l", "--log-domains", help = """Show debug logging for the specified logging domains""",
                action = "append", dest = "debug_domains", default = [] )

    parser.add_option( "-P", "--profile", help = "profile the command and print a report",
               action = "store_true", dest = "profile", default = False )

    parser.add_option( "-u", "--ui", help = "userinterface to use",
               action = "store", dest = "ui")

    options, args = parser.parse_args(sys.argv)

    configuration = BBConfiguration(options)
    configuration.pkgs_to_build = []
    configuration.pkgs_to_build.extend(args[1:])


    # Work out which UI(s) to use
    curseUI = False
    depexplorerUI = False
    if configuration.ui:
        if configuration.ui == "ncurses":
            curseUI = True
        elif configuration.ui == "knotty" or configuration.ui == "tty" or configuration.ui == "file":
            curseUI = False
        elif configuration.ui == "depexp":
            depexplorerUI = True
        else:
            print "FATAL: Invalid user interface '%s' specified.\nValid interfaces are 'ncurses', 'depexp' or the default, 'knotty'." % configuration.ui
            sys.exit(1)


    cooker = bb.cooker.BBCooker(configuration)

    # Optionally clean up the environment
    if 'BB_PRESERVE_ENV' not in os.environ:
        if 'BB_ENV_WHITELIST' in os.environ:
            good_vars = os.environ['BB_ENV_WHITELIST'].split()
        else:
            good_vars = bb.utils.preserved_envvars_list()
        if 'BB_ENV_EXTRAWHITE' in os.environ:
            good_vars.extend(os.environ['BB_ENV_EXTRAWHITE'].split())
        bb.utils.filter_environment(good_vars)

    cooker.parseConfiguration()
    host = cooker.server.host
    port = cooker.server.port

    # Save a logfile for cooker somewhere
    t = bb.data.getVar('TMPDIR', cooker.configuration.data, True)
    if not t:
       bb.msg.fatal(bb.msg.domain.Build, "TMPDIR not set")
    t = os.path.join(t, "cooker")
    bb.mkdirhier(t)
    cooker_logfile = "%s/log.cooker.%s" % (t, str(os.getpid()))

    daemonize.createDaemon(cooker.serve, cooker_logfile)
    del cooker

    # Setup a connection to the server (cooker)
    server = xmlrpclib.Server("http://%s:%s" % (host, port),  allow_none=True)
    # Setup an event receiving queue
    eventHandler = uievent.BBUIEventQueue(server)

    # Launch the UI
    try:
        # Disable UIs that need a terminal
        if not os.isatty(sys.stdout.fileno()):
            curseUI = False

        if curseUI:
            try:
                import curses
            except ImportError, details:
                curseUI = False

        if curseUI:
            from bb.ui import ncurses
            ncurses.init(server, eventHandler)
        elif depexplorerUI:
            from bb.ui import depexplorer
            depexplorer.init(server, eventHandler)
        else:
            from bb.ui import knotty
            return_value = knotty.init(server, eventHandler)

    finally:
        # Don't wait for server indefinitely
        import socket
        socket.setdefaulttimeout(2) 
        try:
            eventHandler.system_quit()
        except:
            pass
        try:
            server.terminateServer()
        except:
            pass
        return return_value

if __name__ == "__main__":
    print """WARNING, WARNING, WARNING
This is a Bitbake from the Unstable/Development 1.9 Branch. This software contains gaping security holes and is dangerous to use!
You might want to use the bitbake-1.8 stable branch (if you are not a BitBake developer or tester). I'm going to sleep 5 seconds now to make sure you see that."""
    import time
    time.sleep(5)
    ret = main()
    sys.exit(ret)