summaryrefslogtreecommitdiffstats
path: root/import-layers/yocto-poky/bitbake/lib/bb/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'import-layers/yocto-poky/bitbake/lib/bb/main.py')
-rwxr-xr-ximport-layers/yocto-poky/bitbake/lib/bb/main.py288
1 files changed, 185 insertions, 103 deletions
diff --git a/import-layers/yocto-poky/bitbake/lib/bb/main.py b/import-layers/yocto-poky/bitbake/lib/bb/main.py
index e30217369..f2f59f670 100755
--- a/import-layers/yocto-poky/bitbake/lib/bb/main.py
+++ b/import-layers/yocto-poky/bitbake/lib/bb/main.py
@@ -27,6 +27,7 @@ import sys
import logging
import optparse
import warnings
+import fcntl
import bb
from bb import event
@@ -100,11 +101,12 @@ def import_extension_module(pkg, modulename, checkattr):
# Dynamically load the UI based on the ui name. Although we
# suggest a fixed set this allows you to have flexibility in which
# ones are available.
- module = __import__(pkg.__name__, fromlist = [modulename])
+ module = __import__(pkg.__name__, fromlist=[modulename])
return getattr(module, modulename)
except AttributeError:
- raise BBMainException('FATAL: Unable to import extension module "%s" from %s. Valid extension modules: %s' % (modulename, pkg.__name__, present_options(list_extension_modules(pkg, checkattr))))
-
+ modules = present_options(list_extension_modules(pkg, checkattr))
+ raise BBMainException('FATAL: Unable to import extension module "%s" from %s. '
+ 'Valid extension modules: %s' % (modulename, pkg.__name__, modules))
# Display bitbake/OE warnings via the BitBake.Warnings logger, ignoring others"""
warnlog = logging.getLogger("BitBake.Warnings")
@@ -115,7 +117,7 @@ def _showwarning(message, category, filename, lineno, file=None, line=None):
_warnings_showwarning(message, category, filename, lineno, file, line)
else:
s = warnings.formatwarning(message, category, filename, lineno)
- warnlog.warn(s)
+ warnlog.warning(s)
warnings.showwarning = _showwarning
warnings.filterwarnings("ignore")
@@ -129,136 +131,189 @@ class BitBakeConfigParameters(cookerdata.ConfigParameters):
def parseCommandLine(self, argv=sys.argv):
parser = optparse.OptionParser(
- formatter = BitbakeHelpFormatter(),
- version = "BitBake Build Tool Core version %s" % bb.__version__,
- usage = """%prog [options] [recipename/target recipe:do_task ...]
+ formatter=BitbakeHelpFormatter(),
+ version="BitBake Build Tool Core version %s" % bb.__version__,
+ usage="""%prog [options] [recipename/target recipe:do_task ...]
Executes the specified task (default is 'build') for a given set of target recipes (.bb files).
It is assumed there is a conf/bblayers.conf available in cwd or in BBPATH which
will provide the layer, BBFILES and other configuration information.""")
- parser.add_option("-b", "--buildfile", help = "Execute tasks from a specific .bb recipe directly. WARNING: Does not handle any dependencies from other recipes.",
- action = "store", dest = "buildfile", default = None)
+ parser.add_option("-b", "--buildfile", action="store", dest="buildfile", default=None,
+ help="Execute tasks from a specific .bb recipe directly. WARNING: Does "
+ "not handle any dependencies from other recipes.")
+
+ parser.add_option("-k", "--continue", action="store_false", dest="abort", default=True,
+ help="Continue as much as possible after an error. While the target that "
+ "failed and anything depending on it cannot be built, as much as "
+ "possible will be built before stopping.")
- parser.add_option("-k", "--continue", help = "Continue as much as possible after an error. While the target that failed and anything depending on it cannot be built, as much as possible will be built before stopping.",
- action = "store_false", dest = "abort", default = True)
+ parser.add_option("-a", "--tryaltconfigs", action="store_true",
+ dest="tryaltconfigs", default=False,
+ help="Continue with builds by trying to use alternative providers "
+ "where possible.")
- 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", action="store_true", dest="force", default=False,
+ help="Force the specified targets/task to run (invalidating any "
+ "existing stamp file).")
- parser.add_option("-f", "--force", help = "Force the specified targets/task to run (invalidating any existing stamp file).",
- action = "store_true", dest = "force", default = False)
+ parser.add_option("-c", "--cmd", action="store", dest="cmd",
+ help="Specify the task to execute. The exact options available "
+ "depend on the metadata. Some examples might be 'compile'"
+ " or 'populate_sysroot' or 'listtasks' may give a list of "
+ "the tasks available.")
- parser.add_option("-c", "--cmd", help = "Specify the task to execute. The exact options available depend on the metadata. Some examples might be 'compile' or 'populate_sysroot' or 'listtasks' may give a list of the tasks available.",
- action = "store", dest = "cmd")
+ parser.add_option("-C", "--clear-stamp", action="store", dest="invalidate_stamp",
+ help="Invalidate the stamp for the specified task such as 'compile' "
+ "and then run the default task for the specified target(s).")
- parser.add_option("-C", "--clear-stamp", help = "Invalidate the stamp for the specified task such as 'compile' and then run the default task for the specified target(s).",
- action = "store", dest = "invalidate_stamp")
+ parser.add_option("-r", "--read", action="append", dest="prefile", default=[],
+ help="Read the specified file before bitbake.conf.")
- parser.add_option("-r", "--read", help = "Read the specified file before bitbake.conf.",
- action = "append", dest = "prefile", default = [])
+ parser.add_option("-R", "--postread", action="append", dest="postfile", default=[],
+ help="Read the specified file after bitbake.conf.")
- parser.add_option("-R", "--postread", help = "Read the specified file after bitbake.conf.",
- action = "append", dest = "postfile", default = [])
+ parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
+ help="Output more log message data to the terminal.")
- parser.add_option("-v", "--verbose", help = "Output more log message data to the terminal.",
- action = "store_true", dest = "verbose", default = False)
+ parser.add_option("-D", "--debug", action="count", dest="debug", default=0,
+ help="Increase the debug level. You can specify this more than once.")
- 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("-q", "--quiet", action="store_true", dest="quiet", default=False,
+ help="Output less log message data to the terminal.")
- 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("-n", "--dry-run", action="store_true", dest="dry_run", default=False,
+ help="Don't execute, just go through the motions.")
- parser.add_option("-S", "--dump-signatures", help = "Dump out the signature construction information, with no task execution. The SIGNATURE_HANDLER parameter is passed to the handler. Two common values are none and printdiff but the handler may define more/less. none means only dump the signature, printdiff means compare the dumped signature with the cached one.",
- action = "append", dest = "dump_signatures", default = [], metavar="SIGNATURE_HANDLER")
+ parser.add_option("-S", "--dump-signatures", action="append", dest="dump_signatures",
+ default=[], metavar="SIGNATURE_HANDLER",
+ help="Dump out the signature construction information, with no task "
+ "execution. The SIGNATURE_HANDLER parameter is passed to the "
+ "handler. Two common values are none and printdiff but the handler "
+ "may define more/less. none means only dump the signature, printdiff"
+ " means compare the dumped signature with the cached one.")
- parser.add_option("-p", "--parse-only", help = "Quit after parsing the BB recipes.",
- action = "store_true", dest = "parse_only", default = False)
+ parser.add_option("-p", "--parse-only", action="store_true",
+ dest="parse_only", default=False,
+ help="Quit after parsing the BB recipes.")
- parser.add_option("-s", "--show-versions", help = "Show current and preferred versions of all recipes.",
- action = "store_true", dest = "show_versions", default = False)
+ parser.add_option("-s", "--show-versions", action="store_true",
+ dest="show_versions", default=False,
+ help="Show current and preferred versions of all recipes.")
- parser.add_option("-e", "--environment", help = "Show the global or per-recipe environment complete with information about where variables were set/changed.",
- action = "store_true", dest = "show_environment", default = False)
+ parser.add_option("-e", "--environment", action="store_true",
+ dest="show_environment", default=False,
+ help="Show the global or per-recipe environment complete with information"
+ " about where variables were set/changed.")
- parser.add_option("-g", "--graphviz", help = "Save dependency tree information for the specified targets in the dot syntax.",
- action = "store_true", dest = "dot_graph", default = False)
+ parser.add_option("-g", "--graphviz", action="store_true", dest="dot_graph", default=False,
+ help="Save dependency tree information for the specified "
+ "targets in the dot syntax.")
- 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("-I", "--ignore-deps", action="append",
+ dest="extra_assume_provided", default=[],
+ help="Assume these dependencies don't exist and are already provided "
+ "(equivalent to ASSUME_PROVIDED). Useful to make dependency "
+ "graphs more appealing")
- parser.add_option("-l", "--log-domains", help = """Show debug logging for the specified logging domains""",
- action = "append", dest = "debug_domains", default = [])
+ parser.add_option("-l", "--log-domains", action="append", dest="debug_domains", default=[],
+ help="Show debug logging for the specified logging domains")
- parser.add_option("-P", "--profile", help = "Profile the command and save reports.",
- action = "store_true", dest = "profile", default = False)
+ parser.add_option("-P", "--profile", action="store_true", dest="profile", default=False,
+ help="Profile the command and save reports.")
- env_ui = os.environ.get('BITBAKE_UI', None)
- default_ui = env_ui or 'knotty'
# @CHOICES@ is substituted out by BitbakeHelpFormatter above
- parser.add_option("-u", "--ui", help = "The user interface to use (@CHOICES@ - default %default).",
- action="store", dest="ui", default=default_ui)
+ parser.add_option("-u", "--ui", action="store", dest="ui",
+ default=os.environ.get('BITBAKE_UI', 'knotty'),
+ help="The user interface to use (@CHOICES@ - default %default).")
# @CHOICES@ is substituted out by BitbakeHelpFormatter above
- parser.add_option("-t", "--servertype", help = "Choose which server type to use (@CHOICES@ - default %default).",
- action = "store", dest = "servertype", default = "process")
+ parser.add_option("-t", "--servertype", action="store", dest="servertype",
+ default=["process", "xmlrpc"]["BBSERVER" in os.environ],
+ help="Choose which server type to use (@CHOICES@ - default %default).")
+
+ parser.add_option("", "--token", action="store", dest="xmlrpctoken",
+ default=os.environ.get("BBTOKEN"),
+ help="Specify the connection token to be used when connecting "
+ "to a remote server.")
- parser.add_option("", "--token", help = "Specify the connection token to be used when connecting to a remote server.",
- action = "store", dest = "xmlrpctoken")
+ parser.add_option("", "--revisions-changed", action="store_true",
+ dest="revisions_changed", default=False,
+ help="Set the exit code depending on whether upstream floating "
+ "revisions have changed or not.")
- parser.add_option("", "--revisions-changed", help = "Set the exit code depending on whether upstream floating revisions have changed or not.",
- action = "store_true", dest = "revisions_changed", default = False)
+ parser.add_option("", "--server-only", action="store_true",
+ dest="server_only", default=False,
+ help="Run bitbake without a UI, only starting a server "
+ "(cooker) process.")
- parser.add_option("", "--server-only", help = "Run bitbake without a UI, only starting a server (cooker) process.",
- action = "store_true", dest = "server_only", default = False)
+ parser.add_option("", "--foreground", action="store_true",
+ help="Run bitbake server in foreground.")
- parser.add_option("-B", "--bind", help = "The name/address for the bitbake server to bind to.",
- action = "store", dest = "bind", default = False)
+ parser.add_option("-B", "--bind", action="store", dest="bind", default=False,
+ help="The name/address for the bitbake server to bind to.")
- parser.add_option("", "--no-setscene", help = "Do not run any setscene tasks. sstate will be ignored and everything needed, built.",
- action = "store_true", dest = "nosetscene", default = False)
+ parser.add_option("-T", "--idle-timeout", type=int,
+ default=int(os.environ.get("BBTIMEOUT", "0")),
+ help="Set timeout to unload bitbake server due to inactivity")
- parser.add_option("", "--setscene-only", help = "Only run setscene tasks, don't run any real tasks.",
- action = "store_true", dest = "setsceneonly", default = False)
+ parser.add_option("", "--no-setscene", action="store_true",
+ dest="nosetscene", default=False,
+ help="Do not run any setscene tasks. sstate will be ignored and "
+ "everything needed, built.")
- parser.add_option("", "--remote-server", help = "Connect to the specified server.",
- action = "store", dest = "remote_server", default = False)
+ parser.add_option("", "--setscene-only", action="store_true",
+ dest="setsceneonly", default=False,
+ help="Only run setscene tasks, don't run any real tasks.")
- parser.add_option("-m", "--kill-server", help = "Terminate the remote server.",
- action = "store_true", dest = "kill_server", default = False)
+ parser.add_option("", "--remote-server", action="store", dest="remote_server",
+ default=os.environ.get("BBSERVER"),
+ help="Connect to the specified server.")
- parser.add_option("", "--observe-only", help = "Connect to a server as an observing-only client.",
- action = "store_true", dest = "observe_only", default = False)
+ parser.add_option("-m", "--kill-server", action="store_true",
+ dest="kill_server", default=False,
+ help="Terminate the remote server.")
- parser.add_option("", "--status-only", help = "Check the status of the remote bitbake server.",
- action = "store_true", dest = "status_only", default = False)
+ parser.add_option("", "--observe-only", action="store_true",
+ dest="observe_only", default=False,
+ help="Connect to a server as an observing-only client.")
- parser.add_option("-w", "--write-log", help = "Writes the event log of the build to a bitbake event json file. Use '' (empty string) to assign the name automatically.",
- action = "store", dest = "writeeventlog")
+ parser.add_option("", "--status-only", action="store_true",
+ dest="status_only", default=False,
+ help="Check the status of the remote bitbake server.")
+
+ parser.add_option("-w", "--write-log", action="store", dest="writeeventlog",
+ default=os.environ.get("BBEVENTLOG"),
+ help="Writes the event log of the build to a bitbake event json file. "
+ "Use '' (empty string) to assign the name automatically.")
options, targets = parser.parse_args(argv)
- # some environmental variables set also configuration options
- if "BBSERVER" in os.environ:
- options.servertype = "xmlrpc"
- options.remote_server = os.environ["BBSERVER"]
+ if options.quiet and options.verbose:
+ parser.error("options --quiet and --verbose are mutually exclusive")
+
+ if options.quiet and options.debug:
+ parser.error("options --quiet and --debug are mutually exclusive")
- if "BBTOKEN" in os.environ:
- options.xmlrpctoken = os.environ["BBTOKEN"]
+ # use configuration files from environment variables
+ if "BBPRECONF" in os.environ:
+ options.prefile.append(os.environ["BBPRECONF"])
- if "BBEVENTLOG" in os.environ:
- options.writeeventlog = os.environ["BBEVENTLOG"]
+ if "BBPOSTCONF" in os.environ:
+ options.postfile.append(os.environ["BBPOSTCONF"])
# fill in proper log name if not supplied
if options.writeeventlog is not None and len(options.writeeventlog) == 0:
- import datetime
- options.writeeventlog = "bitbake_eventlog_%s.json" % datetime.datetime.now().strftime("%Y%m%d%H%M%S")
+ from datetime import datetime
+ eventlog = "bitbake_eventlog_%s.json" % datetime.now().strftime("%Y%m%d%H%M%S")
+ options.writeeventlog = eventlog
# if BBSERVER says to autodetect, let's do that
if options.remote_server:
- [host, port] = options.remote_server.split(":", 2)
- port = int(port)
+ port = -1
+ if options.remote_server != 'autostart':
+ host, port = options.remote_server.split(":", 2)
+ port = int(port)
# use automatic port if port set to -1, means read it from
# the bitbake.lock file; this is a bit tricky, but we always expect
# to be in the base of the build directory if we need to have a
@@ -275,18 +330,20 @@ class BitBakeConfigParameters(cookerdata.ConfigParameters):
lf.close()
options.remote_server = remotedef
except Exception as e:
- raise BBMainException("Failed to read bitbake.lock (%s), invalid port" % str(e))
+ if options.remote_server != 'autostart':
+ raise BBMainException("Failed to read bitbake.lock (%s), invalid port" % str(e))
return options, targets[1:]
def start_server(servermodule, configParams, configuration, features):
server = servermodule.BitBakeServer()
- single_use = not configParams.server_only
+ single_use = not configParams.server_only and os.getenv('BBSERVER') != 'autostart'
if configParams.bind:
(host, port) = configParams.bind.split(':')
- server.initServer((host, int(port)), single_use)
- configuration.interface = [ server.serverImpl.host, server.serverImpl.port ]
+ server.initServer((host, int(port)), single_use=single_use,
+ idle_timeout=configParams.idle_timeout)
+ configuration.interface = [server.serverImpl.host, server.serverImpl.port]
else:
server.initServer(single_use=single_use)
configuration.interface = []
@@ -299,20 +356,17 @@ def start_server(servermodule, configParams, configuration, features):
server.addcooker(cooker)
server.saveConnectionDetails()
except Exception as e:
- exc_info = sys.exc_info()
while hasattr(server, "event_queue"):
- try:
- import queue
- except ImportError:
- import Queue as queue
+ import queue
try:
event = server.event_queue.get(block=False)
except (queue.Empty, IOError):
break
if isinstance(event, logging.LogRecord):
logger.handle(event)
- raise exc_info[1], None, exc_info[2]
- server.detach()
+ raise
+ if not configParams.foreground:
+ server.detach()
cooker.lock.close()
return server
@@ -328,7 +382,10 @@ def bitbake_main(configParams, configuration):
# updates to log files for use with tail
try:
if sys.stdout.name == '<stdout>':
- sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
+ # Reopen with O_SYNC (unbuffered)
+ fl = fcntl.fcntl(sys.stdout.fileno(), fcntl.F_GETFL)
+ fl |= os.O_SYNC
+ fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL, fl)
except:
pass
@@ -345,10 +402,21 @@ def bitbake_main(configParams, configuration):
if not configParams.bind:
raise BBMainException("FATAL: The '--server-only' option requires a name/address "
"to bind to with the -B option.\n")
+ else:
+ try:
+ #Checking that the port is a number
+ int(configParams.bind.split(":")[1])
+ except (ValueError,IndexError):
+ raise BBMainException(
+ "FATAL: Malformed host:port bind parameter")
if configParams.remote_server:
raise BBMainException("FATAL: The '--server-only' option conflicts with %s.\n" %
("the BBSERVER environment variable" if "BBSERVER" in os.environ \
- else "the '--remote-server' option" ))
+ else "the '--remote-server' option"))
+
+ elif configParams.foreground:
+ raise BBMainException("FATAL: The '--foreground' option can only be used "
+ "with --server-only.\n")
if configParams.bind and configParams.servertype != "xmlrpc":
raise BBMainException("FATAL: If '-B' or '--bind' is defined, we must "
@@ -363,7 +431,8 @@ def bitbake_main(configParams, configuration):
"connecting to a server.\n")
if configParams.kill_server and not configParams.remote_server:
- raise BBMainException("FATAL: '--kill-server' can only be used to terminate a remote server")
+ raise BBMainException("FATAL: '--kill-server' can only be used to "
+ "terminate a remote server")
if "BBDEBUG" in os.environ:
level = int(os.environ["BBDEBUG"])
@@ -371,7 +440,7 @@ def bitbake_main(configParams, configuration):
configuration.debug = level
bb.msg.init_msgconfig(configParams.verbose, configuration.debug,
- configuration.debug_domains)
+ configuration.debug_domains)
# Ensure logging messages get sent to the UI as events
handler = bb.event.LogHandler()
@@ -399,8 +468,17 @@ def bitbake_main(configParams, configuration):
server = start_server(servermodule, configParams, configuration, featureset)
bb.event.ui_queue = []
else:
+ if os.getenv('BBSERVER') == 'autostart':
+ if configParams.remote_server == 'autostart' or \
+ not servermodule.check_connection(configParams.remote_server, timeout=2):
+ configParams.bind = 'localhost:0'
+ srv = start_server(servermodule, configParams, configuration, featureset)
+ configParams.remote_server = '%s:%d' % tuple(configuration.interface)
+ bb.event.ui_queue = []
+
# we start a stub server that is actually a XMLRPClient that connects to a real server
- server = servermodule.BitBakeXMLRPCClient(configParams.observe_only, configParams.xmlrpctoken)
+ server = servermodule.BitBakeXMLRPCClient(configParams.observe_only,
+ configParams.xmlrpctoken)
server.saveConnectionDetails(configParams.remote_server)
@@ -429,12 +507,16 @@ def bitbake_main(configParams, configuration):
return 0
try:
- return ui_module.main(server_connection.connection, server_connection.events, configParams)
+ return ui_module.main(server_connection.connection, server_connection.events,
+ configParams)
finally:
bb.event.ui_queue = []
server_connection.terminate()
else:
- print("Bitbake server address: %s, server port: %s" % (server.serverImpl.host, server.serverImpl.port))
+ print("Bitbake server address: %s, server port: %s" % (server.serverImpl.host,
+ server.serverImpl.port))
+ if configParams.foreground:
+ server.serverImpl.serve_forever()
return 0
return 1
OpenPOWER on IntegriCloud