Jonathan Maw pushed to branch jonathan/workspace-fragment-create at BuildStream / buildstream
Commits:
-
6e2b1526
by Jonathan Maw at 2018-11-13T13:54:38Z
-
7617e3a9
by Jonathan Maw at 2018-11-13T13:54:38Z
-
d6ca4e27
by Jonathan Maw at 2018-11-13T13:54:38Z
-
1c957239
by Jonathan Maw at 2018-11-13T13:54:38Z
-
fe9a4cb8
by Jonathan Maw at 2018-11-13T13:54:38Z
-
01aa2a70
by Jonathan Maw at 2018-11-13T13:54:38Z
-
69a09684
by Jonathan Maw at 2018-11-13T13:54:38Z
-
6883c907
by Jonathan Maw at 2018-11-13T13:54:38Z
-
e2085be9
by Jonathan Maw at 2018-11-13T13:54:38Z
-
c8b54e8f
by Jonathan Maw at 2018-11-13T13:54:38Z
-
359c2eae
by Jonathan Maw at 2018-11-13T13:54:38Z
-
3d6d33d2
by Jonathan Maw at 2018-11-13T13:54:38Z
7 changed files:
- buildstream/_frontend/cli.py
- buildstream/_project.py
- buildstream/_stream.py
- buildstream/_workspaces.py
- buildstream/utils.py
- tests/frontend/workspace.py
- tests/integration/shell.py
Changes:
... | ... | @@ -59,18 +59,9 @@ def complete_target(args, incomplete): |
59 | 59 |
:return: all the possible user-specified completions for the param
|
60 | 60 |
"""
|
61 | 61 |
|
62 |
+ from .. import utils
|
|
62 | 63 |
project_conf = 'project.conf'
|
63 | 64 |
|
64 |
- def ensure_project_dir(directory):
|
|
65 |
- directory = os.path.abspath(directory)
|
|
66 |
- while not os.path.isfile(os.path.join(directory, project_conf)):
|
|
67 |
- parent_dir = os.path.dirname(directory)
|
|
68 |
- if directory == parent_dir:
|
|
69 |
- break
|
|
70 |
- directory = parent_dir
|
|
71 |
- |
|
72 |
- return directory
|
|
73 |
- |
|
74 | 65 |
# First resolve the directory, in case there is an
|
75 | 66 |
# active --directory/-C option
|
76 | 67 |
#
|
... | ... | @@ -89,7 +80,7 @@ def complete_target(args, incomplete): |
89 | 80 |
else:
|
90 | 81 |
# Check if this directory or any of its parent directories
|
91 | 82 |
# contain a project config file
|
92 |
- base_directory = ensure_project_dir(base_directory)
|
|
83 |
+ base_directory = utils._search_upward_for_file(base_directory, project_conf)
|
|
93 | 84 |
|
94 | 85 |
# Now parse the project.conf just to find the element path,
|
95 | 86 |
# this is unfortunately a bit heavy.
|
... | ... | @@ -713,10 +704,12 @@ def workspace_open(app, no_checkout, force, track_, element, directory): |
713 | 704 |
help="Remove the path that contains the closed workspace")
|
714 | 705 |
@click.option('--all', '-a', 'all_', default=False, is_flag=True,
|
715 | 706 |
help="Close all open workspaces")
|
707 |
+@click.option('--force', '-f', default=False, is_flag=True,
|
|
708 |
+ help="Always close the workspace and/or delete your changes")
|
|
716 | 709 |
@click.argument('elements', nargs=-1,
|
717 | 710 |
type=click.Path(readable=False))
|
718 | 711 |
@click.pass_obj
|
719 |
-def workspace_close(app, remove_dir, all_, elements):
|
|
712 |
+def workspace_close(app, remove_dir, all_, force, elements):
|
|
720 | 713 |
"""Close a workspace"""
|
721 | 714 |
|
722 | 715 |
if not (all_ or elements):
|
... | ... | @@ -735,15 +728,25 @@ def workspace_close(app, remove_dir, all_, elements): |
735 | 728 |
|
736 | 729 |
elements = app.stream.redirect_element_names(elements)
|
737 | 730 |
|
738 |
- # Check that the workspaces in question exist
|
|
731 |
+ # Check that the workspaces in question exist, and that it's safe to
|
|
732 |
+ # remove them.
|
|
739 | 733 |
nonexisting = []
|
740 | 734 |
for element_name in elements:
|
741 | 735 |
if not app.stream.workspace_exists(element_name):
|
742 | 736 |
nonexisting.append(element_name)
|
737 |
+ if app.stream.workspace_is_required(element_name):
|
|
738 |
+ if app.interactive:
|
|
739 |
+ click.echo("Removing '{}' will prevent you from running buildstream commands".format(element_name))
|
|
740 |
+ if not click.confirm('Are you sure you want to close this workspace?'):
|
|
741 |
+ click.echo('Aborting', err=True)
|
|
742 |
+ sys.exit(-1)
|
|
743 |
+ elif not force:
|
|
744 |
+ raise AppError("Cannot close workspaces. Workspace {} is being used to load the project"
|
|
745 |
+ .format(element_name), reason='closing-required-workspace')
|
|
743 | 746 |
if nonexisting:
|
744 | 747 |
raise AppError("Workspace does not exist", detail="\n".join(nonexisting))
|
745 | 748 |
|
746 |
- if app.interactive and remove_dir:
|
|
749 |
+ if app.interactive and remove_dir and not force:
|
|
747 | 750 |
if not click.confirm('This will remove all your changes, are you sure?'):
|
748 | 751 |
click.echo('Aborting', err=True)
|
749 | 752 |
sys.exit(-1)
|
... | ... | @@ -40,6 +40,7 @@ from .element import Element |
40 | 40 |
from ._message import Message, MessageType
|
41 | 41 |
from ._includes import Includes
|
42 | 42 |
from ._platform import Platform
|
43 |
+from ._workspaces import WorkspaceLocal
|
|
43 | 44 |
|
44 | 45 |
|
45 | 46 |
# Project Configuration file
|
... | ... | @@ -94,8 +95,8 @@ class Project(): |
94 | 95 |
# The project name
|
95 | 96 |
self.name = None
|
96 | 97 |
|
97 |
- # The project directory
|
|
98 |
- self.directory = self._ensure_project_dir(directory)
|
|
98 |
+ # The project directory, and whether the project was found from an external workspace
|
|
99 |
+ self.directory, self._required_workspace_element = self._find_project_dir(directory)
|
|
99 | 100 |
|
100 | 101 |
# Absolute path to where elements are loaded from within the project
|
101 | 102 |
self.element_path = None
|
... | ... | @@ -370,6 +371,14 @@ class Project(): |
370 | 371 |
|
371 | 372 |
self._load_second_pass()
|
372 | 373 |
|
374 |
+ # required_workspace_element()
|
|
375 |
+ #
|
|
376 |
+ # Returns the element whose workspace is required to load this project,
|
|
377 |
+ # if any.
|
|
378 |
+ #
|
|
379 |
+ def required_workspace_element(self):
|
|
380 |
+ return self._required_workspace_element
|
|
381 |
+ |
|
373 | 382 |
# cleanup()
|
374 | 383 |
#
|
375 | 384 |
# Cleans up resources used loading elements
|
... | ... | @@ -651,7 +660,7 @@ class Project(): |
651 | 660 |
# Source url aliases
|
652 | 661 |
output._aliases = _yaml.node_get(config, Mapping, 'aliases', default_value={})
|
653 | 662 |
|
654 |
- # _ensure_project_dir()
|
|
663 |
+ # _find_project_dir()
|
|
655 | 664 |
#
|
656 | 665 |
# Returns path of the project directory, if a configuration file is found
|
657 | 666 |
# in given directory or any of its parent directories.
|
... | ... | @@ -662,18 +671,24 @@ class Project(): |
662 | 671 |
# Raises:
|
663 | 672 |
# LoadError if project.conf is not found
|
664 | 673 |
#
|
665 |
- def _ensure_project_dir(self, directory):
|
|
666 |
- directory = os.path.abspath(directory)
|
|
667 |
- while not os.path.isfile(os.path.join(directory, _PROJECT_CONF_FILE)):
|
|
668 |
- parent_dir = os.path.dirname(directory)
|
|
669 |
- if directory == parent_dir:
|
|
674 |
+ # Returns:
|
|
675 |
+ # (str) - the directory that contains the project, and
|
|
676 |
+ # (str) - the name of the element required to find the project, or an empty string
|
|
677 |
+ def _find_project_dir(self, directory):
|
|
678 |
+ workspace_element = ""
|
|
679 |
+ project_directory = utils._search_upward_for_file(directory, _PROJECT_CONF_FILE)
|
|
680 |
+ if not project_directory:
|
|
681 |
+ workspace_local = WorkspaceLocal.load(directory)
|
|
682 |
+ if workspace_local:
|
|
683 |
+ project_directory = workspace_local.get_default_path()
|
|
684 |
+ workspace_element = workspace_local.get_default_element()
|
|
685 |
+ else:
|
|
670 | 686 |
raise LoadError(
|
671 | 687 |
LoadErrorReason.MISSING_PROJECT_CONF,
|
672 | 688 |
'{} not found in current directory or any of its parent directories'
|
673 | 689 |
.format(_PROJECT_CONF_FILE))
|
674 |
- directory = parent_dir
|
|
675 | 690 |
|
676 |
- return directory
|
|
691 |
+ return project_directory, workspace_element
|
|
677 | 692 |
|
678 | 693 |
def _load_plugin_factories(self, config, output):
|
679 | 694 |
plugin_source_origins = [] # Origins of custom sources
|
... | ... | @@ -32,6 +32,7 @@ from ._exceptions import StreamError, ImplError, BstError, set_last_task_error |
32 | 32 |
from ._message import Message, MessageType
|
33 | 33 |
from ._scheduler import Scheduler, SchedStatus, TrackQueue, FetchQueue, BuildQueue, PullQueue, PushQueue
|
34 | 34 |
from ._pipeline import Pipeline, PipelineSelection
|
35 |
+from ._workspaces import WorkspaceLocal
|
|
35 | 36 |
from . import utils, _yaml, _site
|
36 | 37 |
from . import Scope, Consistency
|
37 | 38 |
|
... | ... | @@ -516,6 +517,10 @@ class Stream(): |
516 | 517 |
with target.timed_activity("Staging sources to {}".format(directory)):
|
517 | 518 |
target._open_workspace()
|
518 | 519 |
|
520 |
+ project = self._context.get_toplevel_project()
|
|
521 |
+ workspace_local = WorkspaceLocal.create(directory, project.directory, target._get_full_name())
|
|
522 |
+ workspace_local.write()
|
|
523 |
+ |
|
519 | 524 |
workspaces.save_config()
|
520 | 525 |
self._message(MessageType.INFO, "Saved workspace configuration")
|
521 | 526 |
|
... | ... | @@ -540,6 +545,11 @@ class Stream(): |
540 | 545 |
except OSError as e:
|
541 | 546 |
raise StreamError("Could not remove '{}': {}"
|
542 | 547 |
.format(workspace.get_absolute_path(), e)) from e
|
548 |
+ else:
|
|
549 |
+ # TODO: At some point, closing a workspace only deletes the file if no projects are using it.
|
|
550 |
+ workspace_local = WorkspaceLocal.load(workspace.get_absolute_path())
|
|
551 |
+ if workspace_local:
|
|
552 |
+ workspace_local.delete()
|
|
543 | 553 |
|
544 | 554 |
# Delete the workspace and save the configuration
|
545 | 555 |
workspaces.delete_workspace(element_name)
|
... | ... | @@ -633,6 +643,20 @@ class Stream(): |
633 | 643 |
|
634 | 644 |
return False
|
635 | 645 |
|
646 |
+ # workspace_is_required()
|
|
647 |
+ #
|
|
648 |
+ # Checks whether the workspace belonging to element_name is required to
|
|
649 |
+ # load the project
|
|
650 |
+ #
|
|
651 |
+ # Args:
|
|
652 |
+ # element_name (str): The element whose workspace may be required
|
|
653 |
+ #
|
|
654 |
+ # Returns:
|
|
655 |
+ # (bool): True if the workspace is required
|
|
656 |
+ def workspace_is_required(self, element_name):
|
|
657 |
+ required_elm = self._project.required_workspace_element()
|
|
658 |
+ return required_elm == element_name
|
|
659 |
+ |
|
636 | 660 |
# workspace_list
|
637 | 661 |
#
|
638 | 662 |
# Serializes the workspaces and dumps them in YAML to stdout.
|
... | ... | @@ -25,6 +25,149 @@ from ._exceptions import LoadError, LoadErrorReason |
25 | 25 |
|
26 | 26 |
|
27 | 27 |
BST_WORKSPACE_FORMAT_VERSION = 3
|
28 |
+BST_WORKSPACE_LOCAL_FORMAT_VERSION = 1
|
|
29 |
+WORKSPACE_LOCAL_FILE = ".bstproject.yaml"
|
|
30 |
+ |
|
31 |
+ |
|
32 |
+# WorkspaceLocal()
|
|
33 |
+#
|
|
34 |
+# An object to contain various helper functions and data required for
|
|
35 |
+# referring from a workspace back to buildstream.
|
|
36 |
+#
|
|
37 |
+# Args:
|
|
38 |
+# directory (str): The directory that the workspace exists in
|
|
39 |
+# project_path (str): The project path used to refer back
|
|
40 |
+# to buildstream projects.
|
|
41 |
+# element_name (str): The name of the element used to create this workspace.
|
|
42 |
+class WorkspaceLocal():
|
|
43 |
+ def __init__(self, directory, project_path="", element_name=""):
|
|
44 |
+ self._projects = []
|
|
45 |
+ self._directory = directory
|
|
46 |
+ |
|
47 |
+ assert (project_path and element_name) or (not project_path and not element_name)
|
|
48 |
+ if project_path:
|
|
49 |
+ self._add_project(project_path, element_name)
|
|
50 |
+ |
|
51 |
+ # get_default_path()
|
|
52 |
+ #
|
|
53 |
+ # Retrieves the default path to a project.
|
|
54 |
+ #
|
|
55 |
+ # Returns:
|
|
56 |
+ # (str): The path to a project
|
|
57 |
+ def get_default_path(self):
|
|
58 |
+ return self._projects[0]['project-path']
|
|
59 |
+ |
|
60 |
+ # get_default_element()
|
|
61 |
+ #
|
|
62 |
+ # Retrieves the name of the element that owns this workspace.
|
|
63 |
+ #
|
|
64 |
+ # Returns:
|
|
65 |
+ # (str): The name of an element
|
|
66 |
+ def get_default_element(self):
|
|
67 |
+ return self._projects[0]['element-name']
|
|
68 |
+ |
|
69 |
+ # to_dict()
|
|
70 |
+ #
|
|
71 |
+ # Turn the members data into a dict for serialization purposes
|
|
72 |
+ #
|
|
73 |
+ # Returns:
|
|
74 |
+ # (dict): A dict representation of the WorkspaceLocal
|
|
75 |
+ #
|
|
76 |
+ def to_dict(self):
|
|
77 |
+ ret = {
|
|
78 |
+ 'projects': self._projects,
|
|
79 |
+ 'format-version': BST_WORKSPACE_LOCAL_FORMAT_VERSION,
|
|
80 |
+ }
|
|
81 |
+ return ret
|
|
82 |
+ |
|
83 |
+ # from_dict()
|
|
84 |
+ #
|
|
85 |
+ # Loads a new WorkspaceLocal from a simple dictionary
|
|
86 |
+ #
|
|
87 |
+ # Args:
|
|
88 |
+ # directory (str): The directory that the workspace exists in
|
|
89 |
+ # dictionary (dict): The dict to generate a WorkspaceLocal from
|
|
90 |
+ #
|
|
91 |
+ # Returns:
|
|
92 |
+ # (WorkspaceLocal): A newly instantiated WorkspaceLocal
|
|
93 |
+ @classmethod
|
|
94 |
+ def from_dict(cls, directory, dictionary):
|
|
95 |
+ # Only know how to handle one format-version at the moment.
|
|
96 |
+ format_version = int(dictionary['format-version'])
|
|
97 |
+ assert format_version == BST_WORKSPACE_LOCAL_FORMAT_VERSION, \
|
|
98 |
+ "Format version {} not found in {}".format(BST_WORKSPACE_LOCAL_FORMAT_VERSION, dictionary)
|
|
99 |
+ |
|
100 |
+ workspace_local = cls(directory)
|
|
101 |
+ for item in dictionary['projects']:
|
|
102 |
+ workspace_local._add_project(item['project-path'], item['element-name'])
|
|
103 |
+ |
|
104 |
+ return workspace_local
|
|
105 |
+ |
|
106 |
+ # create()
|
|
107 |
+ #
|
|
108 |
+ # Creates a new WorkspaceLocal
|
|
109 |
+ #
|
|
110 |
+ # Args:
|
|
111 |
+ # directory (str): The directory that the workspace exists in
|
|
112 |
+ # project_path (str): The path to the project to store
|
|
113 |
+ # element_name (str): The name of the element within the project
|
|
114 |
+ #
|
|
115 |
+ # Returns:
|
|
116 |
+ # (WorkspaceLocal): The created WorkspaceLocal
|
|
117 |
+ @classmethod
|
|
118 |
+ def create(cls, directory, project_path, element_name):
|
|
119 |
+ # TODO: Load WorkspaceLocal if it exists, and maybe add project_path to it
|
|
120 |
+ return cls(directory, project_path, element_name)
|
|
121 |
+ |
|
122 |
+ # load()
|
|
123 |
+ #
|
|
124 |
+ # Loads the WorkspaceLocal for a given directory. This directory may be a
|
|
125 |
+ # subdirectory of the workspace's directory.
|
|
126 |
+ #
|
|
127 |
+ # Args:
|
|
128 |
+ # directory (str): The directory
|
|
129 |
+ # Returns:
|
|
130 |
+ # (WorkspaceLocal): The created WorkspaceLocal, if in a workspace, or
|
|
131 |
+ # (NoneType): None, if the directory is not inside a workspace.
|
|
132 |
+ @classmethod
|
|
133 |
+ def load(cls, directory):
|
|
134 |
+ local_dir = cls.search_for_dir(directory)
|
|
135 |
+ if local_dir:
|
|
136 |
+ workspace_file = os.path.join(local_dir, WORKSPACE_LOCAL_FILE)
|
|
137 |
+ data_dict = _yaml.load(workspace_file)
|
|
138 |
+ return cls.from_dict(local_dir, data_dict)
|
|
139 |
+ else:
|
|
140 |
+ return None
|
|
141 |
+ |
|
142 |
+ # write()
|
|
143 |
+ #
|
|
144 |
+ # Writes the WorkspaceLocal to disk
|
|
145 |
+ def write(self):
|
|
146 |
+ os.makedirs(self._directory, exist_ok=True)
|
|
147 |
+ _yaml.dump(self.to_dict(), self._get_filename())
|
|
148 |
+ |
|
149 |
+ # delete()
|
|
150 |
+ #
|
|
151 |
+ # Deletes the WorkspaceLocal from disk, if it exists.
|
|
152 |
+ def delete(self):
|
|
153 |
+ try:
|
|
154 |
+ os.unlink(self._get_filename())
|
|
155 |
+ except FileNotFoundError:
|
|
156 |
+ pass
|
|
157 |
+ |
|
158 |
+ # search_for_dir()
|
|
159 |
+ #
|
|
160 |
+ # Returns the directory that contains the workspace local file,
|
|
161 |
+ # searching upwards from search_dir.
|
|
162 |
+ @staticmethod
|
|
163 |
+ def search_for_dir(search_dir):
|
|
164 |
+ return utils._search_upward_for_file(search_dir, WORKSPACE_LOCAL_FILE)
|
|
165 |
+ |
|
166 |
+ def _get_filename(self):
|
|
167 |
+ return os.path.join(self._directory, WORKSPACE_LOCAL_FILE)
|
|
168 |
+ |
|
169 |
+ def _add_project(self, project_path, element_name):
|
|
170 |
+ self._projects.append({'project-path': project_path, 'element-name': element_name})
|
|
28 | 171 |
|
29 | 172 |
|
30 | 173 |
# Workspace()
|
... | ... | @@ -174,10 +317,15 @@ class Workspace(): |
174 | 317 |
if recalculate or self._key is None:
|
175 | 318 |
fullpath = self.get_absolute_path()
|
176 | 319 |
|
320 |
+ excluded_files = [WORKSPACE_LOCAL_FILE]
|
|
321 |
+ |
|
177 | 322 |
# Get a list of tuples of the the project relative paths and fullpaths
|
178 | 323 |
if os.path.isdir(fullpath):
|
179 | 324 |
filelist = utils.list_relative_paths(fullpath)
|
180 |
- filelist = [(relpath, os.path.join(fullpath, relpath)) for relpath in filelist]
|
|
325 |
+ filelist = [
|
|
326 |
+ (relpath, os.path.join(fullpath, relpath)) for relpath in filelist
|
|
327 |
+ if relpath not in excluded_files
|
|
328 |
+ ]
|
|
181 | 329 |
else:
|
182 | 330 |
filelist = [(self.get_absolute_path(), fullpath)]
|
183 | 331 |
|
... | ... | @@ -1199,3 +1199,17 @@ def _deduplicate(iterable, key=None): |
1199 | 1199 |
def _get_link_mtime(path):
|
1200 | 1200 |
path_stat = os.lstat(path)
|
1201 | 1201 |
return path_stat.st_mtime
|
1202 |
+ |
|
1203 |
+ |
|
1204 |
+# Returns the first directory to contain filename, or an empty string if
|
|
1205 |
+# none found
|
|
1206 |
+#
|
|
1207 |
+def _search_upward_for_file(directory, filename):
|
|
1208 |
+ directory = os.path.abspath(directory)
|
|
1209 |
+ while not os.path.isfile(os.path.join(directory, filename)):
|
|
1210 |
+ parent_dir = os.path.dirname(directory)
|
|
1211 |
+ if directory == parent_dir:
|
|
1212 |
+ return ""
|
|
1213 |
+ directory = parent_dir
|
|
1214 |
+ |
|
1215 |
+ return directory
|
... | ... | @@ -29,6 +29,7 @@ import shutil |
29 | 29 |
import subprocess
|
30 | 30 |
from ruamel.yaml.comments import CommentedSet
|
31 | 31 |
from tests.testutils import cli, create_repo, ALL_REPO_KINDS, wait_for_cache_granularity
|
32 |
+from tests.testutils import create_artifact_share
|
|
32 | 33 |
|
33 | 34 |
from buildstream import _yaml
|
34 | 35 |
from buildstream._exceptions import ErrorDomain, LoadError, LoadErrorReason
|
... | ... | @@ -93,6 +94,13 @@ def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', workspace_dir |
93 | 94 |
|
94 | 95 |
result.assert_success()
|
95 | 96 |
|
97 |
+ # Assert that a .bstproject.yaml file has been created
|
|
98 |
+ # and contains the path to the project
|
|
99 |
+ bstproject_path = os.path.join(workspace_dir, '.bstproject.yaml')
|
|
100 |
+ assert os.path.exists(bstproject_path)
|
|
101 |
+ with open(bstproject_path) as f:
|
|
102 |
+ assert project_path in f.read()
|
|
103 |
+ |
|
96 | 104 |
# Assert that we are now buildable because the source is
|
97 | 105 |
# now cached.
|
98 | 106 |
assert cli.get_element_state(project_path, element_name) == 'buildable'
|
... | ... | @@ -148,6 +156,10 @@ def test_open_force(cli, tmpdir, datafiles, kind): |
148 | 156 |
# Assert the workspace dir still exists
|
149 | 157 |
assert os.path.exists(workspace)
|
150 | 158 |
|
159 |
+ # Assert the bstproject doesn't exist
|
|
160 |
+ bstproject_path = os.path.join(workspace, '.bstproject.yaml')
|
|
161 |
+ assert not os.path.exists(bstproject_path)
|
|
162 |
+ |
|
151 | 163 |
# Now open the workspace again with --force, this should happily succeed
|
152 | 164 |
result = cli.run(project=project, args=[
|
153 | 165 |
'workspace', 'open', '--force', element_name, workspace
|
... | ... | @@ -436,9 +448,12 @@ def test_list(cli, tmpdir, datafiles): |
436 | 448 |
@pytest.mark.datafiles(DATA_DIR)
|
437 | 449 |
@pytest.mark.parametrize("kind", repo_kinds)
|
438 | 450 |
@pytest.mark.parametrize("strict", [("strict"), ("non-strict")])
|
439 |
-def test_build(cli, tmpdir, datafiles, kind, strict):
|
|
451 |
+@pytest.mark.parametrize("call_from", [("project"), ("workspace")])
|
|
452 |
+def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from):
|
|
453 |
+ tmpdir = tmpdir_factory.mktemp('')
|
|
440 | 454 |
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False)
|
441 | 455 |
checkout = os.path.join(str(tmpdir), 'checkout')
|
456 |
+ args_pre = ['-C', workspace] if call_from == "project" else []
|
|
442 | 457 |
|
443 | 458 |
# Modify workspace
|
444 | 459 |
shutil.rmtree(os.path.join(workspace, 'usr', 'bin'))
|
... | ... | @@ -461,15 +476,14 @@ def test_build(cli, tmpdir, datafiles, kind, strict): |
461 | 476 |
# Build modified workspace
|
462 | 477 |
assert cli.get_element_state(project, element_name) == 'buildable'
|
463 | 478 |
assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
|
464 |
- result = cli.run(project=project, args=['build', element_name])
|
|
479 |
+ result = cli.run(project=project, args=args_pre + ['build', element_name])
|
|
465 | 480 |
result.assert_success()
|
466 | 481 |
assert cli.get_element_state(project, element_name) == 'cached'
|
467 | 482 |
assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
|
468 | 483 |
|
469 | 484 |
# Checkout the result
|
470 |
- result = cli.run(project=project, args=[
|
|
471 |
- 'checkout', element_name, checkout
|
|
472 |
- ])
|
|
485 |
+ result = cli.run(project=project,
|
|
486 |
+ args=args_pre + ['checkout', element_name, checkout])
|
|
473 | 487 |
result.assert_success()
|
474 | 488 |
|
475 | 489 |
# Check that the pony.conf from the modified workspace exists
|
... | ... | @@ -876,3 +890,128 @@ def test_multiple_failed_builds(cli, tmpdir, datafiles): |
876 | 890 |
result = cli.run(project=project, args=["build", element_name])
|
877 | 891 |
assert "BUG" not in result.stderr
|
878 | 892 |
assert cli.get_element_state(project, element_name) != "cached"
|
893 |
+ |
|
894 |
+ |
|
895 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
896 |
+def test_external_fetch(cli, datafiles, tmpdir_factory):
|
|
897 |
+ # Fetching from a workspace outside a project doesn't fail horribly
|
|
898 |
+ tmpdir = tmpdir_factory.mktemp('')
|
|
899 |
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
|
|
900 |
+ |
|
901 |
+ result = cli.run(project=project, args=['-C', workspace, 'fetch', element_name])
|
|
902 |
+ result.assert_success()
|
|
903 |
+ |
|
904 |
+ # We already fetched it by opening the workspace, but we're also checking
|
|
905 |
+ # `bst show` works here
|
|
906 |
+ assert cli.get_element_state(project, element_name) == 'buildable'
|
|
907 |
+ |
|
908 |
+ |
|
909 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
910 |
+def test_external_push_pull(cli, datafiles, tmpdir_factory):
|
|
911 |
+ # Pushing and pulling to/from an artifact cache works from an external workspace
|
|
912 |
+ tmpdir = tmpdir_factory.mktemp('')
|
|
913 |
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
|
|
914 |
+ |
|
915 |
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
|
|
916 |
+ result = cli.run(project=project, args=['-C', workspace, 'build', element_name])
|
|
917 |
+ result.assert_success()
|
|
918 |
+ |
|
919 |
+ cli.configure({
|
|
920 |
+ 'artifacts': {'url': share.repo, 'push': True}
|
|
921 |
+ })
|
|
922 |
+ |
|
923 |
+ result = cli.run(project=project, args=['-C', workspace, 'push', element_name])
|
|
924 |
+ result.assert_success()
|
|
925 |
+ |
|
926 |
+ result = cli.run(project=project, args=['-C', workspace, 'pull', '--deps', 'all', 'target.bst'])
|
|
927 |
+ result.assert_success()
|
|
928 |
+ |
|
929 |
+ |
|
930 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
931 |
+def test_external_track(cli, datafiles, tmpdir_factory):
|
|
932 |
+ # Tracking does not get horribly confused
|
|
933 |
+ tmpdir = tmpdir_factory.mktemp('')
|
|
934 |
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", True)
|
|
935 |
+ |
|
936 |
+ # The workspace is necessarily already tracked, so we only care that
|
|
937 |
+ # there's no weird errors.
|
|
938 |
+ result = cli.run(project=project, args=['-C', workspace, 'track', element_name])
|
|
939 |
+ result.assert_success()
|
|
940 |
+ |
|
941 |
+ |
|
942 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
943 |
+def test_external_open_other(cli, datafiles, tmpdir_factory):
|
|
944 |
+ # From inside an external workspace, open another workspace
|
|
945 |
+ tmpdir1 = tmpdir_factory.mktemp('')
|
|
946 |
+ tmpdir2 = tmpdir_factory.mktemp('')
|
|
947 |
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
|
|
948 |
+ alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
|
|
949 |
+ beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
|
|
950 |
+ |
|
951 |
+ # Closing the other element first, because I'm too lazy to create an
|
|
952 |
+ # element without opening it
|
|
953 |
+ result = cli.run(project=project, args=['workspace', 'close', beta_element])
|
|
954 |
+ result.assert_success()
|
|
955 |
+ |
|
956 |
+ result = cli.run(project=project, args=[
|
|
957 |
+ '-C', alpha_workspace, 'workspace', 'open', '--force', beta_element, beta_workspace
|
|
958 |
+ ])
|
|
959 |
+ result.assert_success()
|
|
960 |
+ |
|
961 |
+ |
|
962 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
963 |
+def test_external_close_other(cli, datafiles, tmpdir_factory):
|
|
964 |
+ # From inside an external workspace, close the other workspace
|
|
965 |
+ tmpdir1 = tmpdir_factory.mktemp('')
|
|
966 |
+ tmpdir2 = tmpdir_factory.mktemp('')
|
|
967 |
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
|
|
968 |
+ alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
|
|
969 |
+ beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
|
|
970 |
+ |
|
971 |
+ result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', beta_element])
|
|
972 |
+ result.assert_success()
|
|
973 |
+ |
|
974 |
+ |
|
975 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
976 |
+@pytest.mark.parametrize("force", [("force"), ("no-force")])
|
|
977 |
+def test_external_close_self(cli, datafiles, tmpdir_factory, force):
|
|
978 |
+ # From inside an external workspace, close it
|
|
979 |
+ # This is unwise, so is only allowed if --force
|
|
980 |
+ tmpdir1 = tmpdir_factory.mktemp('')
|
|
981 |
+ tmpdir2 = tmpdir_factory.mktemp('')
|
|
982 |
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
|
|
983 |
+ alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
|
|
984 |
+ beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
|
|
985 |
+ |
|
986 |
+ args = ['-C', alpha_workspace, 'workspace', 'close']
|
|
987 |
+ if force == "force":
|
|
988 |
+ args.append('--force')
|
|
989 |
+ args.append(alpha_element)
|
|
990 |
+ |
|
991 |
+ result = cli.run(project=project, args=args)
|
|
992 |
+ if force == "force":
|
|
993 |
+ result.assert_success()
|
|
994 |
+ else:
|
|
995 |
+ result.assert_main_error(ErrorDomain.APP, 'closing-required-workspace')
|
|
996 |
+ |
|
997 |
+ |
|
998 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
999 |
+def test_external_reset_other(cli, datafiles, tmpdir_factory):
|
|
1000 |
+ tmpdir1 = tmpdir_factory.mktemp('')
|
|
1001 |
+ tmpdir2 = tmpdir_factory.mktemp('')
|
|
1002 |
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
|
|
1003 |
+ alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
|
|
1004 |
+ beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
|
|
1005 |
+ |
|
1006 |
+ result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'reset', beta_element])
|
|
1007 |
+ result.assert_success()
|
|
1008 |
+ |
|
1009 |
+ |
|
1010 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
1011 |
+def test_external_list(cli, datafiles, tmpdir_factory):
|
|
1012 |
+ tmpdir = tmpdir_factory.mktemp('')
|
|
1013 |
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
|
|
1014 |
+ element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
|
|
1015 |
+ |
|
1016 |
+ result = cli.run(project=project, args=['-C', workspace, 'workspace', 'list'])
|
|
1017 |
+ result.assert_success()
|
... | ... | @@ -339,3 +339,28 @@ def test_integration_devices(cli, tmpdir, datafiles): |
339 | 339 |
|
340 | 340 |
result = execute_shell(cli, project, ["true"], element=element_name)
|
341 | 341 |
assert result.exit_code == 0
|
342 |
+ |
|
343 |
+ |
|
344 |
+# Test that a shell can be opened from an external workspace
|
|
345 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
346 |
+@pytest.mark.parametrize("build_shell", [("build"), ("nobuild")])
|
|
347 |
+def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_shell):
|
|
348 |
+ tmpdir = tmpdir_factory.mktemp("")
|
|
349 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
350 |
+ element_name = 'autotools/amhello.bst'
|
|
351 |
+ workspace_dir = os.path.join(str(tmpdir), 'workspace')
|
|
352 |
+ |
|
353 |
+ result = cli.run(project=project, args=[
|
|
354 |
+ 'workspace', 'open', element_name, workspace_dir
|
|
355 |
+ ])
|
|
356 |
+ result.assert_success()
|
|
357 |
+ |
|
358 |
+ result = cli.run(project=project, args=['-C', workspace_dir, 'build', element_name])
|
|
359 |
+ result.assert_success()
|
|
360 |
+ |
|
361 |
+ command = ['shell']
|
|
362 |
+ if build_shell == 'build':
|
|
363 |
+ command.append('--build')
|
|
364 |
+ command.extend([element_name, '--', 'true'])
|
|
365 |
+ result = cli.run(project=project, cwd=workspace_dir, args=command)
|
|
366 |
+ result.assert_success()
|