... |
... |
@@ -31,7 +31,7 @@ import shutil |
31
|
31
|
import subprocess
|
32
|
32
|
from ruamel.yaml.comments import CommentedSet
|
33
|
33
|
from tests.testutils import cli, create_repo, ALL_REPO_KINDS, wait_for_cache_granularity
|
34
|
|
-from tests.testutils import create_artifact_share
|
|
34
|
+from tests.testutils import create_artifact_share, create_element_size
|
35
|
35
|
|
36
|
36
|
from buildstream import _yaml
|
37
|
37
|
from buildstream._exceptions import ErrorDomain, LoadError, LoadErrorReason
|
... |
... |
@@ -121,7 +121,7 @@ class WorkspaceCreater(): |
121
|
121
|
return element_tuples
|
122
|
122
|
|
123
|
123
|
def open_workspaces(self, kinds, track, suffixs=None, workspace_dir=None,
|
124
|
|
- element_attrs=None):
|
|
124
|
+ element_attrs=None, no_checkout=False):
|
125
|
125
|
|
126
|
126
|
element_tuples = self.create_workspace_elements(kinds, track, suffixs, workspace_dir,
|
127
|
127
|
element_attrs)
|
... |
... |
@@ -132,6 +132,8 @@ class WorkspaceCreater(): |
132
|
132
|
args = ['workspace', 'open']
|
133
|
133
|
if track:
|
134
|
134
|
args.append('--track')
|
|
135
|
+ if no_checkout:
|
|
136
|
+ args.append('--no-checkout')
|
135
|
137
|
if workspace_dir is not None:
|
136
|
138
|
assert len(element_tuples) == 1, "test logic error"
|
137
|
139
|
_, workspace_dir = element_tuples[0]
|
... |
... |
@@ -142,25 +144,26 @@ class WorkspaceCreater(): |
142
|
144
|
|
143
|
145
|
result.assert_success()
|
144
|
146
|
|
145
|
|
- # Assert that we are now buildable because the source is now cached.
|
146
|
|
- states = self.cli.get_element_states(self.project_path, [
|
147
|
|
- e for e, _ in element_tuples
|
148
|
|
- ])
|
149
|
|
- assert not any(states[e] != 'buildable' for e, _ in element_tuples)
|
|
147
|
+ if not no_checkout:
|
|
148
|
+ # Assert that we are now buildable because the source is now cached.
|
|
149
|
+ states = self.cli.get_element_states(self.project_path, [
|
|
150
|
+ e for e, _ in element_tuples
|
|
151
|
+ ])
|
|
152
|
+ assert not any(states[e] != 'buildable' for e, _ in element_tuples)
|
150
|
153
|
|
151
|
|
- # Check that the executable hello file is found in each workspace
|
152
|
|
- for element_name, workspace_dir in element_tuples:
|
153
|
|
- filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello')
|
154
|
|
- assert os.path.exists(filename)
|
|
154
|
+ # Check that the executable hello file is found in each workspace
|
|
155
|
+ for element_name, workspace_dir in element_tuples:
|
|
156
|
+ filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello')
|
|
157
|
+ assert os.path.exists(filename)
|
155
|
158
|
|
156
|
159
|
return element_tuples
|
157
|
160
|
|
158
|
161
|
|
159
|
162
|
def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', workspace_dir=None,
|
160
|
|
- project_path=None, element_attrs=None):
|
|
163
|
+ project_path=None, element_attrs=None, no_checkout=False):
|
161
|
164
|
workspace_object = WorkspaceCreater(cli, tmpdir, datafiles, project_path)
|
162
|
165
|
workspaces = workspace_object.open_workspaces((kind, ), track, (suffix, ), workspace_dir,
|
163
|
|
- element_attrs)
|
|
166
|
+ element_attrs, no_checkout)
|
164
|
167
|
assert len(workspaces) == 1
|
165
|
168
|
element_name, workspace = workspaces[0]
|
166
|
169
|
return element_name, workspace_object.project_path, workspace
|
... |
... |
@@ -1073,25 +1076,35 @@ def test_multiple_failed_builds(cli, tmpdir, datafiles): |
1073
|
1076
|
@pytest.mark.parametrize('subdir', [True, False], ids=["subdir", "no-subdir"])
|
1074
|
1077
|
@pytest.mark.parametrize("guess_element", [True, False], ids=["guess", "no-guess"])
|
1075
|
1078
|
def test_external_fetch(cli, datafiles, tmpdir_factory, subdir, guess_element):
|
1076
|
|
- # Fetching from a workspace outside a project doesn't fail horribly
|
|
1079
|
+ # An element with an open workspace can't be fetched, but we still expect fetches
|
|
1080
|
+ # to fetch any dependencies
|
1077
|
1081
|
tmpdir = tmpdir_factory.mktemp('')
|
1078
|
|
- element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
|
|
1082
|
+ depend_element = 'fetchable.bst'
|
|
1083
|
+
|
|
1084
|
+ # Create an element to fetch (local sources do not need to fetch)
|
|
1085
|
+ create_element_size(depend_element, str(datafiles), 'elements', [], 1024)
|
|
1086
|
+
|
|
1087
|
+ element_name, project, workspace = open_workspace(
|
|
1088
|
+ cli, tmpdir, datafiles, "git", False, no_checkout=True,
|
|
1089
|
+ element_attrs={'depends': [depend_element]}
|
|
1090
|
+ )
|
1079
|
1091
|
arg_elm = [element_name] if not guess_element else []
|
1080
|
1092
|
|
1081
|
1093
|
if subdir:
|
1082
|
1094
|
call_dir = os.path.join(workspace, 'usr')
|
|
1095
|
+ os.makedirs(call_dir, exist_ok=True)
|
1083
|
1096
|
else:
|
1084
|
1097
|
call_dir = workspace
|
1085
|
1098
|
|
|
1099
|
+ # Assert that the depended element is not fetched yet
|
|
1100
|
+ assert cli.get_element_state(str(datafiles), depend_element) == 'fetch needed'
|
|
1101
|
+
|
|
1102
|
+ # Fetch the workspaced element
|
1086
|
1103
|
result = cli.run(project=project, args=['-C', call_dir, 'source', 'fetch'] + arg_elm)
|
1087
|
1104
|
result.assert_success()
|
1088
|
1105
|
|
1089
|
|
- # We already fetched it by opening the workspace, but we're also checking
|
1090
|
|
- # `bst show` works here
|
1091
|
|
- result = cli.run(project=project,
|
1092
|
|
- args=['-C', call_dir, 'show', '--deps', 'none', '--format', '%{state}'] + arg_elm)
|
1093
|
|
- result.assert_success()
|
1094
|
|
- assert result.output.strip() == 'buildable'
|
|
1106
|
+ # Assert that the depended element has now been fetched
|
|
1107
|
+ assert cli.get_element_state(str(datafiles), depend_element) == 'buildable'
|
1095
|
1108
|
|
1096
|
1109
|
|
1097
|
1110
|
@pytest.mark.datafiles(DATA_DIR)
|
... |
... |
@@ -1120,16 +1133,24 @@ def test_external_push_pull(cli, datafiles, tmpdir_factory, guess_element): |
1120
|
1133
|
@pytest.mark.datafiles(DATA_DIR)
|
1121
|
1134
|
@pytest.mark.parametrize("guess_element", [True, False], ids=["guess", "no-guess"])
|
1122
|
1135
|
def test_external_track(cli, datafiles, tmpdir_factory, guess_element):
|
1123
|
|
- # Tracking does not get horribly confused
|
1124
|
1136
|
tmpdir = tmpdir_factory.mktemp('')
|
1125
|
|
- element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", True)
|
|
1137
|
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
|
|
1138
|
+ element_file = os.path.join(str(datafiles), 'elements', element_name)
|
1126
|
1139
|
arg_elm = [element_name] if not guess_element else []
|
1127
|
1140
|
|
1128
|
|
- # The workspace is necessarily already tracked, so we only care that
|
1129
|
|
- # there's no weird errors.
|
|
1141
|
+ # Delete the ref from the source so that we can detect if the
|
|
1142
|
+ # element has been tracked
|
|
1143
|
+ element_contents = _yaml.load(element_file)
|
|
1144
|
+ del element_contents['sources'][0]['ref']
|
|
1145
|
+ _yaml.dump(_yaml.node_sanitize(element_contents), element_file)
|
|
1146
|
+
|
1130
|
1147
|
result = cli.run(project=project, args=['-C', workspace, 'source', 'track'] + arg_elm)
|
1131
|
1148
|
result.assert_success()
|
1132
|
1149
|
|
|
1150
|
+ # Element is tracked now
|
|
1151
|
+ element_contents = _yaml.load(element_file)
|
|
1152
|
+ assert 'ref' in element_contents['sources'][0]
|
|
1153
|
+
|
1133
|
1154
|
|
1134
|
1155
|
@pytest.mark.datafiles(DATA_DIR)
|
1135
|
1156
|
def test_external_open_other(cli, datafiles, tmpdir_factory):
|