Will Salmon pushed to branch willsalmon/shellBuildTrees at BuildStream / buildstream
Commits:
-
e564251b
by Jonathan Maw at 2018-12-11T16:15:19Z
-
7cf83343
by Jonathan Maw at 2018-12-11T16:15:19Z
-
a1dee91e
by Jonathan Maw at 2018-12-11T16:15:19Z
-
9b192015
by Jonathan Maw at 2018-12-11T16:15:19Z
-
e340371f
by Jonathan Maw at 2018-12-11T16:15:19Z
-
bbf81c3d
by Jonathan Maw at 2018-12-11T16:15:19Z
-
a5a53ddd
by Jonathan Maw at 2018-12-12T13:44:09Z
-
30cb4d71
by William Salmon at 2018-12-12T14:59:20Z
14 changed files:
- NEWS
- buildstream/_context.py
- buildstream/_frontend/app.py
- buildstream/_frontend/cli.py
- buildstream/_stream.py
- buildstream/element.py
- doc/sessions/developing.run
- doc/source/developing/workspaces.rst
- + doc/source/sessions-stored/developing-build-after-changes-workspace.html
- tests/frontend/source_checkout.py
- tests/frontend/workspace.py
- tests/integration/build-tree.py
- tests/integration/shell.py
- tests/testutils/runcli.py
Changes:
| ... | ... | @@ -86,6 +86,11 @@ buildstream 1.3.1 |
| 86 | 86 |
o Opening a workspace now creates a .bstproject.yaml file that allows buildstream
|
| 87 | 87 |
commands to be run from a workspace that is not inside a project.
|
| 88 | 88 |
|
| 89 |
+ o Specifying an element is now optional for some commands when buildstream is run
|
|
| 90 |
+ from inside a workspace - the 'build', 'checkout', 'fetch', 'pull', 'push',
|
|
| 91 |
+ 'shell', 'show', 'source-checkout', 'track', 'workspace close' and 'workspace reset'
|
|
| 92 |
+ commands are affected.
|
|
| 93 |
+ |
|
| 89 | 94 |
|
| 90 | 95 |
=================
|
| 91 | 96 |
buildstream 1.1.5
|
| ... | ... | @@ -32,7 +32,7 @@ from ._message import Message, MessageType |
| 32 | 32 |
from ._profile import Topics, profile_start, profile_end
|
| 33 | 33 |
from ._artifactcache import ArtifactCache
|
| 34 | 34 |
from ._artifactcache.cascache import CASCache
|
| 35 |
-from ._workspaces import Workspaces, WorkspaceProjectCache
|
|
| 35 |
+from ._workspaces import Workspaces, WorkspaceProjectCache, WORKSPACE_PROJECT_FILE
|
|
| 36 | 36 |
from .plugin import _plugin_lookup
|
| 37 | 37 |
|
| 38 | 38 |
|
| ... | ... | @@ -47,9 +47,12 @@ from .plugin import _plugin_lookup |
| 47 | 47 |
# verbosity levels and basically anything pertaining to the context
|
| 48 | 48 |
# in which BuildStream was invoked.
|
| 49 | 49 |
#
|
| 50 |
+# Args:
|
|
| 51 |
+# directory (str): The directory that buildstream was invoked in
|
|
| 52 |
+#
|
|
| 50 | 53 |
class Context():
|
| 51 | 54 |
|
| 52 |
- def __init__(self):
|
|
| 55 |
+ def __init__(self, directory=None):
|
|
| 53 | 56 |
|
| 54 | 57 |
# Filename indicating which configuration file was used, or None for the defaults
|
| 55 | 58 |
self.config_origin = None
|
| ... | ... | @@ -148,6 +151,7 @@ class Context(): |
| 148 | 151 |
self._log_handle = None
|
| 149 | 152 |
self._log_filename = None
|
| 150 | 153 |
self._cascache = None
|
| 154 |
+ self._directory = directory
|
|
| 151 | 155 |
|
| 152 | 156 |
# load()
|
| 153 | 157 |
#
|
| ... | ... | @@ -645,6 +649,20 @@ class Context(): |
| 645 | 649 |
self._cascache = CASCache(self.artifactdir)
|
| 646 | 650 |
return self._cascache
|
| 647 | 651 |
|
| 652 |
+ # guess_element()
|
|
| 653 |
+ #
|
|
| 654 |
+ # Attempts to interpret which element the user intended to run commands on
|
|
| 655 |
+ #
|
|
| 656 |
+ # Returns:
|
|
| 657 |
+ # (str) The name of the element, or None if no element can be guessed
|
|
| 658 |
+ def guess_element(self):
|
|
| 659 |
+ workspace_project_dir, _ = utils._search_upward_for_files(self._directory, [WORKSPACE_PROJECT_FILE])
|
|
| 660 |
+ if workspace_project_dir:
|
|
| 661 |
+ workspace_project = self._workspace_project_cache.get(workspace_project_dir)
|
|
| 662 |
+ return workspace_project.get_default_element()
|
|
| 663 |
+ else:
|
|
| 664 |
+ return None
|
|
| 665 |
+ |
|
| 648 | 666 |
|
| 649 | 667 |
# _node_get_option_str()
|
| 650 | 668 |
#
|
| ... | ... | @@ -164,7 +164,7 @@ class App(): |
| 164 | 164 |
# Load the Context
|
| 165 | 165 |
#
|
| 166 | 166 |
try:
|
| 167 |
- self.context = Context()
|
|
| 167 |
+ self.context = Context(directory)
|
|
| 168 | 168 |
self.context.load(config)
|
| 169 | 169 |
except BstError as e:
|
| 170 | 170 |
self._error_exit(e, "Error loading user configuration")
|
| ... | ... | @@ -316,10 +316,15 @@ def build(app, elements, all_, track_, track_save, track_all, track_except, trac |
| 316 | 316 |
if track_save:
|
| 317 | 317 |
click.echo("WARNING: --track-save is deprecated, saving is now unconditional", err=True)
|
| 318 | 318 |
|
| 319 |
- if track_all:
|
|
| 320 |
- track_ = elements
|
|
| 321 |
- |
|
| 322 | 319 |
with app.initialized(session_name="Build"):
|
| 320 |
+ if not all_ and not elements:
|
|
| 321 |
+ guessed_target = app.context.guess_element()
|
|
| 322 |
+ if guessed_target:
|
|
| 323 |
+ elements = (guessed_target,)
|
|
| 324 |
+ |
|
| 325 |
+ if track_all:
|
|
| 326 |
+ track_ = elements
|
|
| 327 |
+ |
|
| 323 | 328 |
app.stream.build(elements,
|
| 324 | 329 |
track_targets=track_,
|
| 325 | 330 |
track_except=track_except,
|
| ... | ... | @@ -371,6 +376,11 @@ def fetch(app, elements, deps, track_, except_, track_cross_junctions): |
| 371 | 376 |
deps = PipelineSelection.ALL
|
| 372 | 377 |
|
| 373 | 378 |
with app.initialized(session_name="Fetch"):
|
| 379 |
+ if not elements:
|
|
| 380 |
+ guessed_target = app.context.guess_element()
|
|
| 381 |
+ if guessed_target:
|
|
| 382 |
+ elements = (guessed_target,)
|
|
| 383 |
+ |
|
| 374 | 384 |
app.stream.fetch(elements,
|
| 375 | 385 |
selection=deps,
|
| 376 | 386 |
except_targets=except_,
|
| ... | ... | @@ -407,6 +417,11 @@ def track(app, elements, deps, except_, cross_junctions): |
| 407 | 417 |
all: All dependencies of all specified elements
|
| 408 | 418 |
"""
|
| 409 | 419 |
with app.initialized(session_name="Track"):
|
| 420 |
+ if not elements:
|
|
| 421 |
+ guessed_target = app.context.guess_element()
|
|
| 422 |
+ if guessed_target:
|
|
| 423 |
+ elements = (guessed_target,)
|
|
| 424 |
+ |
|
| 410 | 425 |
# Substitute 'none' for 'redirect' so that element redirections
|
| 411 | 426 |
# will be done
|
| 412 | 427 |
if deps == 'none':
|
| ... | ... | @@ -442,7 +457,13 @@ def pull(app, elements, deps, remote): |
| 442 | 457 |
none: No dependencies, just the element itself
|
| 443 | 458 |
all: All dependencies
|
| 444 | 459 |
"""
|
| 460 |
+ |
|
| 445 | 461 |
with app.initialized(session_name="Pull"):
|
| 462 |
+ if not elements:
|
|
| 463 |
+ guessed_target = app.context.guess_element()
|
|
| 464 |
+ if guessed_target:
|
|
| 465 |
+ elements = (guessed_target,)
|
|
| 466 |
+ |
|
| 446 | 467 |
app.stream.pull(elements, selection=deps, remote=remote)
|
| 447 | 468 |
|
| 448 | 469 |
|
| ... | ... | @@ -475,6 +496,11 @@ def push(app, elements, deps, remote): |
| 475 | 496 |
all: All dependencies
|
| 476 | 497 |
"""
|
| 477 | 498 |
with app.initialized(session_name="Push"):
|
| 499 |
+ if not elements:
|
|
| 500 |
+ guessed_target = app.context.guess_element()
|
|
| 501 |
+ if guessed_target:
|
|
| 502 |
+ elements = (guessed_target,)
|
|
| 503 |
+ |
|
| 478 | 504 |
app.stream.push(elements, selection=deps, remote=remote)
|
| 479 | 505 |
|
| 480 | 506 |
|
| ... | ... | @@ -545,6 +571,11 @@ def show(app, elements, deps, except_, order, format_): |
| 545 | 571 |
$'---------- %{name} ----------\\n%{vars}'
|
| 546 | 572 |
"""
|
| 547 | 573 |
with app.initialized():
|
| 574 |
+ if not elements:
|
|
| 575 |
+ guessed_target = app.context.guess_element()
|
|
| 576 |
+ if guessed_target:
|
|
| 577 |
+ elements = (guessed_target,)
|
|
| 578 |
+ |
|
| 548 | 579 |
dependencies = app.stream.load_selection(elements,
|
| 549 | 580 |
selection=deps,
|
| 550 | 581 |
except_targets=except_)
|
| ... | ... | @@ -573,11 +604,14 @@ def show(app, elements, deps, except_, order, format_): |
| 573 | 604 |
help="Mount a file or directory into the sandbox")
|
| 574 | 605 |
@click.option('--isolate', is_flag=True, default=False,
|
| 575 | 606 |
help='Create an isolated build sandbox')
|
| 576 |
-@click.argument('element',
|
|
| 607 |
+@click.option('--use-buildtree', '-t', 'cli_buildtree', type=click.Choice(['ask', 'if_available', 'always', 'never']),
|
|
| 608 |
+ default='ask',
|
|
| 609 |
+ help='Defaults to ask but if set to always the function will fail if a build tree is not available')
|
|
| 610 |
+@click.argument('element', required=False,
|
|
| 577 | 611 |
type=click.Path(readable=False))
|
| 578 | 612 |
@click.argument('command', type=click.STRING, nargs=-1)
|
| 579 | 613 |
@click.pass_obj
|
| 580 |
-def shell(app, element, sysroot, mount, isolate, build_, command):
|
|
| 614 |
+def shell(app, element, sysroot, mount, isolate, build_, cli_buildtree, command):
|
|
| 581 | 615 |
"""Run a command in the target element's sandbox environment
|
| 582 | 616 |
|
| 583 | 617 |
This will stage a temporary sysroot for running the target
|
| ... | ... | @@ -603,7 +637,15 @@ def shell(app, element, sysroot, mount, isolate, build_, command): |
| 603 | 637 |
else:
|
| 604 | 638 |
scope = Scope.RUN
|
| 605 | 639 |
|
| 640 |
+ cli_buildtree = cli_buildtree.lower().strip()
|
|
| 641 |
+ use_buildtree = False
|
|
| 642 |
+ |
|
| 606 | 643 |
with app.initialized():
|
| 644 |
+ if not element:
|
|
| 645 |
+ element = app.context.guess_element()
|
|
| 646 |
+ if not element:
|
|
| 647 |
+ raise AppError('Missing argument "ELEMENT".')
|
|
| 648 |
+ |
|
| 607 | 649 |
dependencies = app.stream.load_selection((element,), selection=PipelineSelection.NONE)
|
| 608 | 650 |
element = dependencies[0]
|
| 609 | 651 |
prompt = app.shell_prompt(element)
|
| ... | ... | @@ -611,12 +653,30 @@ def shell(app, element, sysroot, mount, isolate, build_, command): |
| 611 | 653 |
HostMount(path, host_path)
|
| 612 | 654 |
for host_path, path in mount
|
| 613 | 655 |
]
|
| 656 |
+ |
|
| 657 |
+ cached = element._cached_buildtree()
|
|
| 658 |
+ if cli_buildtree == "always":
|
|
| 659 |
+ if cached:
|
|
| 660 |
+ use_buildtree = True
|
|
| 661 |
+ else:
|
|
| 662 |
+ raise AppError("No buildtree is cached but the use buildtree option was specified")
|
|
| 663 |
+ elif cli_buildtree == "never":
|
|
| 664 |
+ pass
|
|
| 665 |
+ elif cli_buildtree == "if_available":
|
|
| 666 |
+ use_buildtree = cached
|
|
| 667 |
+ else:
|
|
| 668 |
+ if app.interactive and cached:
|
|
| 669 |
+ use_buildtree = bool(click.confirm('Do you want to use the cached buildtree?'))
|
|
| 670 |
+ if use_buildtree and not element._cached_success():
|
|
| 671 |
+ click.echo("Warning: using a buildtree from a failed build.")
|
|
| 672 |
+ |
|
| 614 | 673 |
try:
|
| 615 | 674 |
exitcode = app.stream.shell(element, scope, prompt,
|
| 616 | 675 |
directory=sysroot,
|
| 617 | 676 |
mounts=mounts,
|
| 618 | 677 |
isolate=isolate,
|
| 619 |
- command=command)
|
|
| 678 |
+ command=command,
|
|
| 679 |
+ usebuildtree=use_buildtree)
|
|
| 620 | 680 |
except BstError as e:
|
| 621 | 681 |
raise AppError("Error launching shell: {}".format(e), detail=e.detail) from e
|
| 622 | 682 |
|
| ... | ... | @@ -641,15 +701,24 @@ def shell(app, element, sysroot, mount, isolate, build_, command): |
| 641 | 701 |
help="Create a tarball from the artifact contents instead "
|
| 642 | 702 |
"of a file tree. If LOCATION is '-', the tarball "
|
| 643 | 703 |
"will be dumped to the standard output.")
|
| 644 |
-@click.argument('element',
|
|
| 704 |
+@click.argument('element', required=False,
|
|
| 645 | 705 |
type=click.Path(readable=False))
|
| 646 |
-@click.argument('location', type=click.Path())
|
|
| 706 |
+@click.argument('location', type=click.Path(), required=False)
|
|
| 647 | 707 |
@click.pass_obj
|
| 648 | 708 |
def checkout(app, element, location, force, deps, integrate, hardlinks, tar):
|
| 649 | 709 |
"""Checkout a built artifact to the specified location
|
| 650 | 710 |
"""
|
| 651 | 711 |
from ..element import Scope
|
| 652 | 712 |
|
| 713 |
+ if not element and not location:
|
|
| 714 |
+ click.echo("ERROR: LOCATION is not specified", err=True)
|
|
| 715 |
+ sys.exit(-1)
|
|
| 716 |
+ |
|
| 717 |
+ if element and not location:
|
|
| 718 |
+ # Nasty hack to get around click's optional args
|
|
| 719 |
+ location = element
|
|
| 720 |
+ element = None
|
|
| 721 |
+ |
|
| 653 | 722 |
if hardlinks and tar:
|
| 654 | 723 |
click.echo("ERROR: options --hardlinks and --tar conflict", err=True)
|
| 655 | 724 |
sys.exit(-1)
|
| ... | ... | @@ -662,6 +731,11 @@ def checkout(app, element, location, force, deps, integrate, hardlinks, tar): |
| 662 | 731 |
scope = Scope.NONE
|
| 663 | 732 |
|
| 664 | 733 |
with app.initialized():
|
| 734 |
+ if not element:
|
|
| 735 |
+ element = app.context.guess_element()
|
|
| 736 |
+ if not element:
|
|
| 737 |
+ raise AppError('Missing argument "ELEMENT".')
|
|
| 738 |
+ |
|
| 665 | 739 |
app.stream.checkout(element,
|
| 666 | 740 |
location=location,
|
| 667 | 741 |
force=force,
|
| ... | ... | @@ -683,14 +757,28 @@ def checkout(app, element, location, force, deps, integrate, hardlinks, tar): |
| 683 | 757 |
help='The dependencies whose sources to checkout (default: none)')
|
| 684 | 758 |
@click.option('--fetch', 'fetch_', default=False, is_flag=True,
|
| 685 | 759 |
help='Fetch elements if they are not fetched')
|
| 686 |
-@click.argument('element',
|
|
| 760 |
+@click.argument('element', required=False,
|
|
| 687 | 761 |
type=click.Path(readable=False))
|
| 688 |
-@click.argument('location', type=click.Path())
|
|
| 762 |
+@click.argument('location', type=click.Path(), required=False)
|
|
| 689 | 763 |
@click.pass_obj
|
| 690 | 764 |
def source_checkout(app, element, location, deps, fetch_, except_):
|
| 691 | 765 |
"""Checkout sources of an element to the specified location
|
| 692 | 766 |
"""
|
| 767 |
+ if not element and not location:
|
|
| 768 |
+ click.echo("ERROR: LOCATION is not specified", err=True)
|
|
| 769 |
+ sys.exit(-1)
|
|
| 770 |
+ |
|
| 771 |
+ if element and not location:
|
|
| 772 |
+ # Nasty hack to get around click's optional args
|
|
| 773 |
+ location = element
|
|
| 774 |
+ element = None
|
|
| 775 |
+ |
|
| 693 | 776 |
with app.initialized():
|
| 777 |
+ if not element:
|
|
| 778 |
+ element = app.context.guess_element()
|
|
| 779 |
+ if not element:
|
|
| 780 |
+ raise AppError('Missing argument "ELEMENT".')
|
|
| 781 |
+ |
|
| 694 | 782 |
app.stream.source_checkout(element,
|
| 695 | 783 |
location=location,
|
| 696 | 784 |
deps=deps,
|
| ... | ... | @@ -747,11 +835,15 @@ def workspace_open(app, no_checkout, force, track_, directory, elements): |
| 747 | 835 |
def workspace_close(app, remove_dir, all_, elements):
|
| 748 | 836 |
"""Close a workspace"""
|
| 749 | 837 |
|
| 750 |
- if not (all_ or elements):
|
|
| 751 |
- click.echo('ERROR: no elements specified', err=True)
|
|
| 752 |
- sys.exit(-1)
|
|
| 753 |
- |
|
| 754 | 838 |
with app.initialized():
|
| 839 |
+ if not (all_ or elements):
|
|
| 840 |
+ # NOTE: I may need to revisit this when implementing multiple projects
|
|
| 841 |
+ # opening one workspace.
|
|
| 842 |
+ element = app.context.guess_element()
|
|
| 843 |
+ if element:
|
|
| 844 |
+ elements = (element,)
|
|
| 845 |
+ else:
|
|
| 846 |
+ raise AppError('No elements specified')
|
|
| 755 | 847 |
|
| 756 | 848 |
# Early exit if we specified `all` and there are no workspaces
|
| 757 | 849 |
if all_ and not app.stream.workspace_exists():
|
| ... | ... | @@ -808,7 +900,11 @@ def workspace_reset(app, soft, track_, all_, elements): |
| 808 | 900 |
with app.initialized():
|
| 809 | 901 |
|
| 810 | 902 |
if not (all_ or elements):
|
| 811 |
- raise AppError('No elements specified to reset')
|
|
| 903 |
+ element = app.context.guess_element()
|
|
| 904 |
+ if element:
|
|
| 905 |
+ elements = (element,)
|
|
| 906 |
+ else:
|
|
| 907 |
+ raise AppError('No elements specified to reset')
|
|
| 812 | 908 |
|
| 813 | 909 |
if all_ and not app.stream.workspace_exists():
|
| 814 | 910 |
raise AppError("No open workspaces to reset")
|
| ... | ... | @@ -132,7 +132,8 @@ class Stream(): |
| 132 | 132 |
directory=None,
|
| 133 | 133 |
mounts=None,
|
| 134 | 134 |
isolate=False,
|
| 135 |
- command=None):
|
|
| 135 |
+ command=None,
|
|
| 136 |
+ usebuildtree=None):
|
|
| 136 | 137 |
|
| 137 | 138 |
# Assert we have everything we need built, unless the directory is specified
|
| 138 | 139 |
# in which case we just blindly trust the directory, using the element
|
| ... | ... | @@ -147,7 +148,8 @@ class Stream(): |
| 147 | 148 |
raise StreamError("Elements need to be built or downloaded before staging a shell environment",
|
| 148 | 149 |
detail="\n".join(missing_deps))
|
| 149 | 150 |
|
| 150 |
- return element._shell(scope, directory, mounts=mounts, isolate=isolate, prompt=prompt, command=command)
|
|
| 151 |
+ return element._shell(scope, directory, mounts=mounts, isolate=isolate, prompt=prompt, command=command,
|
|
| 152 |
+ usebuildtree=usebuildtree)
|
|
| 151 | 153 |
|
| 152 | 154 |
# build()
|
| 153 | 155 |
#
|
| ... | ... | @@ -544,7 +546,8 @@ class Stream(): |
| 544 | 546 |
if len(elements) != 1:
|
| 545 | 547 |
raise StreamError("Exactly one element can be given if --directory is used",
|
| 546 | 548 |
reason='directory-with-multiple-elements')
|
| 547 |
- expanded_directories = [custom_dir, ]
|
|
| 549 |
+ directory = os.path.abspath(custom_dir)
|
|
| 550 |
+ expanded_directories = [directory, ]
|
|
| 548 | 551 |
else:
|
| 549 | 552 |
# If this fails it is a bug in what ever calls this, usually cli.py and so can not be tested for via the
|
| 550 | 553 |
# run bst test mechanism.
|
| ... | ... | @@ -1338,11 +1338,12 @@ class Element(Plugin): |
| 1338 | 1338 |
# is used to stage things by the `bst checkout` codepath
|
| 1339 | 1339 |
#
|
| 1340 | 1340 |
@contextmanager
|
| 1341 |
- def _prepare_sandbox(self, scope, directory, shell=False, integrate=True):
|
|
| 1341 |
+ def _prepare_sandbox(self, scope, directory, shell=False, integrate=True, usebuildtree=None):
|
|
| 1342 | 1342 |
# bst shell and bst checkout require a local sandbox.
|
| 1343 | 1343 |
bare_directory = True if directory else False
|
| 1344 | 1344 |
with self.__sandbox(directory, config=self.__sandbox_config, allow_remote=False,
|
| 1345 | 1345 |
bare_directory=bare_directory) as sandbox:
|
| 1346 |
+ sandbox.usebuildtree = usebuildtree
|
|
| 1346 | 1347 |
|
| 1347 | 1348 |
# Configure always comes first, and we need it.
|
| 1348 | 1349 |
self.__configure_sandbox(sandbox)
|
| ... | ... | @@ -1386,7 +1387,7 @@ class Element(Plugin): |
| 1386 | 1387 |
# Stage all sources that need to be copied
|
| 1387 | 1388 |
sandbox_vroot = sandbox.get_virtual_directory()
|
| 1388 | 1389 |
host_vdirectory = sandbox_vroot.descend(directory.lstrip(os.sep).split(os.sep), create=True)
|
| 1389 |
- self._stage_sources_at(host_vdirectory, mount_workspaces=mount_workspaces)
|
|
| 1390 |
+ self._stage_sources_at(host_vdirectory, mount_workspaces=mount_workspaces, usebuildtree=sandbox.usebuildtree)
|
|
| 1390 | 1391 |
|
| 1391 | 1392 |
# _stage_sources_at():
|
| 1392 | 1393 |
#
|
| ... | ... | @@ -1396,9 +1397,8 @@ class Element(Plugin): |
| 1396 | 1397 |
# vdirectory (:class:`.storage.Directory`): A virtual directory object to stage sources into.
|
| 1397 | 1398 |
# mount_workspaces (bool): mount workspaces if True, copy otherwise
|
| 1398 | 1399 |
#
|
| 1399 |
- def _stage_sources_at(self, vdirectory, mount_workspaces=True):
|
|
| 1400 |
+ def _stage_sources_at(self, vdirectory, mount_workspaces=True, usebuildtree=False):
|
|
| 1400 | 1401 |
with self.timed_activity("Staging sources", silent_nested=True):
|
| 1401 |
- |
|
| 1402 | 1402 |
if not isinstance(vdirectory, Directory):
|
| 1403 | 1403 |
vdirectory = FileBasedDirectory(vdirectory)
|
| 1404 | 1404 |
if not vdirectory.is_empty():
|
| ... | ... | @@ -1420,7 +1420,7 @@ class Element(Plugin): |
| 1420 | 1420 |
.format(workspace.get_absolute_path())):
|
| 1421 | 1421 |
workspace.stage(temp_staging_directory)
|
| 1422 | 1422 |
# Check if we have a cached buildtree to use
|
| 1423 |
- elif self._cached_buildtree():
|
|
| 1423 |
+ elif usebuildtree:
|
|
| 1424 | 1424 |
artifact_base, _ = self.__extract()
|
| 1425 | 1425 |
import_dir = os.path.join(artifact_base, 'buildtree')
|
| 1426 | 1426 |
else:
|
| ... | ... | @@ -1854,9 +1854,10 @@ class Element(Plugin): |
| 1854 | 1854 |
# Returns: Exit code
|
| 1855 | 1855 |
#
|
| 1856 | 1856 |
# If directory is not specified, one will be staged using scope
|
| 1857 |
- def _shell(self, scope=None, directory=None, *, mounts=None, isolate=False, prompt=None, command=None):
|
|
| 1857 |
+ def _shell(self, scope=None, directory=None, *, mounts=None, isolate=False, prompt=None, command=None,
|
|
| 1858 |
+ usebuildtree=None):
|
|
| 1858 | 1859 |
|
| 1859 |
- with self._prepare_sandbox(scope, directory, shell=True) as sandbox:
|
|
| 1860 |
+ with self._prepare_sandbox(scope, directory, shell=True, usebuildtree=usebuildtree) as sandbox:
|
|
| 1860 | 1861 |
environment = self.get_environment()
|
| 1861 | 1862 |
environment = copy.copy(environment)
|
| 1862 | 1863 |
flags = SandboxFlags.INTERACTIVE | SandboxFlags.ROOT_READ_ONLY
|
| ... | ... | @@ -2231,7 +2232,6 @@ class Element(Plugin): |
| 2231 | 2232 |
specs=self.__remote_execution_specs,
|
| 2232 | 2233 |
bare_directory=bare_directory,
|
| 2233 | 2234 |
allow_real_directory=False)
|
| 2234 |
- yield sandbox
|
|
| 2235 | 2235 |
|
| 2236 | 2236 |
elif directory is not None and os.path.exists(directory):
|
| 2237 | 2237 |
if allow_remote and self.__remote_execution_specs:
|
| ... | ... | @@ -2249,7 +2249,6 @@ class Element(Plugin): |
| 2249 | 2249 |
config=config,
|
| 2250 | 2250 |
bare_directory=bare_directory,
|
| 2251 | 2251 |
allow_real_directory=not self.BST_VIRTUAL_DIRECTORY)
|
| 2252 |
- yield sandbox
|
|
| 2253 | 2252 |
|
| 2254 | 2253 |
else:
|
| 2255 | 2254 |
os.makedirs(context.builddir, exist_ok=True)
|
| ... | ... | @@ -2263,6 +2262,10 @@ class Element(Plugin): |
| 2263 | 2262 |
# Cleanup the build dir
|
| 2264 | 2263 |
utils._force_rmtree(rootdir)
|
| 2265 | 2264 |
|
| 2265 |
+ return
|
|
| 2266 |
+ sandbox.usebuildtree = None
|
|
| 2267 |
+ yield sandbox
|
|
| 2268 |
+ |
|
| 2266 | 2269 |
def __compose_default_splits(self, defaults):
|
| 2267 | 2270 |
project = self._get_project()
|
| 2268 | 2271 |
|
| ... | ... | @@ -24,6 +24,11 @@ commands: |
| 24 | 24 |
output: ../source/sessions/developing-build-after-changes.html
|
| 25 | 25 |
command: build hello.bst
|
| 26 | 26 |
|
| 27 |
+# Rebuild, from the workspace
|
|
| 28 |
+- directory: ../examples/developing/workspace_hello
|
|
| 29 |
+ output: ../source/sessions/developing-build-after-changes-workspace.html
|
|
| 30 |
+ command: build
|
|
| 31 |
+ |
|
| 27 | 32 |
# Capture shell output with changes
|
| 28 | 33 |
- directory: ../examples/developing/
|
| 29 | 34 |
output: ../source/sessions/developing-shell-after-changes.html
|
| ... | ... | @@ -50,11 +50,16 @@ We can open workspace_hello/hello.c and make the following change: |
| 50 | 50 |
.. literalinclude:: ../../examples/developing/update.patch
|
| 51 | 51 |
:language: diff
|
| 52 | 52 |
|
| 53 |
-Now, rebuild the hello.bst element
|
|
| 53 |
+Now, rebuild the hello.bst element.
|
|
| 54 | 54 |
|
| 55 | 55 |
.. raw:: html
|
| 56 | 56 |
:file: ../sessions/developing-build-after-changes.html
|
| 57 | 57 |
|
| 58 |
+Note that if you run the command from inside the workspace, the element name is optional.
|
|
| 59 |
+ |
|
| 60 |
+.. raw:: html
|
|
| 61 |
+ :file: ../sessions/developing-build-after-changes-workspace.html
|
|
| 62 |
+ |
|
| 58 | 63 |
Now running the hello command using bst shell:
|
| 59 | 64 |
|
| 60 | 65 |
.. raw:: html
|
| 1 |
+<!--
|
|
| 2 |
+ WARNING: This file was generated with bst2html.py
|
|
| 3 |
+-->
|
|
| 4 |
+<div class="highlight" style="font-size:x-small"><pre>
|
|
| 5 |
+<span style="color:#C4A000;font-weight:bold">user@host</span>:<span style="color:#3456A4;font-weight:bold">~/workspace_hello</span>$ bst build
|
|
| 6 |
+ |
|
| 7 |
+<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#3465A4"><span style=""><span style="opacity:0.5">START </span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Build
|
|
| 8 |
+<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#3465A4"><span style=""><span style="opacity:0.5">START </span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Loading elements
|
|
| 9 |
+<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#4E9A06"><span style=""><span style="opacity:0.5">SUCCESS</span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Loading elements
|
|
| 10 |
+<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#3465A4"><span style=""><span style="opacity:0.5">START </span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Resolving elements
|
|
| 11 |
+<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#4E9A06"><span style=""><span style="opacity:0.5">SUCCESS</span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Resolving elements
|
|
| 12 |
+<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#3465A4"><span style=""><span style="opacity:0.5">START </span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Resolving cached state
|
|
| 13 |
+<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#4E9A06"><span style=""><span style="opacity:0.5">SUCCESS</span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Resolving cached state
|
|
| 14 |
+<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#3465A4"><span style=""><span style="opacity:0.5">START </span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Checking sources
|
|
| 15 |
+<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#4E9A06"><span style=""><span style="opacity:0.5">SUCCESS</span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Checking sources
|
|
| 16 |
+ |
|
| 17 |
+<span style="color:#C4A000"><span style="">BuildStream Version 1.3.0+1032.g41813d3a.dirty
|
|
| 18 |
+</span></span><span style="color:#06989A"><span style="opacity:0.5"> Session Start: </span></span><span style="color:#C4A000">Wednesday, 05-12-2018 at 16:47:38</span>
|
|
| 19 |
+<span style="color:#06989A"><span style="opacity:0.5"> Project: </span></span><span style="color:#C4A000">developing (/home/user/workspace/buildstream/buildstream/doc/examples/developing)</span>
|
|
| 20 |
+<span style="color:#06989A"><span style="opacity:0.5"> Targets: </span></span><span style="color:#C4A000">hello.bst</span>
|
|
| 21 |
+ |
|
| 22 |
+<span style="color:#C4A000"><span style="">User Configuration
|
|
| 23 |
+</span></span><span style="color:#06989A"><span style="opacity:0.5"> Configuration File: </span></span><span style="color:#C4A000">/home/user/workspace/buildstream/buildstream/doc/run-bst-7ocq4_a7/buildstream.conf</span>
|
|
| 24 |
+<span style="color:#06989A"><span style="opacity:0.5"> Log Files: </span></span><span style="color:#C4A000">/home/user/workspace/buildstream/buildstream/doc/run-bst-7ocq4_a7/logs</span>
|
|
| 25 |
+<span style="color:#06989A"><span style="opacity:0.5"> Source Mirrors: </span></span><span style="color:#C4A000">/home/user/workspace/buildstream/buildstream/doc/run-bst-7ocq4_a7/sources</span>
|
|
| 26 |
+<span style="color:#06989A"><span style="opacity:0.5"> Build Area: </span></span><span style="color:#C4A000">/home/user/workspace/buildstream/buildstream/doc/run-bst-7ocq4_a7/build</span>
|
|
| 27 |
+<span style="color:#06989A"><span style="opacity:0.5"> Artifact Cache: </span></span><span style="color:#C4A000">/home/user/workspace/buildstream/buildstream/doc/run-bst-7ocq4_a7/artifacts</span>
|
|
| 28 |
+<span style="color:#06989A"><span style="opacity:0.5"> Strict Build Plan: </span></span><span style="color:#C4A000">Yes</span>
|
|
| 29 |
+<span style="color:#06989A"><span style="opacity:0.5"> Maximum Fetch Tasks: </span></span><span style="color:#C4A000">10</span>
|
|
| 30 |
+<span style="color:#06989A"><span style="opacity:0.5"> Maximum Build Tasks: </span></span><span style="color:#C4A000">4</span>
|
|
| 31 |
+<span style="color:#06989A"><span style="opacity:0.5"> Maximum Push Tasks: </span></span><span style="color:#C4A000">4</span>
|
|
| 32 |
+<span style="color:#06989A"><span style="opacity:0.5"> Maximum Network Retries: </span></span><span style="color:#C4A000">2</span>
|
|
| 33 |
+ |
|
| 34 |
+<span style="color:#C4A000"><span style="">Pipeline
|
|
| 35 |
+</span></span><span style="color:#75507B"> cached</span> <span style="color:#C4A000">9afe69d645f0bee106749bc2101aae16ef437bb51e1b343ef1f16f04f0572efb</span> <span style="color:#3465A4"><span style="">base/alpine.bst</span></span>
|
|
| 36 |
+<span style="color:#75507B"> cached</span> <span style="color:#C4A000">19f7c50c7a1db9ae4babe9d1f34f4cdbbf2428827d48673861fd1452d6c7e16b</span> <span style="color:#3465A4"><span style="">base.bst</span></span>
|
|
| 37 |
+<span style="color:#75507B"> cached</span> <span style="color:#C4A000">faa419610e7309d36d15926a81a8d75bbc113443c23c8162e63843dd86b5f56a</span> <span style="color:#3465A4"><span style="">hello.bst</span></span> Workspace: /home/user/workspace/buildstream/buildstream/doc/examples/developing/workspace_hello
|
|
| 38 |
+<span style="color:#06989A"><span style="opacity:0.5">===============================================================================
|
|
| 39 |
+</span></span><span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#4E9A06"><span style=""><span style="opacity:0.5">SUCCESS</span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Build
|
|
| 40 |
+ |
|
| 41 |
+<span style="color:#C4A000"><span style="">Pipeline Summary
|
|
| 42 |
+</span></span><span style="color:#06989A"><span style="opacity:0.5"> Total: </span></span><span style="color:#C4A000">3</span>
|
|
| 43 |
+<span style="color:#06989A"><span style="opacity:0.5"> Session: </span></span><span style="color:#C4A000">0</span>
|
|
| 44 |
+<span style="color:#06989A"><span style="opacity:0.5"> Fetch Queue: </span></span><span style="color:#C4A000">processed </span><span style="color:#4E9A06">0</span><span style="color:#06989A"><span style="opacity:0.5">, </span></span><span style="color:#C4A000">skipped </span><span style="color:#C4A000">0</span><span style="color:#06989A"><span style="opacity:0.5">, </span></span><span style="color:#C4A000">failed </span><span style="color:#CC0000"><span style="opacity:0.5">0</span></span>
|
|
| 45 |
+<span style="color:#06989A"><span style="opacity:0.5"> Build Queue: </span></span><span style="color:#C4A000">processed </span><span style="color:#4E9A06">0</span><span style="color:#06989A"><span style="opacity:0.5">, </span></span><span style="color:#C4A000">skipped </span><span style="color:#C4A000">0</span><span style="color:#06989A"><span style="opacity:0.5">, </span></span><span style="color:#C4A000">failed </span><span style="color:#CC0000"><span style="opacity:0.5">0</span></span>
|
|
| 46 |
+</pre></div>
|
| ... | ... | @@ -28,19 +28,28 @@ def generate_remote_import_element(input_path, output_path): |
| 28 | 28 |
|
| 29 | 29 |
|
| 30 | 30 |
@pytest.mark.datafiles(DATA_DIR)
|
| 31 |
-@pytest.mark.parametrize('with_workspace', [('workspace'), ('no-workspace')])
|
|
| 32 |
-def test_source_checkout(datafiles, tmpdir_factory, cli, with_workspace):
|
|
| 31 |
+@pytest.mark.parametrize(
|
|
| 32 |
+ "with_workspace,guess_element",
|
|
| 33 |
+ [(True, True), (True, False), (False, False)],
|
|
| 34 |
+ ids=["workspace-guess", "workspace-no-guess", "no-workspace-no-guess"]
|
|
| 35 |
+)
|
|
| 36 |
+def test_source_checkout(datafiles, cli, tmpdir_factory, with_workspace, guess_element):
|
|
| 33 | 37 |
tmpdir = tmpdir_factory.mktemp("")
|
| 34 | 38 |
project = os.path.join(datafiles.dirname, datafiles.basename)
|
| 35 | 39 |
checkout = os.path.join(cli.directory, 'source-checkout')
|
| 36 | 40 |
target = 'checkout-deps.bst'
|
| 37 | 41 |
workspace = os.path.join(str(tmpdir), 'workspace')
|
| 42 |
+ elm_cmd = [target] if not guess_element else []
|
|
| 38 | 43 |
|
| 39 |
- if with_workspace == "workspace":
|
|
| 40 |
- result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, target])
|
|
| 44 |
+ if with_workspace:
|
|
| 45 |
+ ws_cmd = ['-C', workspace]
|
|
| 46 |
+ result = cli.run(project=project, args=["workspace", "open", "--directory", workspace, target])
|
|
| 41 | 47 |
result.assert_success()
|
| 48 |
+ else:
|
|
| 49 |
+ ws_cmd = []
|
|
| 42 | 50 |
|
| 43 |
- result = cli.run(project=project, args=['source-checkout', target, '--deps', 'none', checkout])
|
|
| 51 |
+ args = ws_cmd + ['source-checkout', '--deps', 'none'] + elm_cmd + [checkout]
|
|
| 52 |
+ result = cli.run(project=project, args=args)
|
|
| 44 | 53 |
result.assert_success()
|
| 45 | 54 |
|
| 46 | 55 |
assert os.path.exists(os.path.join(checkout, 'checkout-deps', 'etc', 'buildstream', 'config'))
|
| ... | ... | @@ -616,12 +616,16 @@ def test_list(cli, tmpdir, datafiles): |
| 616 | 616 |
@pytest.mark.datafiles(DATA_DIR)
|
| 617 | 617 |
@pytest.mark.parametrize("kind", repo_kinds)
|
| 618 | 618 |
@pytest.mark.parametrize("strict", [("strict"), ("non-strict")])
|
| 619 |
-@pytest.mark.parametrize("call_from", [("project"), ("workspace")])
|
|
| 620 |
-def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from):
|
|
| 619 |
+@pytest.mark.parametrize(
|
|
| 620 |
+ "from_workspace,guess_element",
|
|
| 621 |
+ [(False, False), (True, True), (True, False)],
|
|
| 622 |
+ ids=["project-no-guess", "workspace-guess", "workspace-no-guess"])
|
|
| 623 |
+def test_build(cli, tmpdir_factory, datafiles, kind, strict, from_workspace, guess_element):
|
|
| 621 | 624 |
tmpdir = tmpdir_factory.mktemp('')
|
| 622 | 625 |
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False)
|
| 623 | 626 |
checkout = os.path.join(str(tmpdir), 'checkout')
|
| 624 |
- args_pre = ['-C', workspace] if call_from == "workspace" else []
|
|
| 627 |
+ args_dir = ['-C', workspace] if from_workspace else []
|
|
| 628 |
+ args_elm = [element_name] if not guess_element else []
|
|
| 625 | 629 |
|
| 626 | 630 |
# Modify workspace
|
| 627 | 631 |
shutil.rmtree(os.path.join(workspace, 'usr', 'bin'))
|
| ... | ... | @@ -644,14 +648,14 @@ def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from): |
| 644 | 648 |
# Build modified workspace
|
| 645 | 649 |
assert cli.get_element_state(project, element_name) == 'buildable'
|
| 646 | 650 |
assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
|
| 647 |
- result = cli.run(project=project, args=args_pre + ['build', element_name])
|
|
| 651 |
+ result = cli.run(project=project, args=args_dir + ['build'] + args_elm)
|
|
| 648 | 652 |
result.assert_success()
|
| 649 | 653 |
assert cli.get_element_state(project, element_name) == 'cached'
|
| 650 | 654 |
assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
|
| 651 | 655 |
|
| 652 | 656 |
# Checkout the result
|
| 653 | 657 |
result = cli.run(project=project,
|
| 654 |
- args=args_pre + ['checkout', element_name, checkout])
|
|
| 658 |
+ args=args_dir + ['checkout'] + args_elm + [checkout])
|
|
| 655 | 659 |
result.assert_success()
|
| 656 | 660 |
|
| 657 | 661 |
# Check that the pony.conf from the modified workspace exists
|
| ... | ... | @@ -1062,29 +1066,36 @@ def test_multiple_failed_builds(cli, tmpdir, datafiles): |
| 1062 | 1066 |
|
| 1063 | 1067 |
@pytest.mark.datafiles(DATA_DIR)
|
| 1064 | 1068 |
@pytest.mark.parametrize('subdir', [True, False], ids=["subdir", "no-subdir"])
|
| 1065 |
-def test_external_fetch(cli, datafiles, tmpdir_factory, subdir):
|
|
| 1069 |
+@pytest.mark.parametrize("guess_element", [True, False], ids=["guess", "no-guess"])
|
|
| 1070 |
+def test_external_fetch(cli, datafiles, tmpdir_factory, subdir, guess_element):
|
|
| 1066 | 1071 |
# Fetching from a workspace outside a project doesn't fail horribly
|
| 1067 | 1072 |
tmpdir = tmpdir_factory.mktemp('')
|
| 1068 | 1073 |
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
|
| 1074 |
+ arg_elm = [element_name] if not guess_element else []
|
|
| 1069 | 1075 |
|
| 1070 | 1076 |
if subdir:
|
| 1071 | 1077 |
call_dir = os.path.join(workspace, 'usr')
|
| 1072 | 1078 |
else:
|
| 1073 | 1079 |
call_dir = workspace
|
| 1074 | 1080 |
|
| 1075 |
- result = cli.run(project=project, args=['-C', call_dir, 'fetch', element_name])
|
|
| 1081 |
+ result = cli.run(project=project, args=['-C', call_dir, 'fetch'] + arg_elm)
|
|
| 1076 | 1082 |
result.assert_success()
|
| 1077 | 1083 |
|
| 1078 | 1084 |
# We already fetched it by opening the workspace, but we're also checking
|
| 1079 | 1085 |
# `bst show` works here
|
| 1080 |
- assert cli.get_element_state(project, element_name) == 'buildable'
|
|
| 1086 |
+ result = cli.run(project=project,
|
|
| 1087 |
+ args=['-C', call_dir, 'show', '--deps', 'none', '--format', '%{state}'] + arg_elm)
|
|
| 1088 |
+ result.assert_success()
|
|
| 1089 |
+ assert result.output.strip() == 'buildable'
|
|
| 1081 | 1090 |
|
| 1082 | 1091 |
|
| 1083 | 1092 |
@pytest.mark.datafiles(DATA_DIR)
|
| 1084 |
-def test_external_push_pull(cli, datafiles, tmpdir_factory):
|
|
| 1093 |
+@pytest.mark.parametrize("guess_element", [True, False], ids=["guess", "no-guess"])
|
|
| 1094 |
+def test_external_push_pull(cli, datafiles, tmpdir_factory, guess_element):
|
|
| 1085 | 1095 |
# Pushing and pulling to/from an artifact cache works from an external workspace
|
| 1086 | 1096 |
tmpdir = tmpdir_factory.mktemp('')
|
| 1087 | 1097 |
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
|
| 1098 |
+ arg_elm = [element_name] if not guess_element else []
|
|
| 1088 | 1099 |
|
| 1089 | 1100 |
with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
|
| 1090 | 1101 |
result = cli.run(project=project, args=['-C', workspace, 'build', element_name])
|
| ... | ... | @@ -1094,22 +1105,24 @@ def test_external_push_pull(cli, datafiles, tmpdir_factory): |
| 1094 | 1105 |
'artifacts': {'url': share.repo, 'push': True}
|
| 1095 | 1106 |
})
|
| 1096 | 1107 |
|
| 1097 |
- result = cli.run(project=project, args=['-C', workspace, 'push', element_name])
|
|
| 1108 |
+ result = cli.run(project=project, args=['-C', workspace, 'push'] + arg_elm)
|
|
| 1098 | 1109 |
result.assert_success()
|
| 1099 | 1110 |
|
| 1100 |
- result = cli.run(project=project, args=['-C', workspace, 'pull', '--deps', 'all', element_name])
|
|
| 1111 |
+ result = cli.run(project=project, args=['-C', workspace, 'pull', '--deps', 'all'] + arg_elm)
|
|
| 1101 | 1112 |
result.assert_success()
|
| 1102 | 1113 |
|
| 1103 | 1114 |
|
| 1104 | 1115 |
@pytest.mark.datafiles(DATA_DIR)
|
| 1105 |
-def test_external_track(cli, datafiles, tmpdir_factory):
|
|
| 1116 |
+@pytest.mark.parametrize("guess_element", [True, False], ids=["guess", "no-guess"])
|
|
| 1117 |
+def test_external_track(cli, datafiles, tmpdir_factory, guess_element):
|
|
| 1106 | 1118 |
# Tracking does not get horribly confused
|
| 1107 | 1119 |
tmpdir = tmpdir_factory.mktemp('')
|
| 1108 | 1120 |
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", True)
|
| 1121 |
+ arg_elm = [element_name] if not guess_element else []
|
|
| 1109 | 1122 |
|
| 1110 | 1123 |
# The workspace is necessarily already tracked, so we only care that
|
| 1111 | 1124 |
# there's no weird errors.
|
| 1112 |
- result = cli.run(project=project, args=['-C', workspace, 'track', element_name])
|
|
| 1125 |
+ result = cli.run(project=project, args=['-C', workspace, 'track'] + arg_elm)
|
|
| 1113 | 1126 |
result.assert_success()
|
| 1114 | 1127 |
|
| 1115 | 1128 |
|
| ... | ... | @@ -1147,15 +1160,17 @@ def test_external_close_other(cli, datafiles, tmpdir_factory): |
| 1147 | 1160 |
|
| 1148 | 1161 |
|
| 1149 | 1162 |
@pytest.mark.datafiles(DATA_DIR)
|
| 1150 |
-def test_external_close_self(cli, datafiles, tmpdir_factory):
|
|
| 1163 |
+@pytest.mark.parametrize("guess_element", [True, False], ids=["guess", "no-guess"])
|
|
| 1164 |
+def test_external_close_self(cli, datafiles, tmpdir_factory, guess_element):
|
|
| 1151 | 1165 |
# >From inside an external workspace, close it
|
| 1152 | 1166 |
tmpdir1 = tmpdir_factory.mktemp('')
|
| 1153 | 1167 |
tmpdir2 = tmpdir_factory.mktemp('')
|
| 1154 | 1168 |
# Making use of the assumption that it's the same project in both invocations of open_workspace
|
| 1155 | 1169 |
alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
|
| 1156 | 1170 |
beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
|
| 1171 |
+ arg_elm = [alpha_element] if not guess_element else []
|
|
| 1157 | 1172 |
|
| 1158 |
- result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', alpha_element])
|
|
| 1173 |
+ result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close'] + arg_elm)
|
|
| 1159 | 1174 |
result.assert_success()
|
| 1160 | 1175 |
|
| 1161 | 1176 |
|
| ... | ... | @@ -1172,11 +1187,13 @@ def test_external_reset_other(cli, datafiles, tmpdir_factory): |
| 1172 | 1187 |
|
| 1173 | 1188 |
|
| 1174 | 1189 |
@pytest.mark.datafiles(DATA_DIR)
|
| 1175 |
-def test_external_reset_self(cli, datafiles, tmpdir):
|
|
| 1190 |
+@pytest.mark.parametrize("guess_element", [True, False], ids=["guess", "no-guess"])
|
|
| 1191 |
+def test_external_reset_self(cli, datafiles, tmpdir, guess_element):
|
|
| 1176 | 1192 |
element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
|
| 1193 |
+ arg_elm = [element] if not guess_element else []
|
|
| 1177 | 1194 |
|
| 1178 | 1195 |
# Command succeeds
|
| 1179 |
- result = cli.run(project=project, args=['-C', workspace, 'workspace', 'reset', element])
|
|
| 1196 |
+ result = cli.run(project=project, args=['-C', workspace, 'workspace', 'reset'] + arg_elm)
|
|
| 1180 | 1197 |
result.assert_success()
|
| 1181 | 1198 |
|
| 1182 | 1199 |
# Successive commands still work (i.e. .bstproject.yaml hasn't been deleted)
|
| ... | ... | @@ -19,7 +19,9 @@ DATA_DIR = os.path.join( |
| 19 | 19 |
@pytest.mark.datafiles(DATA_DIR)
|
| 20 | 20 |
@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
|
| 21 | 21 |
def test_buildtree_staged(cli_integration, tmpdir, datafiles):
|
| 22 |
- # i.e. tests that cached build trees are staged by `bst shell --build`
|
|
| 22 |
+ # By default we ask about staging build trees but we can only ask
|
|
| 23 |
+ # in a interactive session so by default trees are not staged by
|
|
| 24 |
+ # `bst shell --build` in the tests
|
|
| 23 | 25 |
project = os.path.join(datafiles.dirname, datafiles.basename)
|
| 24 | 26 |
element_name = 'build-shell/buildtree.bst'
|
| 25 | 27 |
|
| ... | ... | @@ -27,15 +29,50 @@ def test_buildtree_staged(cli_integration, tmpdir, datafiles): |
| 27 | 29 |
res.assert_success()
|
| 28 | 30 |
|
| 29 | 31 |
res = cli_integration.run(project=project, args=[
|
| 30 |
- 'shell', '--build', element_name, '--', 'grep', '-q', 'Hi', 'test'
|
|
| 32 |
+ 'shell', '--build', element_name, '--', 'cat', 'test'
|
|
| 33 |
+ ])
|
|
| 34 |
+ res.assert_shell_error()
|
|
| 35 |
+ |
|
| 36 |
+ |
|
| 37 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
| 38 |
+@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
|
|
| 39 |
+def test_buildtree_staged_forced_true(cli_integration, tmpdir, datafiles):
|
|
| 40 |
+ # Test that if we ask for a build tree it is there.
|
|
| 41 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
| 42 |
+ element_name = 'build-shell/buildtree.bst'
|
|
| 43 |
+ |
|
| 44 |
+ res = cli_integration.run(project=project, args=['build', element_name])
|
|
| 45 |
+ res.assert_success()
|
|
| 46 |
+ |
|
| 47 |
+ res = cli_integration.run(project=project, args=[
|
|
| 48 |
+ 'shell', '--build', '--use-buildtree', 'always', element_name, '--', 'cat', 'test'
|
|
| 31 | 49 |
])
|
| 32 | 50 |
res.assert_success()
|
| 51 |
+ assert 'Hi' in res.output
|
|
| 52 |
+ |
|
| 53 |
+ |
|
| 54 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
| 55 |
+@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
|
|
| 56 |
+def test_buildtree_staged_forced_false(cli_integration, tmpdir, datafiles):
|
|
| 57 |
+ # Test that if we ask not to have a build tree it is not there
|
|
| 58 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
| 59 |
+ element_name = 'build-shell/buildtree.bst'
|
|
| 60 |
+ |
|
| 61 |
+ res = cli_integration.run(project=project, args=['build', element_name])
|
|
| 62 |
+ res.assert_success()
|
|
| 63 |
+ |
|
| 64 |
+ res = cli_integration.run(project=project, args=[
|
|
| 65 |
+ 'shell', '--build', '--use-buildtree', 'never', element_name, '--', 'cat', 'test'
|
|
| 66 |
+ ])
|
|
| 67 |
+ res.assert_shell_error()
|
|
| 68 |
+ |
|
| 69 |
+ assert 'Hi' not in res.output
|
|
| 33 | 70 |
|
| 34 | 71 |
|
| 35 | 72 |
@pytest.mark.datafiles(DATA_DIR)
|
| 36 | 73 |
@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
|
| 37 | 74 |
def test_buildtree_from_failure(cli_integration, tmpdir, datafiles):
|
| 38 |
- # i.e. test that on a build failure, we can still shell into it
|
|
| 75 |
+ # Test that we can use a build tree after a failure
|
|
| 39 | 76 |
project = os.path.join(datafiles.dirname, datafiles.basename)
|
| 40 | 77 |
element_name = 'build-shell/buildtree-fail.bst'
|
| 41 | 78 |
|
| ... | ... | @@ -44,9 +81,10 @@ def test_buildtree_from_failure(cli_integration, tmpdir, datafiles): |
| 44 | 81 |
|
| 45 | 82 |
# Assert that file has expected contents
|
| 46 | 83 |
res = cli_integration.run(project=project, args=[
|
| 47 |
- 'shell', '--build', element_name, '--', 'cat', 'test'
|
|
| 84 |
+ 'shell', '--build', element_name, '--use-buildtree', 'always', '--', 'cat', 'test'
|
|
| 48 | 85 |
])
|
| 49 | 86 |
res.assert_success()
|
| 87 |
+ assert "Warning: using a buildtree from a failed build" in res.output
|
|
| 50 | 88 |
assert 'Hi' in res.output
|
| 51 | 89 |
|
| 52 | 90 |
|
| ... | ... | @@ -80,6 +118,58 @@ def test_buildtree_pulled(cli, tmpdir, datafiles): |
| 80 | 118 |
|
| 81 | 119 |
# Check it's using the cached build tree
|
| 82 | 120 |
res = cli.run(project=project, args=[
|
| 83 |
- 'shell', '--build', element_name, '--', 'grep', '-q', 'Hi', 'test'
|
|
| 121 |
+ 'shell', '--build', element_name, '--use-buildtree', 'always', '--', 'cat', 'test'
|
|
| 84 | 122 |
])
|
| 85 | 123 |
res.assert_success()
|
| 124 |
+ |
|
| 125 |
+ |
|
| 126 |
+# This test checks for correct behaviour if a buildtree is not present.
|
|
| 127 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
| 128 |
+@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
|
|
| 129 |
+def test_buildtree_options(cli, tmpdir, datafiles):
|
|
| 130 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
| 131 |
+ element_name = 'build-shell/buildtree.bst'
|
|
| 132 |
+ |
|
| 133 |
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
|
|
| 134 |
+ # Build the element to push it to cache
|
|
| 135 |
+ cli.configure({
|
|
| 136 |
+ 'artifacts': {'url': share.repo, 'push': True}
|
|
| 137 |
+ })
|
|
| 138 |
+ result = cli.run(project=project, args=['build', element_name])
|
|
| 139 |
+ result.assert_success()
|
|
| 140 |
+ assert cli.get_element_state(project, element_name) == 'cached'
|
|
| 141 |
+ |
|
| 142 |
+ # Discard the cache
|
|
| 143 |
+ cli.configure({
|
|
| 144 |
+ 'artifacts': {'url': share.repo, 'push': True},
|
|
| 145 |
+ 'artifactdir': os.path.join(cli.directory, 'artifacts2')
|
|
| 146 |
+ })
|
|
| 147 |
+ assert cli.get_element_state(project, element_name) != 'cached'
|
|
| 148 |
+ |
|
| 149 |
+ # Pull from cache, but do not include buildtrees.
|
|
| 150 |
+ result = cli.run(project=project, args=['pull', '--deps', 'all', element_name])
|
|
| 151 |
+ result.assert_success()
|
|
| 152 |
+ |
|
| 153 |
+ # The above is the simplest way I know to create a local cache without any buildtrees.
|
|
| 154 |
+ |
|
| 155 |
+ # Check it's not using the cached build tree
|
|
| 156 |
+ res = cli.run(project=project, args=[
|
|
| 157 |
+ 'shell', '--build', element_name, '--use-buildtree', 'never', '--', 'cat', 'test'
|
|
| 158 |
+ ])
|
|
| 159 |
+ res.assert_shell_error()
|
|
| 160 |
+ assert 'Hi' not in res.output
|
|
| 161 |
+ |
|
| 162 |
+ # Check it's not using the cached build tree, default is to ask, and fall back to not
|
|
| 163 |
+ # for non interactive behavior
|
|
| 164 |
+ res = cli.run(project=project, args=[
|
|
| 165 |
+ 'shell', '--build', element_name, '--', 'cat', 'test'
|
|
| 166 |
+ ])
|
|
| 167 |
+ res.assert_shell_error()
|
|
| 168 |
+ assert 'Hi' not in res.output
|
|
| 169 |
+ |
|
| 170 |
+ # Check it's using the cached build tree
|
|
| 171 |
+ res = cli.run(project=project, args=[
|
|
| 172 |
+ 'shell', '--build', element_name, '--use-buildtree', 'always', '--', 'cat', 'test'
|
|
| 173 |
+ ])
|
|
| 174 |
+ res.assert_main_error(ErrorDomain.PROG_NOT_FOUND, None)
|
|
| 175 |
+ assert 'Hi' not in res.output
|
| ... | ... | @@ -358,13 +358,22 @@ def test_integration_devices(cli, tmpdir, datafiles): |
| 358 | 358 |
# Test that a shell can be opened from an external workspace
|
| 359 | 359 |
@pytest.mark.datafiles(DATA_DIR)
|
| 360 | 360 |
@pytest.mark.parametrize("build_shell", [("build"), ("nobuild")])
|
| 361 |
+@pytest.mark.parametrize("guess_element", [True, False], ids=["guess", "no-guess"])
|
|
| 361 | 362 |
@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
|
| 362 |
-def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_shell):
|
|
| 363 |
+def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_shell, guess_element):
|
|
| 363 | 364 |
tmpdir = tmpdir_factory.mktemp("")
|
| 364 | 365 |
project = os.path.join(datafiles.dirname, datafiles.basename)
|
| 365 | 366 |
element_name = 'autotools/amhello.bst'
|
| 366 | 367 |
workspace_dir = os.path.join(str(tmpdir), 'workspace')
|
| 367 | 368 |
|
| 369 |
+ if guess_element:
|
|
| 370 |
+ # Mutate the project.conf to use a default shell command
|
|
| 371 |
+ project_file = os.path.join(project, 'project.conf')
|
|
| 372 |
+ config_text = "shell:\n"\
|
|
| 373 |
+ " command: ['true']\n"
|
|
| 374 |
+ with open(project_file, 'a') as f:
|
|
| 375 |
+ f.write(config_text)
|
|
| 376 |
+ |
|
| 368 | 377 |
result = cli.run(project=project, args=[
|
| 369 | 378 |
'workspace', 'open', '--directory', workspace_dir, element_name
|
| 370 | 379 |
])
|
| ... | ... | @@ -373,9 +382,10 @@ def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_sh |
| 373 | 382 |
result = cli.run(project=project, args=['-C', workspace_dir, 'build', element_name])
|
| 374 | 383 |
result.assert_success()
|
| 375 | 384 |
|
| 376 |
- command = ['shell']
|
|
| 385 |
+ command = ['-C', workspace_dir, 'shell']
|
|
| 377 | 386 |
if build_shell == 'build':
|
| 378 | 387 |
command.append('--build')
|
| 379 |
- command.extend([element_name, '--', 'true'])
|
|
| 388 |
+ if not guess_element:
|
|
| 389 |
+ command.extend([element_name, '--', 'true'])
|
|
| 380 | 390 |
result = cli.run(project=project, cwd=workspace_dir, args=command)
|
| 381 | 391 |
result.assert_success()
|
| ... | ... | @@ -153,6 +153,20 @@ class Result(): |
| 153 | 153 |
assert self.task_error_domain == error_domain, fail_message
|
| 154 | 154 |
assert self.task_error_reason == error_reason, fail_message
|
| 155 | 155 |
|
| 156 |
+ # assert_shell_error()
|
|
| 157 |
+ #
|
|
| 158 |
+ # Asserts that the buildstream created a shell and that the task in the
|
|
| 159 |
+ # shell failed.
|
|
| 160 |
+ #
|
|
| 161 |
+ # Args:
|
|
| 162 |
+ # fail_message (str): An optional message to override the automatic
|
|
| 163 |
+ # assertion error messages
|
|
| 164 |
+ # Raises:
|
|
| 165 |
+ # (AssertionError): If any of the assertions fail
|
|
| 166 |
+ #
|
|
| 167 |
+ def assert_shell_error(self, fail_message=''):
|
|
| 168 |
+ assert self.exit_code == 1, fail_message
|
|
| 169 |
+ |
|
| 156 | 170 |
# get_tracked_elements()
|
| 157 | 171 |
#
|
| 158 | 172 |
# Produces a list of element names on which tracking occurred
|
