| ... |
... |
@@ -204,7 +204,7 @@ def workdir(source_cache=None): |
|
204
|
204
|
yield (tempdir, bst_config_file, source_cache)
|
|
205
|
205
|
|
|
206
|
206
|
|
|
207
|
|
-# run_command()
|
|
|
207
|
+# run_bst_command()
|
|
208
|
208
|
#
|
|
209
|
209
|
# Runs a command
|
|
210
|
210
|
#
|
| ... |
... |
@@ -216,10 +216,30 @@ def workdir(source_cache=None): |
|
216
|
216
|
# Returns:
|
|
217
|
217
|
# (str): The colorized combined stdout/stderr of BuildStream
|
|
218
|
218
|
#
|
|
219
|
|
-def run_command(config_file, directory, command):
|
|
220
|
|
- click.echo("Running command in directory '{}': bst {}".format(directory, command), err=True)
|
|
|
219
|
+def run_bst_command(config_file, directory, command):
|
|
|
220
|
+ click.echo("Running bst command in directory '{}': bst {}".format(directory, command), err=True)
|
|
221
|
221
|
|
|
222
|
|
- argv = ['bst', '--colors', '--config', config_file] + shlex.split(command)
|
|
|
222
|
+ argv = ['python3', '-m', 'buildstream', '--colors', '--config', config_file] + shlex.split(command)
|
|
|
223
|
+ p = subprocess.Popen(argv, cwd=directory, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
224
|
+ out, _ = p.communicate()
|
|
|
225
|
+ return out.decode('utf-8').strip()
|
|
|
226
|
+
|
|
|
227
|
+
|
|
|
228
|
+# run_shell_command()
|
|
|
229
|
+#
|
|
|
230
|
+# Runs a command
|
|
|
231
|
+#
|
|
|
232
|
+# Args:
|
|
|
233
|
+# directory (str): The project directory
|
|
|
234
|
+# command (str): A shell command
|
|
|
235
|
+#
|
|
|
236
|
+# Returns:
|
|
|
237
|
+# (str): The combined stdout/stderr of the shell command
|
|
|
238
|
+#
|
|
|
239
|
+def run_shell_command(directory, command):
|
|
|
240
|
+ click.echo("Running shell command in directory '{}': {}".format(directory, command), err=True)
|
|
|
241
|
+
|
|
|
242
|
+ argv = shlex.split(command)
|
|
223
|
243
|
p = subprocess.Popen(argv, cwd=directory, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
224
|
244
|
out, _ = p.communicate()
|
|
225
|
245
|
return out.decode('utf-8').strip()
|
| ... |
... |
@@ -373,12 +393,18 @@ def run_session(description, tempdir, source_cache, palette, config_file, force) |
|
373
|
393
|
# Get the command string
|
|
374
|
394
|
command_str = _yaml.node_get(command, str, 'command')
|
|
375
|
395
|
|
|
|
396
|
+ # Check whether this is a shell command and not a bst command
|
|
|
397
|
+ is_shell = _yaml.node_get(command, bool, 'shell', default_value=False)
|
|
|
398
|
+
|
|
376
|
399
|
# Check if there is fake output
|
|
377
|
400
|
command_fake_output = _yaml.node_get(command, str, 'fake-output', default_value=None)
|
|
378
|
401
|
|
|
379
|
402
|
# Run the command, or just use the fake output
|
|
380
|
403
|
if command_fake_output is None:
|
|
381
|
|
- command_out = run_command(config_file, directory, command_str)
|
|
|
404
|
+ if is_shell:
|
|
|
405
|
+ command_out = run_shell_command(directory, command_str)
|
|
|
406
|
+ else:
|
|
|
407
|
+ command_out = run_bst_command(config_file, directory, command_str)
|
|
382
|
408
|
else:
|
|
383
|
409
|
command_out = command_fake_output
|
|
384
|
410
|
|
| ... |
... |
@@ -414,14 +440,8 @@ def run_session(description, tempdir, source_cache, palette, config_file, force) |
|
414
|
440
|
@click.option('--palette', '-p', default='tango',
|
|
415
|
441
|
type=click.Choice(['solarized', 'solarized-xterm', 'tango', 'xterm', 'console']),
|
|
416
|
442
|
help="Selects a palette for the output style")
|
|
417
|
|
-@click.option('--output', '-o',
|
|
418
|
|
- type=click.Path(file_okay=True, dir_okay=False, writable=True),
|
|
419
|
|
- help="A file to store the output")
|
|
420
|
|
-@click.option('--description', '-d',
|
|
421
|
|
- type=click.Path(file_okay=True, dir_okay=False, readable=True),
|
|
422
|
|
- help="A file describing what to do")
|
|
423
|
|
-@click.argument('command', type=click.STRING, nargs=-1)
|
|
424
|
|
-def run_bst(directory, force, source_cache, description, palette, output, command):
|
|
|
443
|
+@click.argument('description', click.Path(file_okay=True, dir_okay=False, readable=True))
|
|
|
444
|
+def run_bst(directory, force, source_cache, description, palette):
|
|
425
|
445
|
"""Run a bst command and capture stdout/stderr in html
|
|
426
|
446
|
|
|
427
|
447
|
This command normally takes a description yaml file, see the HACKING
|
| ... |
... |
@@ -430,45 +450,8 @@ def run_bst(directory, force, source_cache, description, palette, output, comman |
|
430
|
450
|
if not source_cache and os.environ.get('BST_SOURCE_CACHE'):
|
|
431
|
451
|
source_cache = os.environ['BST_SOURCE_CACHE']
|
|
432
|
452
|
|
|
433
|
|
- if output is not None and not check_needs_build(None, output, force=force):
|
|
434
|
|
- click.echo("No need to rebuild {}".format(output))
|
|
435
|
|
- return 0
|
|
436
|
|
-
|
|
437
|
453
|
with workdir(source_cache=source_cache) as (tempdir, config_file, source_cache):
|
|
438
|
|
-
|
|
439
|
|
- if description:
|
|
440
|
|
- run_session(description, tempdir, source_cache, palette, config_file, force)
|
|
441
|
|
- return 0
|
|
442
|
|
-
|
|
443
|
|
- # Run a command specified on the CLI
|
|
444
|
|
- #
|
|
445
|
|
- if not directory:
|
|
446
|
|
- directory = os.getcwd()
|
|
447
|
|
- else:
|
|
448
|
|
- directory = os.path.abspath(directory)
|
|
449
|
|
- directory = os.path.realpath(directory)
|
|
450
|
|
-
|
|
451
|
|
- if not command:
|
|
452
|
|
- command = []
|
|
453
|
|
- command_str = " ".join(command)
|
|
454
|
|
-
|
|
455
|
|
- # Run the command
|
|
456
|
|
- #
|
|
457
|
|
- command_out = run_command(config_file, directory, command_str)
|
|
458
|
|
-
|
|
459
|
|
- # Generate a nice html div for this output
|
|
460
|
|
- #
|
|
461
|
|
- converted = generate_html(command_out, directory, config_file,
|
|
462
|
|
- source_cache, tempdir, palette,
|
|
463
|
|
- command_str)
|
|
464
|
|
-
|
|
465
|
|
- if output is None:
|
|
466
|
|
- click.echo(converted)
|
|
467
|
|
- else:
|
|
468
|
|
- outdir = os.path.dirname(output)
|
|
469
|
|
- os.makedirs(outdir, exist_ok=True)
|
|
470
|
|
- with open(output, 'wb') as f:
|
|
471
|
|
- f.write(converted.encode('utf-8'))
|
|
|
454
|
+ run_session(description, tempdir, source_cache, palette, config_file, force)
|
|
472
|
455
|
|
|
473
|
456
|
return 0
|
|
474
|
457
|
|