Will Salmon pushed to branch willsalmon/defaultWorkspaces at BuildStream / buildstream
Commits:
- 
26be4dfd
by William Salmon at 2018-11-06T10:03:24Z
- 
e35d6db1
by William Salmon at 2018-11-06T10:11:23Z
14 changed files:
- NEWS
- buildstream/_context.py
- buildstream/_frontend/cli.py
- buildstream/_stream.py
- buildstream/data/userconfig.yaml
- buildstream/utils.py
- tests/examples/developing.py
- tests/examples/junctions.py
- tests/frontend/buildcheckout.py
- tests/frontend/cross_junction_workspace.py
- tests/frontend/workspace.py
- tests/integration/shell.py
- tests/integration/workspace.py
- tests/plugins/filter.py
Changes:
| ... | ... | @@ -45,6 +45,10 @@ buildstream 1.3.1 | 
| 45 | 45 |      instead of just a specially-formatted build-root with a `root` and `scratch`
 | 
| 46 | 46 |      subdirectory.
 | 
| 47 | 47 |  | 
| 48 | +  * 'bst workspace open` now supports the creation of multiple elements and
 | |
| 49 | +    allows the user to set a default location for there creation. This has meant
 | |
| 50 | +    that the new CLI is no longer backwards compatible with buildstream 1.2.
 | |
| 51 | + | |
| 48 | 52 |  | 
| 49 | 53 |  =================
 | 
| 50 | 54 |  buildstream 1.1.5
 | 
| ... | ... | @@ -60,6 +60,9 @@ class Context(): | 
| 60 | 60 |          # The directory where build sandboxes will be created
 | 
| 61 | 61 |          self.builddir = None
 | 
| 62 | 62 |  | 
| 63 | +        # Default root location for workspaces
 | |
| 64 | +        self.workspacedir = None
 | |
| 65 | + | |
| 63 | 66 |          # The local binary artifact cache directory
 | 
| 64 | 67 |          self.artifactdir = None
 | 
| 65 | 68 |  | 
| ... | ... | @@ -161,10 +164,10 @@ class Context(): | 
| 161 | 164 |          _yaml.node_validate(defaults, [
 | 
| 162 | 165 |              'sourcedir', 'builddir', 'artifactdir', 'logdir',
 | 
| 163 | 166 |              'scheduler', 'artifacts', 'logging', 'projects',
 | 
| 164 | -            'cache'
 | |
| 167 | +            'cache', 'workspacedir',
 | |
| 165 | 168 |          ])
 | 
| 166 | 169 |  | 
| 167 | -        for directory in ['sourcedir', 'builddir', 'artifactdir', 'logdir']:
 | |
| 170 | +        for directory in ['sourcedir', 'builddir', 'artifactdir', 'logdir', 'workspacedir']:
 | |
| 168 | 171 |              # Allow the ~ tilde expansion and any environment variables in
 | 
| 169 | 172 |              # path specification in the config files.
 | 
| 170 | 173 |              #
 | 
| ... | ... | @@ -6,6 +6,7 @@ from .. import _yaml | 
| 6 | 6 |  from .._exceptions import BstError, LoadError, AppError
 | 
| 7 | 7 |  from .._versions import BST_FORMAT_VERSION
 | 
| 8 | 8 |  from .complete import main_bashcomplete, complete_path, CompleteUnhandled
 | 
| 9 | +from ..utils import DirectoryDescription
 | |
| 9 | 10 |  | 
| 10 | 11 |  | 
| 11 | 12 |  ##################################################################
 | 
| ... | ... | @@ -678,28 +679,36 @@ def workspace(): | 
| 678 | 679 |  @click.option('--no-checkout', default=False, is_flag=True,
 | 
| 679 | 680 |                help="Do not checkout the source, only link to the given directory")
 | 
| 680 | 681 |  @click.option('--force', '-f', default=False, is_flag=True,
 | 
| 681 | -              help="Overwrite files existing in checkout directory")
 | |
| 682 | +              help="The workspace will be created even if the directory in which it will be created is not empty " +
 | |
| 683 | +              "or if a workspace for that element already exists")
 | |
| 682 | 684 |  @click.option('--track', 'track_', default=False, is_flag=True,
 | 
| 683 | 685 |                help="Track and fetch new source references before checking out the workspace")
 | 
| 684 | -@click.argument('element',
 | |
| 685 | -                type=click.Path(readable=False))
 | |
| 686 | -@click.argument('directory', type=click.Path(file_okay=False))
 | |
| 686 | +@click.option('--directory', type=click.Path(file_okay=False), default=None,
 | |
| 687 | +              help="Only for use when a single Element is given: Set the directory to use to create the workspace")
 | |
| 688 | +@click.argument('elements', nargs=-1, type=click.Path(readable=False))
 | |
| 687 | 689 |  @click.pass_obj
 | 
| 688 | -def workspace_open(app, no_checkout, force, track_, element, directory):
 | |
| 690 | +def workspace_open(app, no_checkout, force, track_, directory, elements):
 | |
| 689 | 691 |      """Open a workspace for manual source modification"""
 | 
| 690 | - | |
| 691 | -    if os.path.exists(directory):
 | |
| 692 | - | |
| 693 | -        if not os.path.isdir(directory):
 | |
| 694 | -            click.echo("Checkout directory is not a directory: {}".format(directory), err=True)
 | |
| 692 | +    directories = []
 | |
| 693 | +    if directory is not None:
 | |
| 694 | +        if len(elements) > 1:
 | |
| 695 | +            click.echo("Directory option can only be used if a single element is given", err=True)
 | |
| 695 | 696 |              sys.exit(-1)
 | 
| 697 | +        if os.path.exists(directory):
 | |
| 698 | +            if not os.path.isdir(directory):
 | |
| 699 | +                click.echo("Directory path is not a directory: {}".format(directory), err=True)
 | |
| 700 | +                sys.exit(-1)
 | |
| 696 | 701 |  | 
| 697 | -        if not (no_checkout or force) and os.listdir(directory):
 | |
| 698 | -            click.echo("Checkout directory is not empty: {}".format(directory), err=True)
 | |
| 699 | -            sys.exit(-1)
 | |
| 702 | +            if not (no_checkout or force) and os.listdir(directory):
 | |
| 703 | +                click.echo("Directory path is not empty: {}".format(directory), err=True)
 | |
| 704 | +                sys.exit(-1)
 | |
| 705 | +        directories.append(DirectoryDescription(directory, use_default=False))
 | |
| 706 | +    else:
 | |
| 707 | +        for element in elements:
 | |
| 708 | +            directories.append(DirectoryDescription(element.rstrip('.bst')))
 | |
| 700 | 709 |  | 
| 701 | 710 |      with app.initialized():
 | 
| 702 | -        app.stream.workspace_open(element, directory,
 | |
| 711 | +        app.stream.workspace_open(elements, directories,
 | |
| 703 | 712 |                                    no_checkout=no_checkout,
 | 
| 704 | 713 |                                    track_first=track_,
 | 
| 705 | 714 |                                    force=force)
 | 
| ... | ... | @@ -448,44 +448,29 @@ class Stream(): | 
| 448 | 448 |      # Open a project workspace
 | 
| 449 | 449 |      #
 | 
| 450 | 450 |      # Args:
 | 
| 451 | -    #    target (str): The target element to open the workspace for
 | |
| 452 | -    #    directory (str): The directory to stage the source in
 | |
| 451 | +    #    target (list): List of target elements to open workspaces for
 | |
| 452 | +    #    directory (list): List of DirectoryDescription objects to stage the source in
 | |
| 453 | 453 |      #    no_checkout (bool): Whether to skip checking out the source
 | 
| 454 | 454 |      #    track_first (bool): Whether to track and fetch first
 | 
| 455 | 455 |      #    force (bool): Whether to ignore contents in an existing directory
 | 
| 456 | 456 |      #
 | 
| 457 | -    def workspace_open(self, target, directory, *,
 | |
| 457 | +    def workspace_open(self, targets, directories, *,
 | |
| 458 | 458 |                         no_checkout,
 | 
| 459 | 459 |                         track_first,
 | 
| 460 | 460 |                         force):
 | 
| 461 | +        # This function is a little funny but it is trying to be as atomic as possible.
 | |
| 461 | 462 |  | 
| 462 | 463 |          if track_first:
 | 
| 463 | -            track_targets = (target,)
 | |
| 464 | +            track_targets = targets
 | |
| 464 | 465 |          else:
 | 
| 465 | 466 |              track_targets = ()
 | 
| 466 | 467 |  | 
| 467 | -        elements, track_elements = self._load((target,), track_targets,
 | |
| 468 | +        elements, track_elements = self._load(targets, track_targets,
 | |
| 468 | 469 |                                                selection=PipelineSelection.REDIRECT,
 | 
| 469 | 470 |                                                track_selection=PipelineSelection.REDIRECT)
 | 
| 470 | -        target = elements[0]
 | |
| 471 | -        directory = os.path.abspath(directory)
 | |
| 472 | - | |
| 473 | -        if not list(target.sources()):
 | |
| 474 | -            build_depends = [x.name for x in target.dependencies(Scope.BUILD, recurse=False)]
 | |
| 475 | -            if not build_depends:
 | |
| 476 | -                raise StreamError("The given element has no sources")
 | |
| 477 | -            detail = "Try opening a workspace on one of its dependencies instead:\n"
 | |
| 478 | -            detail += "  \n".join(build_depends)
 | |
| 479 | -            raise StreamError("The given element has no sources", detail=detail)
 | |
| 480 | 471 |  | 
| 481 | 472 |          workspaces = self._context.get_workspaces()
 | 
| 482 | 473 |  | 
| 483 | -        # Check for workspace config
 | |
| 484 | -        workspace = workspaces.get_workspace(target._get_full_name())
 | |
| 485 | -        if workspace and not force:
 | |
| 486 | -            raise StreamError("Workspace '{}' is already defined at: {}"
 | |
| 487 | -                              .format(target.name, workspace.get_absolute_path()))
 | |
| 488 | - | |
| 489 | 474 |          # If we're going to checkout, we need at least a fetch,
 | 
| 490 | 475 |          # if we were asked to track first, we're going to fetch anyway.
 | 
| 491 | 476 |          #
 | 
| ... | ... | @@ -495,29 +480,69 @@ class Stream(): | 
| 495 | 480 |                  track_elements = elements
 | 
| 496 | 481 |              self._fetch(elements, track_elements=track_elements)
 | 
| 497 | 482 |  | 
| 498 | -        if not no_checkout and target._get_consistency() != Consistency.CACHED:
 | |
| 499 | -            raise StreamError("Could not stage uncached source. " +
 | |
| 500 | -                              "Use `--track` to track and " +
 | |
| 501 | -                              "fetch the latest version of the " +
 | |
| 502 | -                              "source.")
 | |
| 483 | +        expanded_directories = []
 | |
| 484 | +        #  To try to be more atomic, loop through the elements and raise any errors we can early
 | |
| 485 | +        for target, directory_obj in zip(elements, directories):
 | |
| 486 | + | |
| 487 | +            if not list(target.sources()):
 | |
| 488 | +                build_depends = [x.name for x in target.dependencies(Scope.BUILD, recurse=False)]
 | |
| 489 | +                if not build_depends:
 | |
| 490 | +                    raise StreamError("The element {}  has no sources".format(target.name))
 | |
| 491 | +                detail = "Try opening a workspace on one of its dependencies instead:\n"
 | |
| 492 | +                detail += "  \n".join(build_depends)
 | |
| 493 | +                raise StreamError("The element {} has no sources".format(target.name), detail=detail)
 | |
| 494 | + | |
| 495 | +            # Check for workspace config
 | |
| 496 | +            workspace = workspaces.get_workspace(target._get_full_name())
 | |
| 497 | +            if workspace and not force:
 | |
| 498 | +                raise StreamError("Workspace '{}' is already defined at: {}"
 | |
| 499 | +                                  .format(target.name, workspace.get_absolute_path()))
 | |
| 500 | + | |
| 501 | +            if not no_checkout and target._get_consistency() != Consistency.CACHED:
 | |
| 502 | +                raise StreamError("Could not stage uncached source. For {} ".format(target.name) +
 | |
| 503 | +                                  "Use `--track` to track and " +
 | |
| 504 | +                                  "fetch the latest version of the " +
 | |
| 505 | +                                  "source.")
 | |
| 506 | + | |
| 507 | +            if directory_obj.use_default:
 | |
| 508 | +                directory = os.path.abspath(os.path.join(self._context.workspacedir, directory_obj.directory))
 | |
| 509 | +            else:
 | |
| 510 | +                directory = directory_obj.directory
 | |
| 503 | 511 |  | 
| 504 | -        if workspace:
 | |
| 505 | -            workspaces.delete_workspace(target._get_full_name())
 | |
| 506 | -            workspaces.save_config()
 | |
| 507 | -            shutil.rmtree(directory)
 | |
| 508 | -        try:
 | |
| 509 | -            os.makedirs(directory, exist_ok=True)
 | |
| 510 | -        except OSError as e:
 | |
| 511 | -            raise StreamError("Failed to create workspace directory: {}".format(e)) from e
 | |
| 512 | +            expanded_directories.append(directory)
 | |
| 512 | 513 |  | 
| 513 | -        workspaces.create_workspace(target._get_full_name(), directory)
 | |
| 514 | +        # So far this function has tried to catch as many issues as possible with out making any changes
 | |
| 515 | +        # Now it dose the bits that can not be made atomic.
 | |
| 516 | +        targetGenerator = zip(elements, expanded_directories)
 | |
| 517 | +        for target, directory in targetGenerator:
 | |
| 518 | +            self._message(MessageType.INFO, "Creating workspace for element {}"
 | |
| 519 | +                          .format(target.name))
 | |
| 514 | 520 |  | 
| 515 | -        if not no_checkout:
 | |
| 516 | -            with target.timed_activity("Staging sources to {}".format(directory)):
 | |
| 517 | -                target._open_workspace()
 | |
| 521 | +            workspace = workspaces.get_workspace(target._get_full_name())
 | |
| 522 | +            if workspace:
 | |
| 523 | +                workspaces.delete_workspace(target._get_full_name())
 | |
| 524 | +                workspaces.save_config()
 | |
| 525 | +                shutil.rmtree(directory)
 | |
| 526 | +            try:
 | |
| 527 | +                os.makedirs(directory, exist_ok=True)
 | |
| 528 | +            except OSError as e:
 | |
| 529 | +                todo_elements = " ".join([str(target.name) for target, directory_dict in targetGenerator])
 | |
| 530 | +                if todo_elements:
 | |
| 531 | +                    # This output should make creating the remaining workspaces as easy as possible.
 | |
| 532 | +                    todo_elements = "\nDid not try to create workspaces for " + todo_elements
 | |
| 533 | +                raise StreamError("Failed to create workspace directory: {}".format(e) + todo_elements) from e
 | |
| 518 | 534 |  | 
| 519 | -        workspaces.save_config()
 | |
| 520 | -        self._message(MessageType.INFO, "Saved workspace configuration")
 | |
| 535 | +            workspaces.create_workspace(target._get_full_name(), directory)
 | |
| 536 | + | |
| 537 | +            if not no_checkout:
 | |
| 538 | +                with target.timed_activity("Staging sources to {}".format(directory)):
 | |
| 539 | +                    target._open_workspace()
 | |
| 540 | + | |
| 541 | +            # Saving the workspace once it is set up means that if the next workspace fails to be created before
 | |
| 542 | +            # the configuration gets saved. The successfully created workspace still gets saved.
 | |
| 543 | +            workspaces.save_config()
 | |
| 544 | +            self._message(MessageType.INFO, "Added element {} to the workspace configuration"
 | |
| 545 | +                          .format(target._get_full_name()))
 | |
| 521 | 546 |  | 
| 522 | 547 |      # workspace_close
 | 
| 523 | 548 |      #
 | 
| ... | ... | @@ -22,6 +22,9 @@ artifactdir: ${XDG_CACHE_HOME}/buildstream/artifacts | 
| 22 | 22 |  # Location to store build logs
 | 
| 23 | 23 |  logdir: ${XDG_CACHE_HOME}/buildstream/logs
 | 
| 24 | 24 |  | 
| 25 | +# Default root location for workspaces, blank for no default set.
 | |
| 26 | +workspacedir: .
 | |
| 27 | + | |
| 25 | 28 |  #
 | 
| 26 | 29 |  #    Cache
 | 
| 27 | 30 |  #
 | 
| ... | ... | @@ -105,6 +105,20 @@ class FileListResult(): | 
| 105 | 105 |          return ret
 | 
| 106 | 106 |  | 
| 107 | 107 |  | 
| 108 | +class DirectoryDescription():
 | |
| 109 | +    """
 | |
| 110 | +    This object is used to keep information about directories in a nice tidy object.
 | |
| 111 | +    """
 | |
| 112 | +    def __init__(self, directory, *, use_default=True):
 | |
| 113 | +        """
 | |
| 114 | +        Args:
 | |
| 115 | +            directory (str): The path to the directory this object describes
 | |
| 116 | +            use_default (bool): Weather to process the directory so it is in the default folder.
 | |
| 117 | +        """
 | |
| 118 | +        self.directory = directory
 | |
| 119 | +        self.use_default = use_default
 | |
| 120 | + | |
| 121 | + | |
| 108 | 122 |  def list_relative_paths(directory, *, list_dirs=True):
 | 
| 109 | 123 |      """A generator for walking directory relative paths
 | 
| 110 | 124 |  | 
| ... | ... | @@ -55,7 +55,7 @@ def test_open_workspace(cli, tmpdir, datafiles): | 
| 55 | 55 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 56 | 56 |      workspace_dir = os.path.join(str(tmpdir), "workspace_hello")
 | 
| 57 | 57 |  | 
| 58 | -    result = cli.run(project=project, args=['workspace', 'open', '-f', 'hello.bst', workspace_dir])
 | |
| 58 | +    result = cli.run(project=project, args=['workspace', 'open', '-f', '--directory', workspace_dir, 'hello.bst', ])
 | |
| 59 | 59 |      result.assert_success()
 | 
| 60 | 60 |  | 
| 61 | 61 |      result = cli.run(project=project, args=['workspace', 'list'])
 | 
| ... | ... | @@ -72,7 +72,7 @@ def test_make_change_in_workspace(cli, tmpdir, datafiles): | 
| 72 | 72 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 73 | 73 |      workspace_dir = os.path.join(str(tmpdir), "workspace_hello")
 | 
| 74 | 74 |  | 
| 75 | -    result = cli.run(project=project, args=['workspace', 'open', '-f', 'hello.bst', workspace_dir])
 | |
| 75 | +    result = cli.run(project=project, args=['workspace', 'open', '-f', '--directory', workspace_dir, 'hello.bst'])
 | |
| 76 | 76 |      result.assert_success()
 | 
| 77 | 77 |  | 
| 78 | 78 |      result = cli.run(project=project, args=['workspace', 'list'])
 | 
| ... | ... | @@ -44,7 +44,7 @@ def test_open_cross_junction_workspace(cli, tmpdir, datafiles): | 
| 44 | 44 |      workspace_dir = os.path.join(str(tmpdir), "workspace_hello_junction")
 | 
| 45 | 45 |  | 
| 46 | 46 |      result = cli.run(project=project,
 | 
| 47 | -                     args=['workspace', 'open', 'hello-junction.bst:hello.bst', workspace_dir])
 | |
| 47 | +                     args=['workspace', 'open', '--directory', workspace_dir, 'hello-junction.bst:hello.bst'])
 | |
| 48 | 48 |      result.assert_success()
 | 
| 49 | 49 |  | 
| 50 | 50 |      result = cli.run(project=project,
 | 
| ... | ... | @@ -509,7 +509,7 @@ def test_build_checkout_workspaced_junction(cli, tmpdir, datafiles): | 
| 509 | 509 |  | 
| 510 | 510 |      # Now open a workspace on the junction
 | 
| 511 | 511 |      #
 | 
| 512 | -    result = cli.run(project=project, args=['workspace', 'open', 'junction.bst', workspace])
 | |
| 512 | +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, 'junction.bst'])
 | |
| 513 | 513 |      result.assert_success()
 | 
| 514 | 514 |      filename = os.path.join(workspace, 'files', 'etc-files', 'etc', 'animal.conf')
 | 
| 515 | 515 |  | 
| ... | ... | @@ -47,7 +47,7 @@ def open_cross_junction(cli, tmpdir): | 
| 47 | 47 |      workspace = tmpdir.join("workspace")
 | 
| 48 | 48 |  | 
| 49 | 49 |      element = 'sub.bst:data.bst'
 | 
| 50 | -    args = ['workspace', 'open', element, str(workspace)]
 | |
| 50 | +    args = ['workspace', 'open', '--directory', str(workspace), element]
 | |
| 51 | 51 |      result = cli.run(project=project, args=args)
 | 
| 52 | 52 |      result.assert_success()
 | 
| 53 | 53 |  | 
| ... | ... | @@ -25,6 +25,7 @@ | 
| 25 | 25 |  #
 | 
| 26 | 26 |  | 
| 27 | 27 |  import os
 | 
| 28 | +import stat
 | |
| 28 | 29 |  import pytest
 | 
| 29 | 30 |  import shutil
 | 
| 30 | 31 |  import subprocess
 | 
| ... | ... | @@ -182,6 +183,103 @@ def test_open_bzr_customize(cli, tmpdir, datafiles): | 
| 182 | 183 |      assert(expected_output_str in str(output))
 | 
| 183 | 184 |  | 
| 184 | 185 |  | 
| 186 | +@pytest.mark.datafiles(DATA_DIR)
 | |
| 187 | +def test_open_multi(cli, tmpdir, datafiles):
 | |
| 188 | + | |
| 189 | +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
 | |
| 190 | +    workspaces = workspace_object.open_workspaces(repo_kinds, False)
 | |
| 191 | + | |
| 192 | +    for (elname, workspace), kind in zip(workspaces, repo_kinds):
 | |
| 193 | +        assert kind in elname
 | |
| 194 | +        workspace_lsdir = os.listdir(workspace)
 | |
| 195 | +        if kind == 'git':
 | |
| 196 | +            assert('.git' in workspace_lsdir)
 | |
| 197 | +        elif kind == 'bzr':
 | |
| 198 | +            assert('.bzr' in workspace_lsdir)
 | |
| 199 | +        else:
 | |
| 200 | +            assert not ('.git' in workspace_lsdir)
 | |
| 201 | +            assert not ('.bzr' in workspace_lsdir)
 | |
| 202 | + | |
| 203 | + | |
| 204 | +@pytest.mark.datafiles(DATA_DIR)
 | |
| 205 | +def test_open_multi_unwritable(cli, tmpdir, datafiles):
 | |
| 206 | +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
 | |
| 207 | + | |
| 208 | +    element_tuples = workspace_object.create_workspace_elements(repo_kinds, False, repo_kinds)
 | |
| 209 | +    os.makedirs(workspace_object.workspace_cmd, exist_ok=True)
 | |
| 210 | + | |
| 211 | +    # Now open the workspace, this should have the effect of automatically
 | |
| 212 | +    # tracking & fetching the source from the repo.
 | |
| 213 | +    args = ['workspace', 'open']
 | |
| 214 | +    args.extend([element_name for element_name, workspace_dir_suffix in element_tuples])
 | |
| 215 | +    cli.configure({'workspacedir': workspace_object.workspace_cmd})
 | |
| 216 | + | |
| 217 | +    cwdstat = os.stat(workspace_object.workspace_cmd)
 | |
| 218 | +    try:
 | |
| 219 | +        os.chmod(workspace_object.workspace_cmd, cwdstat.st_mode - stat.S_IWRITE)
 | |
| 220 | +        result = workspace_object.cli.run(project=workspace_object.project_path, args=args)
 | |
| 221 | +    finally:
 | |
| 222 | +        # Using this finally to make sure we always put thing back how they should be.
 | |
| 223 | +        os.chmod(workspace_object.workspace_cmd, cwdstat.st_mode)
 | |
| 224 | + | |
| 225 | +    result.assert_main_error(ErrorDomain.STREAM, None)
 | |
| 226 | +    # Normally we avoid checking stderr in favour of using the mechine readable result.assert_main_error
 | |
| 227 | +    # But Tristan was very keen that the names of the elements left needing workspaces were present in the out put
 | |
| 228 | +    assert (" ".join([element_name for element_name, workspace_dir_suffix in element_tuples[1:]]) in result.stderr)
 | |
| 229 | + | |
| 230 | + | |
| 231 | +@pytest.mark.datafiles(DATA_DIR)
 | |
| 232 | +def test_open_multi_with_directory(cli, tmpdir, datafiles):
 | |
| 233 | +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
 | |
| 234 | + | |
| 235 | +    element_tuples = workspace_object.create_workspace_elements(repo_kinds, False, repo_kinds)
 | |
| 236 | +    os.makedirs(workspace_object.workspace_cmd, exist_ok=True)
 | |
| 237 | + | |
| 238 | +    # Now open the workspace, this should have the effect of automatically
 | |
| 239 | +    # tracking & fetching the source from the repo.
 | |
| 240 | +    args = ['workspace', 'open']
 | |
| 241 | +    args.extend(['--directory', 'any/dir/should/fail'])
 | |
| 242 | + | |
| 243 | +    args.extend([element_name for element_name, workspace_dir_suffix in element_tuples])
 | |
| 244 | +    result = workspace_object.cli.run(cwd=workspace_object.workspace_cmd, project=workspace_object.project_path,
 | |
| 245 | +                                      args=args)
 | |
| 246 | + | |
| 247 | +    result.assert_main_error(ErrorDomain.ARTIFACT, None)
 | |
| 248 | +    assert ("Directory option can only be used if a single element is given" in result.stderr)
 | |
| 249 | + | |
| 250 | + | |
| 251 | +@pytest.mark.datafiles(DATA_DIR)
 | |
| 252 | +def test_open_defaultlocation(cli, tmpdir, datafiles):
 | |
| 253 | +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
 | |
| 254 | + | |
| 255 | +    ((element_name, workspace_dir), ) = workspace_object.create_workspace_elements(['git'], False, ['git'])
 | |
| 256 | +    os.makedirs(workspace_object.workspace_cmd, exist_ok=True)
 | |
| 257 | + | |
| 258 | +    # Now open the workspace, this should have the effect of automatically
 | |
| 259 | +    # tracking & fetching the source from the repo.
 | |
| 260 | +    args = ['workspace', 'open']
 | |
| 261 | +    args.append(element_name)
 | |
| 262 | + | |
| 263 | +    # In the other tests we set the cmd to workspace_object.workspace_cmd with the optional
 | |
| 264 | +    # argument, cwd for the workspace_object.cli.run function. But hear we set the default
 | |
| 265 | +    # workspace location to workspace_object.workspace_cmd and run the cli.run function with
 | |
| 266 | +    # no cwd option so that it runs in the project directory.
 | |
| 267 | +    cli.configure({'workspacedir': workspace_object.workspace_cmd})
 | |
| 268 | +    result = workspace_object.cli.run(project=workspace_object.project_path,
 | |
| 269 | +                                      args=args)
 | |
| 270 | + | |
| 271 | +    result.assert_success()
 | |
| 272 | + | |
| 273 | +    assert cli.get_element_state(workspace_object.project_path, element_name) == 'buildable'
 | |
| 274 | + | |
| 275 | +    # Check that the executable hello file is found in the workspace
 | |
| 276 | +    # even though the cli.run function was not run with cwd = workspace_object.workspace_cmd
 | |
| 277 | +    # the workspace should be created in there as we used the 'workspacedir' configuration
 | |
| 278 | +    # option.
 | |
| 279 | +    filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello')
 | |
| 280 | +    assert os.path.exists(filename)
 | |
| 281 | + | |
| 282 | + | |
| 185 | 283 |  @pytest.mark.datafiles(DATA_DIR)
 | 
| 186 | 284 |  @pytest.mark.parametrize("kind", repo_kinds)
 | 
| 187 | 285 |  def test_open_track(cli, tmpdir, datafiles, kind):
 | 
| ... | ... | @@ -204,7 +302,7 @@ def test_open_force(cli, tmpdir, datafiles, kind): | 
| 204 | 302 |  | 
| 205 | 303 |      # Now open the workspace again with --force, this should happily succeed
 | 
| 206 | 304 |      result = cli.run(project=project, args=[
 | 
| 207 | -        'workspace', 'open', '--force', element_name, workspace
 | |
| 305 | +        'workspace', 'open', '--force', '--directory', workspace, element_name
 | |
| 208 | 306 |      ])
 | 
| 209 | 307 |      result.assert_success()
 | 
| 210 | 308 |  | 
| ... | ... | @@ -219,7 +317,7 @@ def test_open_force_open(cli, tmpdir, datafiles, kind): | 
| 219 | 317 |  | 
| 220 | 318 |      # Now open the workspace again with --force, this should happily succeed
 | 
| 221 | 319 |      result = cli.run(project=project, args=[
 | 
| 222 | -        'workspace', 'open', '--force', element_name, workspace
 | |
| 320 | +        'workspace', 'open', '--force', '--directory', workspace, element_name
 | |
| 223 | 321 |      ])
 | 
| 224 | 322 |      result.assert_success()
 | 
| 225 | 323 |  | 
| ... | ... | @@ -250,7 +348,7 @@ def test_open_force_different_workspace(cli, tmpdir, datafiles, kind): | 
| 250 | 348 |  | 
| 251 | 349 |      # Now open the workspace again with --force, this should happily succeed
 | 
| 252 | 350 |      result = cli.run(project=project, args=[
 | 
| 253 | -        'workspace', 'open', '--force', element_name2, workspace
 | |
| 351 | +        'workspace', 'open', '--force', '--directory', workspace, element_name2
 | |
| 254 | 352 |      ])
 | 
| 255 | 353 |  | 
| 256 | 354 |      # Assert that the file in workspace 1 has been replaced
 | 
| ... | ... | @@ -558,7 +656,7 @@ def test_buildable_no_ref(cli, tmpdir, datafiles): | 
| 558 | 656 |      # Now open the workspace. We don't need to checkout the source though.
 | 
| 559 | 657 |      workspace = os.path.join(str(tmpdir), 'workspace-no-ref')
 | 
| 560 | 658 |      os.makedirs(workspace)
 | 
| 561 | -    args = ['workspace', 'open', '--no-checkout', element_name, workspace]
 | |
| 659 | +    args = ['workspace', 'open', '--no-checkout', '--directory', workspace, element_name]
 | |
| 562 | 660 |      result = cli.run(project=project, args=args)
 | 
| 563 | 661 |      result.assert_success()
 | 
| 564 | 662 |  | 
| ... | ... | @@ -820,7 +918,7 @@ def test_list_supported_workspace(cli, tmpdir, datafiles, workspace_cfg, expecte | 
| 820 | 918 |                              element_name))
 | 
| 821 | 919 |  | 
| 822 | 920 |      # Make a change to the workspaces file
 | 
| 823 | -    result = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
 | |
| 921 | +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
 | |
| 824 | 922 |      result.assert_success()
 | 
| 825 | 923 |      result = cli.run(project=project, args=['workspace', 'close', '--remove-dir', element_name])
 | 
| 826 | 924 |      result.assert_success()
 | 
| ... | ... | @@ -278,7 +278,7 @@ def test_workspace_visible(cli, tmpdir, datafiles): | 
| 278 | 278 |  | 
| 279 | 279 |      # Open a workspace on our build failing element
 | 
| 280 | 280 |      #
 | 
| 281 | -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
 | |
| 281 | +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
 | |
| 282 | 282 |      assert res.exit_code == 0
 | 
| 283 | 283 |  | 
| 284 | 284 |      # Ensure the dependencies of our build failing element are built
 | 
| ... | ... | @@ -23,7 +23,7 @@ def test_workspace_mount(cli, tmpdir, datafiles): | 
| 23 | 23 |      workspace = os.path.join(cli.directory, 'workspace')
 | 
| 24 | 24 |      element_name = 'workspace/workspace-mount.bst'
 | 
| 25 | 25 |  | 
| 26 | -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
 | |
| 26 | +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
 | |
| 27 | 27 |      assert res.exit_code == 0
 | 
| 28 | 28 |  | 
| 29 | 29 |      res = cli.run(project=project, args=['build', element_name])
 | 
| ... | ... | @@ -39,7 +39,7 @@ def test_workspace_commanddir(cli, tmpdir, datafiles): | 
| 39 | 39 |      workspace = os.path.join(cli.directory, 'workspace')
 | 
| 40 | 40 |      element_name = 'workspace/workspace-commanddir.bst'
 | 
| 41 | 41 |  | 
| 42 | -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
 | |
| 42 | +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
 | |
| 43 | 43 |      assert res.exit_code == 0
 | 
| 44 | 44 |  | 
| 45 | 45 |      res = cli.run(project=project, args=['build', element_name])
 | 
| ... | ... | @@ -75,7 +75,7 @@ def test_workspace_updated_dependency(cli, tmpdir, datafiles): | 
| 75 | 75 |      _yaml.dump(dependency, os.path.join(element_path, dep_name))
 | 
| 76 | 76 |  | 
| 77 | 77 |      # First open the workspace
 | 
| 78 | -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
 | |
| 78 | +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
 | |
| 79 | 79 |      assert res.exit_code == 0
 | 
| 80 | 80 |  | 
| 81 | 81 |      # We build the workspaced element, so that we have an artifact
 | 
| ... | ... | @@ -130,7 +130,7 @@ def test_workspace_update_dependency_failed(cli, tmpdir, datafiles): | 
| 130 | 130 |      _yaml.dump(dependency, os.path.join(element_path, dep_name))
 | 
| 131 | 131 |  | 
| 132 | 132 |      # First open the workspace
 | 
| 133 | -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
 | |
| 133 | +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
 | |
| 134 | 134 |      assert res.exit_code == 0
 | 
| 135 | 135 |  | 
| 136 | 136 |      # We build the workspaced element, so that we have an artifact
 | 
| ... | ... | @@ -205,7 +205,7 @@ def test_updated_dependency_nested(cli, tmpdir, datafiles): | 
| 205 | 205 |      _yaml.dump(dependency, os.path.join(element_path, dep_name))
 | 
| 206 | 206 |  | 
| 207 | 207 |      # First open the workspace
 | 
| 208 | -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
 | |
| 208 | +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
 | |
| 209 | 209 |      assert res.exit_code == 0
 | 
| 210 | 210 |  | 
| 211 | 211 |      # We build the workspaced element, so that we have an artifact
 | 
| ... | ... | @@ -258,7 +258,7 @@ def test_incremental_configure_commands_run_only_once(cli, tmpdir, datafiles): | 
| 258 | 258 |      _yaml.dump(element, os.path.join(element_path, element_name))
 | 
| 259 | 259 |  | 
| 260 | 260 |      # We open a workspace on the above element
 | 
| 261 | -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
 | |
| 261 | +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
 | |
| 262 | 262 |      res.assert_success()
 | 
| 263 | 263 |  | 
| 264 | 264 |      # Then we build, and check whether the configure step succeeded
 | 
| ... | ... | @@ -108,7 +108,7 @@ def test_filter_forbid_also_rdep(datafiles, cli): | 
| 108 | 108 |  def test_filter_workspace_open(datafiles, cli, tmpdir):
 | 
| 109 | 109 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 110 | 110 |      workspace_dir = os.path.join(tmpdir.dirname, tmpdir.basename, "workspace")
 | 
| 111 | -    result = cli.run(project=project, args=['workspace', 'open', 'deps-permitted.bst', workspace_dir])
 | |
| 111 | +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace_dir, 'deps-permitted.bst'])
 | |
| 112 | 112 |      result.assert_success()
 | 
| 113 | 113 |      assert os.path.exists(os.path.join(workspace_dir, "foo"))
 | 
| 114 | 114 |      assert os.path.exists(os.path.join(workspace_dir, "bar"))
 | 
| ... | ... | @@ -120,7 +120,7 @@ def test_filter_workspace_build(datafiles, cli, tmpdir): | 
| 120 | 120 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 121 | 121 |      tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
 | 
| 122 | 122 |      workspace_dir = os.path.join(tempdir, "workspace")
 | 
| 123 | -    result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
 | |
| 123 | +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace_dir, 'output-orphans.bst'])
 | |
| 124 | 124 |      result.assert_success()
 | 
| 125 | 125 |      src = os.path.join(workspace_dir, "foo")
 | 
| 126 | 126 |      dst = os.path.join(workspace_dir, "quux")
 | 
| ... | ... | @@ -138,7 +138,7 @@ def test_filter_workspace_close(datafiles, cli, tmpdir): | 
| 138 | 138 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 139 | 139 |      tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
 | 
| 140 | 140 |      workspace_dir = os.path.join(tempdir, "workspace")
 | 
| 141 | -    result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
 | |
| 141 | +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace_dir, 'output-orphans.bst'])
 | |
| 142 | 142 |      result.assert_success()
 | 
| 143 | 143 |      src = os.path.join(workspace_dir, "foo")
 | 
| 144 | 144 |      dst = os.path.join(workspace_dir, "quux")
 | 
| ... | ... | @@ -158,7 +158,7 @@ def test_filter_workspace_reset(datafiles, cli, tmpdir): | 
| 158 | 158 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 159 | 159 |      tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
 | 
| 160 | 160 |      workspace_dir = os.path.join(tempdir, "workspace")
 | 
| 161 | -    result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
 | |
| 161 | +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace_dir, 'output-orphans.bst'])
 | |
| 162 | 162 |      result.assert_success()
 | 
| 163 | 163 |      src = os.path.join(workspace_dir, "foo")
 | 
| 164 | 164 |      dst = os.path.join(workspace_dir, "quux")
 | 
