bitbake 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. # Copyright (C) 2003, 2004 Chris Larson
  6. # Copyright (C) 2003, 2004 Phil Blundell
  7. # Copyright (C) 2003 - 2005 Michael 'Mickey' Lauer
  8. # Copyright (C) 2005 Holger Hans Peter Freyther
  9. # Copyright (C) 2005 ROAD GmbH
  10. # Copyright (C) 2006 Richard Purdie
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License version 2 as
  14. # published by the Free Software Foundation.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License along
  22. # with this program; if not, write to the Free Software Foundation, Inc.,
  23. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. import os
  25. import sys
  26. sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])),
  27. 'lib'))
  28. import optparse
  29. import warnings
  30. from traceback import format_exception
  31. import bb
  32. import bb.msg
  33. from bb import cooker
  34. from bb import ui
  35. from bb import server
  36. from bb.server import none
  37. #from bb.server import xmlrpc
  38. __version__ = "1.11.0"
  39. #============================================================================#
  40. # BBOptions
  41. #============================================================================#
  42. class BBConfiguration(object):
  43. """
  44. Manages build options and configurations for one run
  45. """
  46. def __init__(self, options):
  47. for key, val in options.__dict__.items():
  48. setattr(self, key, val)
  49. self.pkgs_to_build = []
  50. def print_exception(exc, value, tb):
  51. """Send exception information through bb.msg"""
  52. bb.fatal("".join(format_exception(exc, value, tb, limit=8)))
  53. sys.excepthook = print_exception
  54. _warnings_showwarning = warnings.showwarning
  55. def _showwarning(message, category, filename, lineno, file=None, line=None):
  56. """Display python warning messages using bb.msg"""
  57. if file is not None:
  58. if _warnings_showwarning is not None:
  59. _warnings_showwarning(message, category, filename, lineno, file, line)
  60. else:
  61. s = warnings.formatwarning(message, category, filename, lineno)
  62. s = s.split("\n")[0]
  63. bb.msg.warn(None, s)
  64. warnings.showwarning = _showwarning
  65. warnings.simplefilter("ignore", DeprecationWarning)
  66. #============================================================================#
  67. # main
  68. #============================================================================#
  69. def main():
  70. return_value = 1
  71. parser = optparse.OptionParser(
  72. version = "BitBake Build Tool Core version %s, %%prog version %s" % (bb.__version__, __version__),
  73. usage = """%prog [options] [package ...]
  74. Executes the specified task (default is 'build') for a given set of BitBake files.
  75. It expects that BBFILES is defined, which is a space separated list of files to
  76. be executed. BBFILES does support wildcards.
  77. Default BBFILES are the .bb files in the current directory.""")
  78. parser.add_option("-b", "--buildfile", help = "execute the task against this .bb file, rather than a package from BBFILES.",
  79. action = "store", dest = "buildfile", default = None)
  80. 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.",
  81. action = "store_false", dest = "abort", default = True)
  82. parser.add_option("-a", "--tryaltconfigs", help = "continue with builds by trying to use alternative providers where possible.",
  83. action = "store_true", dest = "tryaltconfigs", default = False)
  84. parser.add_option("-f", "--force", help = "force run of specified cmd, regardless of stamp status",
  85. action = "store_true", dest = "force", default = False)
  86. 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",
  87. action = "store", dest = "cmd")
  88. parser.add_option("-r", "--read", help = "read the specified file before bitbake.conf",
  89. action = "append", dest = "file", default = [])
  90. parser.add_option("-v", "--verbose", help = "output more chit-chat to the terminal",
  91. action = "store_true", dest = "verbose", default = False)
  92. parser.add_option("-D", "--debug", help = "Increase the debug level. You can specify this more than once.",
  93. action = "count", dest="debug", default = 0)
  94. parser.add_option("-n", "--dry-run", help = "don't execute, just go through the motions",
  95. action = "store_true", dest = "dry_run", default = False)
  96. parser.add_option("-p", "--parse-only", help = "quit after parsing the BB files (developers only)",
  97. action = "store_true", dest = "parse_only", default = False)
  98. parser.add_option("-d", "--disable-psyco", help = "disable using the psyco just-in-time compiler (not recommended)",
  99. action = "store_true", dest = "disable_psyco", default = False)
  100. parser.add_option("-s", "--show-versions", help = "show current and preferred versions of all packages",
  101. action = "store_true", dest = "show_versions", default = False)
  102. parser.add_option("-e", "--environment", help = "show the global or per-package environment (this is what used to be bbread)",
  103. action = "store_true", dest = "show_environment", default = False)
  104. parser.add_option("-g", "--graphviz", help = "emit the dependency trees of the specified packages in the dot syntax",
  105. action = "store_true", dest = "dot_graph", default = False)
  106. 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""",
  107. action = "append", dest = "extra_assume_provided", default = [])
  108. parser.add_option("-l", "--log-domains", help = """Show debug logging for the specified logging domains""",
  109. action = "append", dest = "debug_domains", default = [])
  110. parser.add_option("-P", "--profile", help = "profile the command and print a report",
  111. action = "store_true", dest = "profile", default = False)
  112. parser.add_option("-u", "--ui", help = "userinterface to use",
  113. action = "store", dest = "ui")
  114. parser.add_option("", "--revisions-changed", help = "Set the exit code depending on whether upstream floating revisions have changed or not",
  115. action = "store_true", dest = "revisions_changed", default = False)
  116. options, args = parser.parse_args(sys.argv)
  117. configuration = BBConfiguration(options)
  118. configuration.pkgs_to_build.extend(args[1:])
  119. #server = bb.server.xmlrpc
  120. server = bb.server.none
  121. # Save a logfile for cooker into the current working directory. When the
  122. # server is daemonized this logfile will be truncated.
  123. cooker_logfile = os.path.join(os.getcwd(), "cooker.log")
  124. bb.utils.init_logger(bb.msg, configuration.verbose, configuration.debug,
  125. configuration.debug_domains)
  126. # Clear away any spurious environment variables. But don't wipe the
  127. # environment totally. This is necessary to ensure the correct operation
  128. # of the UIs (e.g. for DISPLAY, etc.)
  129. bb.utils.clean_environment()
  130. cooker = bb.cooker.BBCooker(configuration, server)
  131. cooker.parseCommandLine()
  132. serverinfo = server.BitbakeServerInfo(cooker.server)
  133. server.BitBakeServerFork(serverinfo, cooker.serve, cooker_logfile)
  134. del cooker
  135. # Setup a connection to the server (cooker)
  136. serverConnection = server.BitBakeServerConnection(serverinfo)
  137. # Launch the UI
  138. if configuration.ui:
  139. ui = configuration.ui
  140. else:
  141. ui = "knotty"
  142. try:
  143. # Dynamically load the UI based on the ui name. Although we
  144. # suggest a fixed set this allows you to have flexibility in which
  145. # ones are available.
  146. uimodule = __import__("bb.ui", fromlist = [ui])
  147. ui_init = getattr(uimodule, ui).init
  148. except AttributeError:
  149. print("FATAL: Invalid user interface '%s' specified. " % ui)
  150. print("Valid interfaces are 'ncurses', 'depexp' or the default, 'knotty'.")
  151. else:
  152. return_value = ui_init(serverConnection.connection, serverConnection.events)
  153. finally:
  154. serverConnection.terminate()
  155. return return_value
  156. if __name__ == "__main__":
  157. ret = main()
  158. sys.exit(ret)