Will Salmon pushed to branch willsalmon/defaultWorkspaces at BuildStream / buildstream
Commits:
-
e16b5022
by William Salmon at 2018-10-24T13:38:34Z
3 changed files:
Changes:
... | ... | @@ -690,7 +690,8 @@ def workspace_open(app, no_checkout, force, track_, directory, elements): |
690 | 690 |
directories = []
|
691 | 691 |
if directory is not None:
|
692 | 692 |
if len(elements) > 1:
|
693 |
- raise "horible error"
|
|
693 |
+ click.echo("Directory option can only be used if a single element is given", err=True)
|
|
694 |
+ sys.exit(-1)
|
|
694 | 695 |
if os.path.exists(directory):
|
695 | 696 |
if not os.path.isdir(directory):
|
696 | 697 |
click.echo("Checkout directory is not a directory: {}".format(directory), err=True)
|
... | ... | @@ -705,11 +706,10 @@ def workspace_open(app, no_checkout, force, track_, directory, elements): |
705 | 706 |
directories.append(element.rstrip('.bst'))
|
706 | 707 |
|
707 | 708 |
with app.initialized():
|
708 |
- for element, directory in zip(elements, directories):
|
|
709 |
- app.stream.workspace_open(element, directory,
|
|
710 |
- no_checkout=no_checkout,
|
|
711 |
- track_first=track_,
|
|
712 |
- force=force)
|
|
709 |
+ app.stream.workspace_open(elements, directories,
|
|
710 |
+ no_checkout=no_checkout,
|
|
711 |
+ track_first=track_,
|
|
712 |
+ force=force)
|
|
713 | 713 |
|
714 | 714 |
|
715 | 715 |
##################################################################
|
... | ... | @@ -447,68 +447,70 @@ class Stream(): |
447 | 447 |
# track_first (bool): Whether to track and fetch first
|
448 | 448 |
# force (bool): Whether to ignore contents in an existing directory
|
449 | 449 |
#
|
450 |
- def workspace_open(self, target, directory, *,
|
|
450 |
+ def workspace_open(self, targets, directories, *,
|
|
451 | 451 |
no_checkout,
|
452 | 452 |
track_first,
|
453 | 453 |
force):
|
454 | 454 |
|
455 | 455 |
if track_first:
|
456 |
- track_targets = (target,)
|
|
456 |
+ track_targets = targets
|
|
457 | 457 |
else:
|
458 | 458 |
track_targets = ()
|
459 | 459 |
|
460 |
- elements, track_elements = self._load((target,), track_targets,
|
|
460 |
+ elements, track_elements = self._load(targets, track_targets,
|
|
461 | 461 |
selection=PipelineSelection.REDIRECT,
|
462 | 462 |
track_selection=PipelineSelection.REDIRECT)
|
463 |
- target = elements[0]
|
|
464 |
- directory = os.path.abspath(directory)
|
|
465 | 463 |
|
466 |
- if not list(target.sources()):
|
|
467 |
- build_depends = [x.name for x in target.dependencies(Scope.BUILD, recurse=False)]
|
|
468 |
- if not build_depends:
|
|
469 |
- raise StreamError("The given element has no sources")
|
|
470 |
- detail = "Try opening a workspace on one of its dependencies instead:\n"
|
|
471 |
- detail += " \n".join(build_depends)
|
|
472 |
- raise StreamError("The given element has no sources", detail=detail)
|
|
473 |
- |
|
474 |
- workspaces = self._context.get_workspaces()
|
|
475 |
- |
|
476 |
- # Check for workspace config
|
|
477 |
- workspace = workspaces.get_workspace(target._get_full_name())
|
|
478 |
- if workspace and not force:
|
|
479 |
- raise StreamError("Workspace '{}' is already defined at: {}"
|
|
464 |
+ for target, directory in zip(elements, directories):
|
|
465 |
+ directory = os.path.abspath(directory)
|
|
466 |
+
|
|
467 |
+ if not list(target.sources()):
|
|
468 |
+ build_depends = [x.name for x in target.dependencies(Scope.BUILD, recurse=False)]
|
|
469 |
+ if not build_depends:
|
|
470 |
+ raise StreamError("The given element has no sources")
|
|
471 |
+ detail = "Try opening a workspace on one of its dependencies instead:\n"
|
|
472 |
+ detail += " \n".join(build_depends)
|
|
473 |
+ raise StreamError("The given element has no sources", detail=detail)
|
|
474 |
+ |
|
475 |
+ workspaces = self._context.get_workspaces()
|
|
476 |
+ |
|
477 |
+ # Check for workspace config
|
|
478 |
+ workspace = workspaces.get_workspace(target._get_full_name())
|
|
479 |
+ if workspace and not force:
|
|
480 |
+ raise StreamError("Workspace '{}' is already defined at: {}"
|
|
480 | 481 |
.format(target.name, workspace.get_absolute_path()))
|
481 | 482 |
|
482 |
- # If we're going to checkout, we need at least a fetch,
|
|
483 |
- # if we were asked to track first, we're going to fetch anyway.
|
|
484 |
- #
|
|
485 |
- if not no_checkout or track_first:
|
|
486 |
- track_elements = []
|
|
487 |
- if track_first:
|
|
488 |
- track_elements = elements
|
|
489 |
- self._fetch(elements, track_elements=track_elements)
|
|
483 |
+ # If we're going to checkout, we need at least a fetch,
|
|
484 |
+ # if we were asked to track first, we're going to fetch anyway.
|
|
485 |
+ #
|
|
486 |
+ if not no_checkout or track_first:
|
|
487 |
+ track_elements = []
|
|
488 |
+ if track_first:
|
|
489 |
+ track_elements = elements
|
|
490 |
+ self._fetch(elements, track_elements=track_elements)
|
|
491 |
+ |
|
492 |
+ if not no_checkout and target._get_consistency() != Consistency.CACHED:
|
|
493 |
+ raise StreamError("Could not stage uncached source. " +
|
|
494 |
+ "Use `--track` to track and " +
|
|
495 |
+ "fetch the latest version of the " +
|
|
496 |
+ "source.")
|
|
490 | 497 |
|
491 |
- if not no_checkout and target._get_consistency() != Consistency.CACHED:
|
|
492 |
- raise StreamError("Could not stage uncached source. " +
|
|
493 |
- "Use `--track` to track and " +
|
|
494 |
- "fetch the latest version of the " +
|
|
495 |
- "source.")
|
|
496 |
- |
|
497 |
- if workspace:
|
|
498 |
- workspaces.delete_workspace(target._get_full_name())
|
|
499 |
- workspaces.save_config()
|
|
500 |
- shutil.rmtree(directory)
|
|
501 |
- try:
|
|
502 |
- os.makedirs(directory, exist_ok=True)
|
|
503 |
- except OSError as e:
|
|
504 |
- raise StreamError("Failed to create workspace directory: {}".format(e)) from e
|
|
498 |
+ if workspace:
|
|
499 |
+ workspaces.delete_workspace(target._get_full_name())
|
|
500 |
+ workspaces.save_config()
|
|
501 |
+ shutil.rmtree(directory)
|
|
502 |
+ try:
|
|
503 |
+ os.makedirs(directory, exist_ok=True)
|
|
504 |
+ except OSError as e:
|
|
505 |
+ raise StreamError("Failed to create workspace directory: {}".format(e)) from e
|
|
505 | 506 |
|
506 |
- workspaces.create_workspace(target._get_full_name(), directory)
|
|
507 |
+ workspaces.create_workspace(target._get_full_name(), directory)
|
|
507 | 508 |
|
508 |
- if not no_checkout:
|
|
509 |
- with target.timed_activity("Staging sources to {}".format(directory)):
|
|
510 |
- target._open_workspace()
|
|
509 |
+ if not no_checkout:
|
|
510 |
+ with target.timed_activity("Staging sources to {}".format(directory)):
|
|
511 |
+ target._open_workspace()
|
|
511 | 512 |
|
513 |
+ ## should we try to make this more attomic?
|
|
512 | 514 |
workspaces.save_config()
|
513 | 515 |
self._message(MessageType.INFO, "Saved workspace configuration")
|
514 | 516 |
|
... | ... | @@ -84,11 +84,10 @@ def create_workspace_elements(cli, tmpdir, datafiles, kinds, track, suffixs=None |
84 | 84 |
else:
|
85 | 85 |
shutil.copytree(os.path.join(datafiles.dirname, datafiles.basename), project_path)
|
86 | 86 |
|
87 |
- |
|
88 | 87 |
results = []
|
89 | 88 |
|
90 | 89 |
if suffixs is None:
|
91 |
- suffixs = [None, ] * len(kinds)
|
|
90 |
+ suffixs = ['', ] * len(kinds)
|
|
92 | 91 |
else:
|
93 | 92 |
if len(suffixs) != len(kinds):
|
94 | 93 |
raise "terable error"
|
... | ... | @@ -105,6 +104,7 @@ def create_workspace_elements(cli, tmpdir, datafiles, kinds, track, suffixs=None |
105 | 104 |
else:
|
106 | 105 |
assert state == 'fetch needed'
|
107 | 106 |
results.append((element_name, project_path, workspace_dir_suffix))
|
107 |
+ return results
|
|
108 | 108 |
|
109 | 109 |
|
110 | 110 |
def open_workspaces(cli, tmpdir, datafiles, kinds, track, suffixs=None, workspace_dir=None,
|
... | ... | @@ -112,7 +112,7 @@ def open_workspaces(cli, tmpdir, datafiles, kinds, track, suffixs=None, workspac |
112 | 112 |
|
113 | 113 |
results = create_workspace_elements(cli, tmpdir, datafiles, kinds, track, suffixs, workspace_dir,
|
114 | 114 |
project_path, element_attrs)
|
115 |
- |
|
115 |
+ _, project_path, workspace_dir_suffix = results[0]
|
|
116 | 116 |
workspace_cmd = os.path.join(project_path, 'workspace_cmd')
|
117 | 117 |
os.makedirs(workspace_cmd, exist_ok=True)
|
118 | 118 |
|
... | ... | @@ -122,9 +122,11 @@ def open_workspaces(cli, tmpdir, datafiles, kinds, track, suffixs=None, workspac |
122 | 122 |
if track:
|
123 | 123 |
args.append('--track')
|
124 | 124 |
if workspace_dir is not None:
|
125 |
+ assert (len(results) != 1, "test logic error")
|
|
125 | 126 |
args.extend(['--directory', workspace_dir_suffix])
|
126 | 127 |
|
127 | 128 |
args.extend([element_name for element_name, project_path, workspace_dir_suffix in results])
|
129 |
+ print ('args', args)
|
|
128 | 130 |
result = cli.run(cwd=workspace_cmd, project=project_path, args=args)
|
129 | 131 |
|
130 | 132 |
result.assert_success()
|
... | ... | @@ -144,16 +146,19 @@ def open_workspaces(cli, tmpdir, datafiles, kinds, track, suffixs=None, workspac |
144 | 146 |
def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', workspace_dir=None,
|
145 | 147 |
project_path=None, element_attrs=None):
|
146 | 148 |
return open_workspaces(cli, tmpdir, datafiles, (kind,), track, suffixs=(suffix,), workspace_dir=workspace_dir,
|
147 |
- project_path=project_path, element_attrs=element_attrs)[0]
|
|
149 |
+ project_path=project_path, element_attrs=element_attrs)[0]
|
|
150 |
+ |
|
148 | 151 |
|
149 | 152 |
@pytest.mark.datafiles(DATA_DIR)
|
150 | 153 |
@pytest.mark.parametrize("kind", repo_kinds)
|
151 | 154 |
def test_open(cli, tmpdir, datafiles, kind):
|
152 | 155 |
open_workspace(cli, tmpdir, datafiles, kind, False)
|
153 | 156 |
|
157 |
+ |
|
154 | 158 |
@pytest.mark.datafiles(DATA_DIR)
|
155 |
-def test_open_multi(cli, tmpdir, datafiles ):
|
|
156 |
- workspaces = open_workspaces(cli, tmpdir, datafiles, repo_kinds, False, repo_kinds)
|
|
159 |
+def test_open_multi(cli, tmpdir, datafiles):
|
|
160 |
+ |
|
161 |
+ workspaces = open_workspaces(cli, tmpdir, datafiles, repo_kinds, False)
|
|
157 | 162 |
|
158 | 163 |
for (element_name, project, workspace), kind in zip(workspaces, repo_kinds):
|
159 | 164 |
workspace_lsdir = os.listdir(workspace)
|
... | ... | @@ -165,11 +170,12 @@ def test_open_multi(cli, tmpdir, datafiles ): |
165 | 170 |
assert not ('.git' in workspace_lsdir)
|
166 | 171 |
assert not ('.bzr' in workspace_lsdir)
|
167 | 172 |
|
173 |
+ |
|
168 | 174 |
@pytest.mark.datafiles(DATA_DIR)
|
169 |
-def test_open_multi(cli, tmpdir, datafiles):
|
|
175 |
+def test_open_multi_with_directory(cli, tmpdir, datafiles):
|
|
170 | 176 |
|
171 |
- results = create_workspace_elements(cli, tmpdir, datafiles, kinds, track, suffixs, workspace_dir,
|
|
172 |
- project_path, element_attrs)
|
|
177 |
+ results = create_workspace_elements(cli, tmpdir, datafiles, repo_kinds, False, repo_kinds)
|
|
178 |
+ _, project_path, workspace_dir_suffix = results[0]
|
|
173 | 179 |
|
174 | 180 |
workspace_cmd = os.path.join(project_path, 'workspace_cmd')
|
175 | 181 |
os.makedirs(workspace_cmd, exist_ok=True)
|
... | ... | @@ -181,10 +187,9 @@ def test_open_multi(cli, tmpdir, datafiles): |
181 | 187 |
args.extend([element_name for element_name, project_path, workspace_dir_suffix in results])
|
182 | 188 |
result = cli.run(cwd=workspace_cmd, project=project_path, args=args)
|
183 | 189 |
|
184 |
- result.assert_main_error()
|
|
185 |
- print(result.output)
|
|
186 |
- print(result.stderr)
|
|
187 |
- assert 1 == 0
|
|
190 |
+ result.assert_main_error(ErrorDomain.ARTIFACT, None)
|
|
191 |
+ assert ("Directory option can only be used if a single element is given" in result.stderr)
|
|
192 |
+ |
|
188 | 193 |
|
189 | 194 |
@pytest.mark.datafiles(DATA_DIR)
|
190 | 195 |
def test_open_bzr_customize(cli, tmpdir, datafiles):
|