summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorChris Laplante <chris.laplante@agilent.com>2020-11-06 09:34:55 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-11-11 10:09:18 +0000
commit1eb5b30329a01bf719f02356d5c5876ef800916f (patch)
tree2abf30b4afbe786cad07b24cb63963d8cb6d5cd1 /bitbake
parent7b94fa5d961a4d4d8b927ae7b300436886052a06 (diff)
downloadpoky-1eb5b30329a01bf719f02356d5c5876ef800916f.tar.gz
bitbake: main: extract creation of argument parser into function so it can be utilized externally, e.g. by unit tests
(Bitbake rev: 9599059672cc4ae88ba212e34336e0325d37bd75) Signed-off-by: Chris Laplante <chris.laplante@agilent.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rwxr-xr-xbitbake/lib/bb/main.py333
1 files changed, 168 insertions, 165 deletions
diff --git a/bitbake/lib/bb/main.py b/bitbake/lib/bb/main.py
index e92e409f07..06bad495ac 100755
--- a/bitbake/lib/bb/main.py
+++ b/bitbake/lib/bb/main.py
@@ -119,178 +119,181 @@ warnings.filterwarnings("ignore", category=ImportWarning)
119warnings.filterwarnings("ignore", category=DeprecationWarning, module="<string>$") 119warnings.filterwarnings("ignore", category=DeprecationWarning, module="<string>$")
120warnings.filterwarnings("ignore", message="With-statements now directly support multiple context managers") 120warnings.filterwarnings("ignore", message="With-statements now directly support multiple context managers")
121 121
122class BitBakeConfigParameters(cookerdata.ConfigParameters):
123 122
124 def parseCommandLine(self, argv=sys.argv): 123def create_bitbake_parser():
125 parser = optparse.OptionParser( 124 parser = optparse.OptionParser(
126 formatter=BitbakeHelpFormatter(), 125 formatter=BitbakeHelpFormatter(),
127 version="BitBake Build Tool Core version %s" % bb.__version__, 126 version="BitBake Build Tool Core version %s" % bb.__version__,
128 usage="""%prog [options] [recipename/target recipe:do_task ...] 127 usage="""%prog [options] [recipename/target recipe:do_task ...]
129 128
130 Executes the specified task (default is 'build') for a given set of target recipes (.bb files). 129 Executes the specified task (default is 'build') for a given set of target recipes (.bb files).
131 It is assumed there is a conf/bblayers.conf available in cwd or in BBPATH which 130 It is assumed there is a conf/bblayers.conf available in cwd or in BBPATH which
132 will provide the layer, BBFILES and other configuration information.""") 131 will provide the layer, BBFILES and other configuration information.""")
133 132
134 parser.add_option("-b", "--buildfile", action="store", dest="buildfile", default=None, 133 parser.add_option("-b", "--buildfile", action="store", dest="buildfile", default=None,
135 help="Execute tasks from a specific .bb recipe directly. WARNING: Does " 134 help="Execute tasks from a specific .bb recipe directly. WARNING: Does "
136 "not handle any dependencies from other recipes.") 135 "not handle any dependencies from other recipes.")
137 136
138 parser.add_option("-k", "--continue", action="store_false", dest="abort", default=True, 137 parser.add_option("-k", "--continue", action="store_false", dest="abort", default=True,
139 help="Continue as much as possible after an error. While the target that " 138 help="Continue as much as possible after an error. While the target that "
140 "failed and anything depending on it cannot be built, as much as " 139 "failed and anything depending on it cannot be built, as much as "
141 "possible will be built before stopping.") 140 "possible will be built before stopping.")
142 141
143 parser.add_option("-f", "--force", action="store_true", dest="force", default=False, 142 parser.add_option("-f", "--force", action="store_true", dest="force", default=False,
144 help="Force the specified targets/task to run (invalidating any " 143 help="Force the specified targets/task to run (invalidating any "
145 "existing stamp file).") 144 "existing stamp file).")
146 145
147 parser.add_option("-c", "--cmd", action="store", dest="cmd", 146 parser.add_option("-c", "--cmd", action="store", dest="cmd",
148 help="Specify the task to execute. The exact options available " 147 help="Specify the task to execute. The exact options available "
149 "depend on the metadata. Some examples might be 'compile'" 148 "depend on the metadata. Some examples might be 'compile'"
150 " or 'populate_sysroot' or 'listtasks' may give a list of " 149 " or 'populate_sysroot' or 'listtasks' may give a list of "
151 "the tasks available.") 150 "the tasks available.")
152 151
153 parser.add_option("-C", "--clear-stamp", action="store", dest="invalidate_stamp", 152 parser.add_option("-C", "--clear-stamp", action="store", dest="invalidate_stamp",
154 help="Invalidate the stamp for the specified task such as 'compile' " 153 help="Invalidate the stamp for the specified task such as 'compile' "
155 "and then run the default task for the specified target(s).") 154 "and then run the default task for the specified target(s).")
156 155
157 parser.add_option("-r", "--read", action="append", dest="prefile", default=[], 156 parser.add_option("-r", "--read", action="append", dest="prefile", default=[],
158 help="Read the specified file before bitbake.conf.") 157 help="Read the specified file before bitbake.conf.")
159 158
160 parser.add_option("-R", "--postread", action="append", dest="postfile", default=[], 159 parser.add_option("-R", "--postread", action="append", dest="postfile", default=[],
161 help="Read the specified file after bitbake.conf.") 160 help="Read the specified file after bitbake.conf.")
162 161
163 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, 162 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
164 help="Enable tracing of shell tasks (with 'set -x'). " 163 help="Enable tracing of shell tasks (with 'set -x'). "
165 "Also print bb.note(...) messages to stdout (in " 164 "Also print bb.note(...) messages to stdout (in "
166 "addition to writing them to ${T}/log.do_<task>).") 165 "addition to writing them to ${T}/log.do_<task>).")
167 166
168 parser.add_option("-D", "--debug", action="count", dest="debug", default=0, 167 parser.add_option("-D", "--debug", action="count", dest="debug", default=0,
169 help="Increase the debug level. You can specify this " 168 help="Increase the debug level. You can specify this "
170 "more than once. -D sets the debug level to 1, " 169 "more than once. -D sets the debug level to 1, "
171 "where only bb.debug(1, ...) messages are printed " 170 "where only bb.debug(1, ...) messages are printed "
172 "to stdout; -DD sets the debug level to 2, where " 171 "to stdout; -DD sets the debug level to 2, where "
173 "both bb.debug(1, ...) and bb.debug(2, ...) " 172 "both bb.debug(1, ...) and bb.debug(2, ...) "
174 "messages are printed; etc. Without -D, no debug " 173 "messages are printed; etc. Without -D, no debug "
175 "messages are printed. Note that -D only affects " 174 "messages are printed. Note that -D only affects "
176 "output to stdout. All debug messages are written " 175 "output to stdout. All debug messages are written "
177 "to ${T}/log.do_taskname, regardless of the debug " 176 "to ${T}/log.do_taskname, regardless of the debug "
178 "level.") 177 "level.")
179 178
180 parser.add_option("-q", "--quiet", action="count", dest="quiet", default=0, 179 parser.add_option("-q", "--quiet", action="count", dest="quiet", default=0,
181 help="Output less log message data to the terminal. You can specify this more than once.") 180 help="Output less log message data to the terminal. You can specify this more than once.")
182 181
183 parser.add_option("-n", "--dry-run", action="store_true", dest="dry_run", default=False, 182 parser.add_option("-n", "--dry-run", action="store_true", dest="dry_run", default=False,
184 help="Don't execute, just go through the motions.") 183 help="Don't execute, just go through the motions.")
185 184
186 parser.add_option("-S", "--dump-signatures", action="append", dest="dump_signatures", 185 parser.add_option("-S", "--dump-signatures", action="append", dest="dump_signatures",
187 default=[], metavar="SIGNATURE_HANDLER", 186 default=[], metavar="SIGNATURE_HANDLER",
188 help="Dump out the signature construction information, with no task " 187 help="Dump out the signature construction information, with no task "
189 "execution. The SIGNATURE_HANDLER parameter is passed to the " 188 "execution. The SIGNATURE_HANDLER parameter is passed to the "
190 "handler. Two common values are none and printdiff but the handler " 189 "handler. Two common values are none and printdiff but the handler "
191 "may define more/less. none means only dump the signature, printdiff" 190 "may define more/less. none means only dump the signature, printdiff"
192 " means compare the dumped signature with the cached one.") 191 " means compare the dumped signature with the cached one.")
193 192
194 parser.add_option("-p", "--parse-only", action="store_true", 193 parser.add_option("-p", "--parse-only", action="store_true",
195 dest="parse_only", default=False, 194 dest="parse_only", default=False,
196 help="Quit after parsing the BB recipes.") 195 help="Quit after parsing the BB recipes.")
197 196
198 parser.add_option("-s", "--show-versions", action="store_true", 197 parser.add_option("-s", "--show-versions", action="store_true",
199 dest="show_versions", default=False, 198 dest="show_versions", default=False,
200 help="Show current and preferred versions of all recipes.") 199 help="Show current and preferred versions of all recipes.")
201 200
202 parser.add_option("-e", "--environment", action="store_true", 201 parser.add_option("-e", "--environment", action="store_true",
203 dest="show_environment", default=False, 202 dest="show_environment", default=False,
204 help="Show the global or per-recipe environment complete with information" 203 help="Show the global or per-recipe environment complete with information"
205 " about where variables were set/changed.") 204 " about where variables were set/changed.")
206 205
207 parser.add_option("-g", "--graphviz", action="store_true", dest="dot_graph", default=False, 206 parser.add_option("-g", "--graphviz", action="store_true", dest="dot_graph", default=False,
208 help="Save dependency tree information for the specified " 207 help="Save dependency tree information for the specified "
209 "targets in the dot syntax.") 208 "targets in the dot syntax.")
210 209
211 parser.add_option("-I", "--ignore-deps", action="append", 210 parser.add_option("-I", "--ignore-deps", action="append",
212 dest="extra_assume_provided", default=[], 211 dest="extra_assume_provided", default=[],
213 help="Assume these dependencies don't exist and are already provided " 212 help="Assume these dependencies don't exist and are already provided "
214 "(equivalent to ASSUME_PROVIDED). Useful to make dependency " 213 "(equivalent to ASSUME_PROVIDED). Useful to make dependency "
215 "graphs more appealing") 214 "graphs more appealing")
216 215
217 parser.add_option("-l", "--log-domains", action="append", dest="debug_domains", default=[], 216 parser.add_option("-l", "--log-domains", action="append", dest="debug_domains", default=[],
218 help="Show debug logging for the specified logging domains") 217 help="Show debug logging for the specified logging domains")
219 218
220 parser.add_option("-P", "--profile", action="store_true", dest="profile", default=False, 219 parser.add_option("-P", "--profile", action="store_true", dest="profile", default=False,
221 help="Profile the command and save reports.") 220 help="Profile the command and save reports.")
222 221
223 # @CHOICES@ is substituted out by BitbakeHelpFormatter above 222 # @CHOICES@ is substituted out by BitbakeHelpFormatter above
224 parser.add_option("-u", "--ui", action="store", dest="ui", 223 parser.add_option("-u", "--ui", action="store", dest="ui",
225 default=os.environ.get('BITBAKE_UI', 'knotty'), 224 default=os.environ.get('BITBAKE_UI', 'knotty'),
226 help="The user interface to use (@CHOICES@ - default %default).") 225 help="The user interface to use (@CHOICES@ - default %default).")
227 226
228 parser.add_option("", "--token", action="store", dest="xmlrpctoken", 227 parser.add_option("", "--token", action="store", dest="xmlrpctoken",
229 default=os.environ.get("BBTOKEN"), 228 default=os.environ.get("BBTOKEN"),
230 help="Specify the connection token to be used when connecting " 229 help="Specify the connection token to be used when connecting "
231 "to a remote server.") 230 "to a remote server.")
232 231
233 parser.add_option("", "--revisions-changed", action="store_true", 232 parser.add_option("", "--revisions-changed", action="store_true",
234 dest="revisions_changed", default=False, 233 dest="revisions_changed", default=False,
235 help="Set the exit code depending on whether upstream floating " 234 help="Set the exit code depending on whether upstream floating "
236 "revisions have changed or not.") 235 "revisions have changed or not.")
237 236
238 parser.add_option("", "--server-only", action="store_true", 237 parser.add_option("", "--server-only", action="store_true",
239 dest="server_only", default=False, 238 dest="server_only", default=False,
240 help="Run bitbake without a UI, only starting a server " 239 help="Run bitbake without a UI, only starting a server "
241 "(cooker) process.") 240 "(cooker) process.")
242 241
243 parser.add_option("-B", "--bind", action="store", dest="bind", default=False, 242 parser.add_option("-B", "--bind", action="store", dest="bind", default=False,
244 help="The name/address for the bitbake xmlrpc server to bind to.") 243 help="The name/address for the bitbake xmlrpc server to bind to.")
245 244
246 parser.add_option("-T", "--idle-timeout", type=float, dest="server_timeout", 245 parser.add_option("-T", "--idle-timeout", type=float, dest="server_timeout",
247 default=os.getenv("BB_SERVER_TIMEOUT"), 246 default=os.getenv("BB_SERVER_TIMEOUT"),
248 help="Set timeout to unload bitbake server due to inactivity, " 247 help="Set timeout to unload bitbake server due to inactivity, "
249 "set to -1 means no unload, " 248 "set to -1 means no unload, "
250 "default: Environment variable BB_SERVER_TIMEOUT.") 249 "default: Environment variable BB_SERVER_TIMEOUT.")
251 250
252 parser.add_option("", "--no-setscene", action="store_true", 251 parser.add_option("", "--no-setscene", action="store_true",
253 dest="nosetscene", default=False, 252 dest="nosetscene", default=False,
254 help="Do not run any setscene tasks. sstate will be ignored and " 253 help="Do not run any setscene tasks. sstate will be ignored and "
255 "everything needed, built.") 254 "everything needed, built.")
256 255
257 parser.add_option("", "--skip-setscene", action="store_true", 256 parser.add_option("", "--skip-setscene", action="store_true",
258 dest="skipsetscene", default=False, 257 dest="skipsetscene", default=False,
259 help="Skip setscene tasks if they would be executed. Tasks previously " 258 help="Skip setscene tasks if they would be executed. Tasks previously "
260 "restored from sstate will be kept, unlike --no-setscene") 259 "restored from sstate will be kept, unlike --no-setscene")
261 260
262 parser.add_option("", "--setscene-only", action="store_true", 261 parser.add_option("", "--setscene-only", action="store_true",
263 dest="setsceneonly", default=False, 262 dest="setsceneonly", default=False,
264 help="Only run setscene tasks, don't run any real tasks.") 263 help="Only run setscene tasks, don't run any real tasks.")
265 264
266 parser.add_option("", "--remote-server", action="store", dest="remote_server", 265 parser.add_option("", "--remote-server", action="store", dest="remote_server",
267 default=os.environ.get("BBSERVER"), 266 default=os.environ.get("BBSERVER"),
268 help="Connect to the specified server.") 267 help="Connect to the specified server.")
269 268
270 parser.add_option("-m", "--kill-server", action="store_true", 269 parser.add_option("-m", "--kill-server", action="store_true",
271 dest="kill_server", default=False, 270 dest="kill_server", default=False,
272 help="Terminate any running bitbake server.") 271 help="Terminate any running bitbake server.")
273 272
274 parser.add_option("", "--observe-only", action="store_true", 273 parser.add_option("", "--observe-only", action="store_true",
275 dest="observe_only", default=False, 274 dest="observe_only", default=False,
276 help="Connect to a server as an observing-only client.") 275 help="Connect to a server as an observing-only client.")
277 276
278 parser.add_option("", "--status-only", action="store_true", 277 parser.add_option("", "--status-only", action="store_true",
279 dest="status_only", default=False, 278 dest="status_only", default=False,
280 help="Check the status of the remote bitbake server.") 279 help="Check the status of the remote bitbake server.")
281 280
282 parser.add_option("-w", "--write-log", action="store", dest="writeeventlog", 281 parser.add_option("-w", "--write-log", action="store", dest="writeeventlog",
283 default=os.environ.get("BBEVENTLOG"), 282 default=os.environ.get("BBEVENTLOG"),
284 help="Writes the event log of the build to a bitbake event json file. " 283 help="Writes the event log of the build to a bitbake event json file. "
285 "Use '' (empty string) to assign the name automatically.") 284 "Use '' (empty string) to assign the name automatically.")
286 285
287 parser.add_option("", "--runall", action="append", dest="runall", 286 parser.add_option("", "--runall", action="append", dest="runall",
288 help="Run the specified task for any recipe in the taskgraph of the specified target (even if it wouldn't otherwise have run).") 287 help="Run the specified task for any recipe in the taskgraph of the specified target (even if it wouldn't otherwise have run).")
289 288
290 parser.add_option("", "--runonly", action="append", dest="runonly", 289 parser.add_option("", "--runonly", action="append", dest="runonly",
291 help="Run only the specified task within the taskgraph of the specified targets (and any task dependencies those tasks may have).") 290 help="Run only the specified task within the taskgraph of the specified targets (and any task dependencies those tasks may have).")
291 return parser
292 292
293 293
294class BitBakeConfigParameters(cookerdata.ConfigParameters):
295 def parseCommandLine(self, argv=sys.argv):
296 parser = create_bitbake_parser()
294 options, targets = parser.parse_args(argv) 297 options, targets = parser.parse_args(argv)
295 298
296 if options.quiet and options.verbose: 299 if options.quiet and options.verbose:
@@ -466,7 +469,7 @@ def setup_bitbake(configParams, extrafeatures=None):
466 logger.info("Retrying server connection (#%d)..." % tryno) 469 logger.info("Retrying server connection (#%d)..." % tryno)
467 else: 470 else:
468 logger.info("Retrying server connection (#%d)... (%s)" % (tryno, traceback.format_exc())) 471 logger.info("Retrying server connection (#%d)... (%s)" % (tryno, traceback.format_exc()))
469 472
470 if not retries: 473 if not retries:
471 bb.fatal("Unable to connect to bitbake server, or start one (server startup failures would be in bitbake-cookerdaemon.log).") 474 bb.fatal("Unable to connect to bitbake server, or start one (server startup failures would be in bitbake-cookerdaemon.log).")
472 bb.event.print_ui_queue() 475 bb.event.print_ui_queue()