diff options
| -rwxr-xr-x | bitbake/lib/bb/main.py | 346 |
1 files changed, 175 insertions, 171 deletions
diff --git a/bitbake/lib/bb/main.py b/bitbake/lib/bb/main.py index ed3e1ede61..70b3845aab 100755 --- a/bitbake/lib/bb/main.py +++ b/bitbake/lib/bb/main.py | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | import os | 12 | import os |
| 13 | import sys | 13 | import sys |
| 14 | import logging | 14 | import logging |
| 15 | import optparse | 15 | import argparse |
| 16 | import warnings | 16 | import warnings |
| 17 | import fcntl | 17 | import fcntl |
| 18 | import time | 18 | import time |
| @@ -44,18 +44,18 @@ def present_options(optionlist): | |||
| 44 | else: | 44 | else: |
| 45 | return optionlist[0] | 45 | return optionlist[0] |
| 46 | 46 | ||
| 47 | class BitbakeHelpFormatter(optparse.IndentedHelpFormatter): | 47 | class BitbakeHelpFormatter(argparse.HelpFormatter): |
| 48 | def format_option(self, option): | 48 | def _get_help_string(self, action): |
| 49 | # We need to do this here rather than in the text we supply to | 49 | # We need to do this here rather than in the text we supply to |
| 50 | # add_option() because we don't want to call list_extension_modules() | 50 | # add_option() because we don't want to call list_extension_modules() |
| 51 | # on every execution (since it imports all of the modules) | 51 | # on every execution (since it imports all of the modules) |
| 52 | # Note also that we modify option.help rather than the returned text | 52 | # Note also that we modify option.help rather than the returned text |
| 53 | # - this is so that we don't have to re-format the text ourselves | 53 | # - this is so that we don't have to re-format the text ourselves |
| 54 | if option.dest == 'ui': | 54 | if action.dest == 'ui': |
| 55 | valid_uis = list_extension_modules(bb.ui, 'main') | 55 | valid_uis = list_extension_modules(bb.ui, 'main') |
| 56 | option.help = option.help.replace('@CHOICES@', present_options(valid_uis)) | 56 | return action.help.replace('@CHOICES@', present_options(valid_uis)) |
| 57 | 57 | ||
| 58 | return optparse.IndentedHelpFormatter.format_option(self, option) | 58 | return action.help |
| 59 | 59 | ||
| 60 | def list_extension_modules(pkg, checkattr): | 60 | def list_extension_modules(pkg, checkattr): |
| 61 | """ | 61 | """ |
| @@ -115,180 +115,184 @@ def _showwarning(message, category, filename, lineno, file=None, line=None): | |||
| 115 | warnings.showwarning = _showwarning | 115 | warnings.showwarning = _showwarning |
| 116 | 116 | ||
| 117 | def create_bitbake_parser(): | 117 | def create_bitbake_parser(): |
| 118 | parser = optparse.OptionParser( | 118 | parser = argparse.ArgumentParser( |
| 119 | formatter=BitbakeHelpFormatter(), | 119 | description="""\ |
| 120 | version="BitBake Build Tool Core version %s" % bb.__version__, | 120 | It is assumed there is a conf/bblayers.conf available in cwd or in BBPATH which |
| 121 | usage="""%prog [options] [recipename/target recipe:do_task ...] | 121 | will provide the layer, BBFILES and other configuration information. |
| 122 | 122 | """, | |
| 123 | Executes the specified task (default is 'build') for a given set of target recipes (.bb files). | 123 | formatter_class=BitbakeHelpFormatter, |
| 124 | It is assumed there is a conf/bblayers.conf available in cwd or in BBPATH which | 124 | allow_abbrev=False, |
| 125 | will provide the layer, BBFILES and other configuration information.""") | 125 | ) |
| 126 | 126 | ||
| 127 | parser.add_option("-b", "--buildfile", action="store", dest="buildfile", default=None, | 127 | parser.add_argument("--version", action="store_true", |
| 128 | help="Execute tasks from a specific .bb recipe directly. WARNING: Does " | 128 | help="Show programs version and exit") |
| 129 | "not handle any dependencies from other recipes.") | 129 | |
| 130 | 130 | parser.add_argument("-b", "--buildfile", | |
| 131 | parser.add_option("-k", "--continue", action="store_false", dest="halt", default=True, | 131 | help="Execute tasks from a specific .bb recipe directly. WARNING: Does " |
| 132 | help="Continue as much as possible after an error. While the target that " | 132 | "not handle any dependencies from other recipes.") |
| 133 | "failed and anything depending on it cannot be built, as much as " | 133 | |
| 134 | "possible will be built before stopping.") | 134 | parser.add_argument("-k", "--continue", action="store_false", dest="halt", |
| 135 | 135 | help="Continue as much as possible after an error. While the target that " | |
| 136 | parser.add_option("-f", "--force", action="store_true", dest="force", default=False, | 136 | "failed and anything depending on it cannot be built, as much as " |
| 137 | help="Force the specified targets/task to run (invalidating any " | 137 | "possible will be built before stopping.") |
| 138 | "existing stamp file).") | 138 | |
| 139 | 139 | parser.add_argument("-f", "--force", action="store_true", | |
| 140 | parser.add_option("-c", "--cmd", action="store", dest="cmd", | 140 | help="Force the specified targets/task to run (invalidating any " |
| 141 | help="Specify the task to execute. The exact options available " | 141 | "existing stamp file).") |
| 142 | "depend on the metadata. Some examples might be 'compile'" | 142 | |
| 143 | " or 'populate_sysroot' or 'listtasks' may give a list of " | 143 | parser.add_argument("-c", "--cmd", |
| 144 | "the tasks available.") | 144 | help="Specify the task to execute. The exact options available " |
| 145 | 145 | "depend on the metadata. Some examples might be 'compile'" | |
| 146 | parser.add_option("-C", "--clear-stamp", action="store", dest="invalidate_stamp", | 146 | " or 'populate_sysroot' or 'listtasks' may give a list of " |
| 147 | help="Invalidate the stamp for the specified task such as 'compile' " | 147 | "the tasks available.") |
| 148 | "and then run the default task for the specified target(s).") | 148 | |
| 149 | 149 | parser.add_argument("-C", "--clear-stamp", dest="invalidate_stamp", | |
| 150 | parser.add_option("-r", "--read", action="append", dest="prefile", default=[], | 150 | help="Invalidate the stamp for the specified task such as 'compile' " |
| 151 | help="Read the specified file before bitbake.conf.") | 151 | "and then run the default task for the specified target(s).") |
| 152 | 152 | ||
| 153 | parser.add_option("-R", "--postread", action="append", dest="postfile", default=[], | 153 | parser.add_argument("-r", "--read", action="append", dest="prefile", default=[], |
| 154 | help="Read the specified file after bitbake.conf.") | 154 | help="Read the specified file before bitbake.conf.") |
| 155 | 155 | ||
| 156 | parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, | 156 | parser.add_argument("-R", "--postread", action="append", dest="postfile", default=[], |
| 157 | help="Enable tracing of shell tasks (with 'set -x'). " | 157 | help="Read the specified file after bitbake.conf.") |
| 158 | "Also print bb.note(...) messages to stdout (in " | 158 | |
| 159 | "addition to writing them to ${T}/log.do_<task>).") | 159 | parser.add_argument("-v", "--verbose", action="store_true", |
| 160 | 160 | help="Enable tracing of shell tasks (with 'set -x'). " | |
| 161 | parser.add_option("-D", "--debug", action="count", dest="debug", default=0, | 161 | "Also print bb.note(...) messages to stdout (in " |
| 162 | help="Increase the debug level. You can specify this " | 162 | "addition to writing them to ${T}/log.do_<task>).") |
| 163 | "more than once. -D sets the debug level to 1, " | 163 | |
| 164 | "where only bb.debug(1, ...) messages are printed " | 164 | parser.add_argument("-D", "--debug", action="count", default=0, |
| 165 | "to stdout; -DD sets the debug level to 2, where " | 165 | help="Increase the debug level. You can specify this " |
| 166 | "both bb.debug(1, ...) and bb.debug(2, ...) " | 166 | "more than once. -D sets the debug level to 1, " |
| 167 | "messages are printed; etc. Without -D, no debug " | 167 | "where only bb.debug(1, ...) messages are printed " |
| 168 | "messages are printed. Note that -D only affects " | 168 | "to stdout; -DD sets the debug level to 2, where " |
| 169 | "output to stdout. All debug messages are written " | 169 | "both bb.debug(1, ...) and bb.debug(2, ...) " |
| 170 | "to ${T}/log.do_taskname, regardless of the debug " | 170 | "messages are printed; etc. Without -D, no debug " |
| 171 | "level.") | 171 | "messages are printed. Note that -D only affects " |
| 172 | 172 | "output to stdout. All debug messages are written " | |
| 173 | parser.add_option("-q", "--quiet", action="count", dest="quiet", default=0, | 173 | "to ${T}/log.do_taskname, regardless of the debug " |
| 174 | help="Output less log message data to the terminal. You can specify this more than once.") | 174 | "level.") |
| 175 | 175 | ||
| 176 | parser.add_option("-n", "--dry-run", action="store_true", dest="dry_run", default=False, | 176 | parser.add_argument("-q", "--quiet", action="count", default=0, |
| 177 | help="Don't execute, just go through the motions.") | 177 | help="Output less log message data to the terminal. You can specify this more than once.") |
| 178 | 178 | ||
| 179 | parser.add_option("-S", "--dump-signatures", action="append", dest="dump_signatures", | 179 | parser.add_argument("-n", "--dry-run", action="store_true", |
| 180 | default=[], metavar="SIGNATURE_HANDLER", | 180 | help="Don't execute, just go through the motions.") |
| 181 | help="Dump out the signature construction information, with no task " | 181 | |
| 182 | "execution. The SIGNATURE_HANDLER parameter is passed to the " | 182 | parser.add_argument("-S", "--dump-signatures", action="append", |
| 183 | "handler. Two common values are none and printdiff but the handler " | 183 | default=[], metavar="SIGNATURE_HANDLER", |
| 184 | "may define more/less. none means only dump the signature, printdiff" | 184 | help="Dump out the signature construction information, with no task " |
| 185 | " means compare the dumped signature with the cached one.") | 185 | "execution. The SIGNATURE_HANDLER parameter is passed to the " |
| 186 | 186 | "handler. Two common values are none and printdiff but the handler " | |
| 187 | parser.add_option("-p", "--parse-only", action="store_true", | 187 | "may define more/less. none means only dump the signature, printdiff" |
| 188 | dest="parse_only", default=False, | 188 | " means compare the dumped signature with the cached one.") |
| 189 | help="Quit after parsing the BB recipes.") | 189 | |
| 190 | 190 | parser.add_argument("-p", "--parse-only", action="store_true", | |
| 191 | parser.add_option("-s", "--show-versions", action="store_true", | 191 | help="Quit after parsing the BB recipes.") |
| 192 | dest="show_versions", default=False, | 192 | |
| 193 | help="Show current and preferred versions of all recipes.") | 193 | parser.add_argument("-s", "--show-versions", action="store_true", |
| 194 | 194 | help="Show current and preferred versions of all recipes.") | |
| 195 | parser.add_option("-e", "--environment", action="store_true", | 195 | |
| 196 | dest="show_environment", default=False, | 196 | parser.add_argument("-e", "--environment", action="store_true", |
| 197 | help="Show the global or per-recipe environment complete with information" | 197 | dest="show_environment", |
| 198 | " about where variables were set/changed.") | 198 | help="Show the global or per-recipe environment complete with information" |
| 199 | 199 | " about where variables were set/changed.") | |
| 200 | parser.add_option("-g", "--graphviz", action="store_true", dest="dot_graph", default=False, | 200 | |
| 201 | help="Save dependency tree information for the specified " | 201 | parser.add_argument("-g", "--graphviz", action="store_true", dest="dot_graph", |
| 202 | "targets in the dot syntax.") | 202 | help="Save dependency tree information for the specified " |
| 203 | 203 | "targets in the dot syntax.") | |
| 204 | parser.add_option("-I", "--ignore-deps", action="append", | 204 | |
| 205 | dest="extra_assume_provided", default=[], | 205 | parser.add_argument("-I", "--ignore-deps", action="append", |
| 206 | help="Assume these dependencies don't exist and are already provided " | 206 | dest="extra_assume_provided", default=[], |
| 207 | "(equivalent to ASSUME_PROVIDED). Useful to make dependency " | 207 | help="Assume these dependencies don't exist and are already provided " |
| 208 | "graphs more appealing") | 208 | "(equivalent to ASSUME_PROVIDED). Useful to make dependency " |
| 209 | 209 | "graphs more appealing") | |
| 210 | parser.add_option("-l", "--log-domains", action="append", dest="debug_domains", default=[], | 210 | |
| 211 | help="Show debug logging for the specified logging domains") | 211 | parser.add_argument("-l", "--log-domains", action="append", dest="debug_domains", default=[], |
| 212 | 212 | help="Show debug logging for the specified logging domains") | |
| 213 | parser.add_option("-P", "--profile", action="store_true", dest="profile", default=False, | 213 | |
| 214 | help="Profile the command and save reports.") | 214 | parser.add_argument("-P", "--profile", action="store_true", |
| 215 | help="Profile the command and save reports.") | ||
| 215 | 216 | ||
| 216 | # @CHOICES@ is substituted out by BitbakeHelpFormatter above | 217 | # @CHOICES@ is substituted out by BitbakeHelpFormatter above |
| 217 | parser.add_option("-u", "--ui", action="store", dest="ui", | 218 | parser.add_argument("-u", "--ui", |
| 218 | default=os.environ.get('BITBAKE_UI', 'knotty'), | 219 | default=os.environ.get('BITBAKE_UI', 'knotty'), |
| 219 | help="The user interface to use (@CHOICES@ - default %default).") | 220 | help="The user interface to use (@CHOICES@ - default %(default)s).") |
| 220 | 221 | ||
| 221 | parser.add_option("", "--token", action="store", dest="xmlrpctoken", | 222 | parser.add_argument("--token", dest="xmlrpctoken", |
| 222 | default=os.environ.get("BBTOKEN"), | 223 | default=os.environ.get("BBTOKEN"), |
| 223 | help="Specify the connection token to be used when connecting " | 224 | help="Specify the connection token to be used when connecting " |
| 224 | "to a remote server.") | 225 | "to a remote server.") |
| 225 | 226 | ||
| 226 | parser.add_option("", "--revisions-changed", action="store_true", | 227 | parser.add_argument("--revisions-changed", action="store_true", |
| 227 | dest="revisions_changed", default=False, | 228 | help="Set the exit code depending on whether upstream floating " |
| 228 | help="Set the exit code depending on whether upstream floating " | 229 | "revisions have changed or not.") |
| 229 | "revisions have changed or not.") | 230 | |
| 230 | 231 | parser.add_argument("--server-only", action="store_true", | |
| 231 | parser.add_option("", "--server-only", action="store_true", | 232 | help="Run bitbake without a UI, only starting a server " |
| 232 | dest="server_only", default=False, | 233 | "(cooker) process.") |
| 233 | help="Run bitbake without a UI, only starting a server " | 234 | |
| 234 | "(cooker) process.") | 235 | parser.add_argument("-B", "--bind", default=False, |
| 235 | 236 | help="The name/address for the bitbake xmlrpc server to bind to.") | |
| 236 | parser.add_option("-B", "--bind", action="store", dest="bind", default=False, | 237 | |
| 237 | help="The name/address for the bitbake xmlrpc server to bind to.") | 238 | parser.add_argument("-T", "--idle-timeout", type=float, dest="server_timeout", |
| 238 | 239 | default=os.getenv("BB_SERVER_TIMEOUT"), | |
| 239 | parser.add_option("-T", "--idle-timeout", type=float, dest="server_timeout", | 240 | help="Set timeout to unload bitbake server due to inactivity, " |
| 240 | default=os.getenv("BB_SERVER_TIMEOUT"), | 241 | "set to -1 means no unload, " |
| 241 | help="Set timeout to unload bitbake server due to inactivity, " | 242 | "default: Environment variable BB_SERVER_TIMEOUT.") |
| 242 | "set to -1 means no unload, " | 243 | |
| 243 | "default: Environment variable BB_SERVER_TIMEOUT.") | 244 | parser.add_argument("--no-setscene", action="store_true", |
| 244 | 245 | dest="nosetscene", | |
| 245 | parser.add_option("", "--no-setscene", action="store_true", | 246 | help="Do not run any setscene tasks. sstate will be ignored and " |
| 246 | dest="nosetscene", default=False, | 247 | "everything needed, built.") |
| 247 | help="Do not run any setscene tasks. sstate will be ignored and " | 248 | |
| 248 | "everything needed, built.") | 249 | parser.add_argument("--skip-setscene", action="store_true", |
| 249 | 250 | dest="skipsetscene", | |
| 250 | parser.add_option("", "--skip-setscene", action="store_true", | 251 | help="Skip setscene tasks if they would be executed. Tasks previously " |
| 251 | dest="skipsetscene", default=False, | 252 | "restored from sstate will be kept, unlike --no-setscene") |
| 252 | help="Skip setscene tasks if they would be executed. Tasks previously " | 253 | |
| 253 | "restored from sstate will be kept, unlike --no-setscene") | 254 | parser.add_argument("--setscene-only", action="store_true", |
| 254 | 255 | dest="setsceneonly", | |
| 255 | parser.add_option("", "--setscene-only", action="store_true", | 256 | help="Only run setscene tasks, don't run any real tasks.") |
| 256 | dest="setsceneonly", default=False, | 257 | |
| 257 | help="Only run setscene tasks, don't run any real tasks.") | 258 | parser.add_argument("--remote-server", |
| 258 | 259 | default=os.environ.get("BBSERVER"), | |
| 259 | parser.add_option("", "--remote-server", action="store", dest="remote_server", | 260 | help="Connect to the specified server.") |
| 260 | default=os.environ.get("BBSERVER"), | 261 | |
| 261 | help="Connect to the specified server.") | 262 | parser.add_argument("-m", "--kill-server", action="store_true", |
| 262 | 263 | help="Terminate any running bitbake server.") | |
| 263 | parser.add_option("-m", "--kill-server", action="store_true", | 264 | |
| 264 | dest="kill_server", default=False, | 265 | parser.add_argument("--observe-only", action="store_true", |
| 265 | help="Terminate any running bitbake server.") | 266 | help="Connect to a server as an observing-only client.") |
| 266 | 267 | ||
| 267 | parser.add_option("", "--observe-only", action="store_true", | 268 | parser.add_argument("--status-only", action="store_true", |
| 268 | dest="observe_only", default=False, | 269 | help="Check the status of the remote bitbake server.") |
| 269 | help="Connect to a server as an observing-only client.") | 270 | |
| 270 | 271 | parser.add_argument("-w", "--write-log", dest="writeeventlog", | |
| 271 | parser.add_option("", "--status-only", action="store_true", | 272 | default=os.environ.get("BBEVENTLOG"), |
| 272 | dest="status_only", default=False, | 273 | help="Writes the event log of the build to a bitbake event json file. " |
| 273 | help="Check the status of the remote bitbake server.") | 274 | "Use '' (empty string) to assign the name automatically.") |
| 274 | 275 | ||
| 275 | parser.add_option("-w", "--write-log", action="store", dest="writeeventlog", | 276 | parser.add_argument("--runall", action="append", default=[], |
| 276 | default=os.environ.get("BBEVENTLOG"), | ||
| 277 | help="Writes the event log of the build to a bitbake event json file. " | ||
| 278 | "Use '' (empty string) to assign the name automatically.") | ||
| 279 | |||
| 280 | parser.add_option("", "--runall", action="append", dest="runall", | ||
| 281 | help="Run the specified task for any recipe in the taskgraph of the specified target (even if it wouldn't otherwise have run).") | 277 | help="Run the specified task for any recipe in the taskgraph of the specified target (even if it wouldn't otherwise have run).") |
| 282 | 278 | ||
| 283 | parser.add_option("", "--runonly", action="append", dest="runonly", | 279 | parser.add_argument("--runonly", action="append", |
| 284 | help="Run only the specified task within the taskgraph of the specified targets (and any task dependencies those tasks may have).") | 280 | help="Run only the specified task within the taskgraph of the specified targets (and any task dependencies those tasks may have).") |
| 281 | |||
| 282 | parser.add_argument("targets", nargs="*", metavar="recipename/target", | ||
| 283 | help="Execute the specified task (default is 'build') for these target recipes (.bb files).") | ||
| 284 | |||
| 285 | return parser | 285 | return parser |
| 286 | 286 | ||
| 287 | 287 | ||
| 288 | class BitBakeConfigParameters(cookerdata.ConfigParameters): | 288 | class BitBakeConfigParameters(cookerdata.ConfigParameters): |
| 289 | def parseCommandLine(self, argv=sys.argv): | 289 | def parseCommandLine(self, argv=sys.argv): |
| 290 | parser = create_bitbake_parser() | 290 | parser = create_bitbake_parser() |
| 291 | options, targets = parser.parse_args(argv) | 291 | options = parser.parse_intermixed_args(argv[1:]) |
| 292 | |||
| 293 | if options.version: | ||
| 294 | print("BitBake Build Tool Core version %s" % bb.__version__) | ||
| 295 | sys.exit(0) | ||
| 292 | 296 | ||
| 293 | if options.quiet and options.verbose: | 297 | if options.quiet and options.verbose: |
| 294 | parser.error("options --quiet and --verbose are mutually exclusive") | 298 | parser.error("options --quiet and --verbose are mutually exclusive") |
| @@ -320,7 +324,7 @@ class BitBakeConfigParameters(cookerdata.ConfigParameters): | |||
| 320 | else: | 324 | else: |
| 321 | options.xmlrpcinterface = (None, 0) | 325 | options.xmlrpcinterface = (None, 0) |
| 322 | 326 | ||
| 323 | return options, targets[1:] | 327 | return options, options.targets |
| 324 | 328 | ||
| 325 | 329 | ||
| 326 | def bitbake_main(configParams, configuration): | 330 | def bitbake_main(configParams, configuration): |
