Phillip Smyth pushed to branch relative_workspaces at BuildStream / buildstream
Commits:
-
1a791246
by Phillip Smyth at 2018-07-27T10:22:52Z
5 changed files:
- buildstream/_stream.py
- buildstream/_workspaces.py
- buildstream/element.py
- tests/frontend/workspace.py
- tests/integration/shell.py
Changes:
1 |
-#
|
|
2 | 1 |
# Copyright (C) 2018 Codethink Limited
|
3 | 2 |
#
|
4 | 3 |
# This program is free software; you can redistribute it and/or
|
... | ... | @@ -460,14 +459,14 @@ class Stream(): |
460 | 459 |
"source.")
|
461 | 460 |
|
462 | 461 |
try:
|
463 |
- os.makedirs(directory, exist_ok=True)
|
|
462 |
+ os.makedirs(workdir, exist_ok=True)
|
|
464 | 463 |
except OSError as e:
|
465 | 464 |
raise StreamError("Failed to create workspace directory: {}".format(e)) from e
|
466 | 465 |
|
467 | 466 |
workspaces.create_workspace(target._get_full_name(), workdir)
|
468 | 467 |
|
469 | 468 |
if not no_checkout:
|
470 |
- with target.timed_activity("Staging sources to {}".format(directory)):
|
|
469 |
+ with target.timed_activity("Staging sources to {}".format(workdir)):
|
|
471 | 470 |
target._open_workspace()
|
472 | 471 |
|
473 | 472 |
workspaces.save_config()
|
... | ... | @@ -490,7 +489,7 @@ class Stream(): |
490 | 489 |
with self._context.timed_activity("Removing workspace directory {}"
|
491 | 490 |
.format(workspace.path)):
|
492 | 491 |
try:
|
493 |
- shutil.rmtree(workspace.path)
|
|
492 |
+ shutil.rmtree(workspace.get_absolute_path())
|
|
494 | 493 |
except OSError as e:
|
495 | 494 |
raise StreamError("Could not remove '{}': {}"
|
496 | 495 |
.format(workspace.path, e)) from e
|
... | ... | @@ -536,23 +535,23 @@ class Stream(): |
536 | 535 |
|
537 | 536 |
for element in elements:
|
538 | 537 |
workspace = workspaces.get_workspace(element._get_full_name())
|
539 |
- |
|
538 |
+ workspace_path = workspace.get_absolute_path()
|
|
540 | 539 |
if soft:
|
541 | 540 |
workspace.prepared = False
|
542 | 541 |
self._message(MessageType.INFO, "Reset workspace state for {} at: {}"
|
543 |
- .format(element.name, workspace.path))
|
|
542 |
+ .format(element.name, workspace_path))
|
|
544 | 543 |
continue
|
545 | 544 |
|
546 | 545 |
with element.timed_activity("Removing workspace directory {}"
|
547 |
- .format(workspace.path)):
|
|
546 |
+ .format(workspace_path)):
|
|
548 | 547 |
try:
|
549 |
- shutil.rmtree(workspace.path)
|
|
548 |
+ shutil.rmtree(workspace_path)
|
|
550 | 549 |
except OSError as e:
|
551 | 550 |
raise StreamError("Could not remove '{}': {}"
|
552 |
- .format(workspace.path, e)) from e
|
|
551 |
+ .format(workspace_path, e)) from e
|
|
553 | 552 |
|
554 | 553 |
workspaces.delete_workspace(element._get_full_name())
|
555 |
- workspaces.create_workspace(element._get_full_name(), workspace.path)
|
|
554 |
+ workspaces.create_workspace(element._get_full_name(), workspace_path)
|
|
556 | 555 |
|
557 | 556 |
with element.timed_activity("Staging sources to {}".format(workspace.path)):
|
558 | 557 |
element._open_workspace()
|
... | ... | @@ -594,7 +593,7 @@ class Stream(): |
594 | 593 |
for element_name, workspace_ in self._context.get_workspaces().list():
|
595 | 594 |
workspace_detail = {
|
596 | 595 |
'element': element_name,
|
597 |
- 'directory': workspace_.path,
|
|
596 |
+ 'directory': workspace_.get_absolute_path(),
|
|
598 | 597 |
}
|
599 | 598 |
workspaces.append(workspace_detail)
|
600 | 599 |
|
... | ... | @@ -189,7 +189,7 @@ class Workspace(): |
189 | 189 |
filelist = utils.list_relative_paths(fullpath)
|
190 | 190 |
filelist = [(relpath, os.path.join(fullpath, relpath)) for relpath in filelist]
|
191 | 191 |
else:
|
192 |
- filelist = [(self.path, fullpath)]
|
|
192 |
+ filelist = [(os.path.abspath(self.path), fullpath)]
|
|
193 | 193 |
|
194 | 194 |
self._key = [(relpath, unique_key(fullpath)) for relpath, fullpath in filelist]
|
195 | 195 |
|
... | ... | @@ -236,6 +236,9 @@ class Workspaces(): |
236 | 236 |
# path (str) - The path in which the workspace should be kept
|
237 | 237 |
#
|
238 | 238 |
def create_workspace(self, element_name, path):
|
239 |
+ if path.startswith(self._toplevel_project.directory):
|
|
240 |
+ path = os.path.relpath(path, self._toplevel_project.directory)
|
|
241 |
+ |
|
239 | 242 |
self._workspaces[element_name] = Workspace(self._toplevel_project, path=path)
|
240 | 243 |
|
241 | 244 |
return self._workspaces[element_name]
|
... | ... | @@ -1455,10 +1455,14 @@ class Element(Plugin): |
1455 | 1455 |
#
|
1456 | 1456 |
workspace = self._get_workspace()
|
1457 | 1457 |
if workspace and self.__staged_sources_directory:
|
1458 |
+ print("\n\n\nFLIBBLE!\n\n\n")
|
|
1458 | 1459 |
sandbox_root = sandbox.get_directory()
|
1460 |
+ print("\n\n\nSandbox_root: {}\n\n\n".format(sandbox_root))
|
|
1459 | 1461 |
sandbox_path = os.path.join(sandbox_root,
|
1460 | 1462 |
self.__staged_sources_directory.lstrip(os.sep))
|
1461 | 1463 |
try:
|
1464 |
+ print("\n\n\nSandbox_path: {}\n\n\n".format(sandbox_path))
|
|
1465 |
+ print("\n\n\nworkspace_path: {}\n\n\n".format(workspace.path))
|
|
1462 | 1466 |
utils.copy_files(workspace.path, sandbox_path)
|
1463 | 1467 |
except UtilError as e:
|
1464 | 1468 |
self.warn("Failed to preserve workspace state for failed build sysroot: {}"
|
... | ... | @@ -1752,7 +1756,7 @@ class Element(Plugin): |
1752 | 1756 |
source._init_workspace(temp)
|
1753 | 1757 |
|
1754 | 1758 |
# Now hardlink the files into the workspace target.
|
1755 |
- utils.link_files(temp, workspace.path)
|
|
1759 |
+ utils.link_files(temp, workspace.get_absolute_path())
|
|
1756 | 1760 |
|
1757 | 1761 |
# _get_workspace():
|
1758 | 1762 |
#
|
... | ... | @@ -18,7 +18,10 @@ DATA_DIR = os.path.join( |
18 | 18 |
)
|
19 | 19 |
|
20 | 20 |
|
21 |
-def open_workspace(cli, tmpdir, datafiles, kind, track, suffix=''):
|
|
21 |
+def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', rerun=False, new_dir=None):
|
|
22 |
+ if os.path.isdir(os.path.join(str(tmpdir), 'repo')):
|
|
23 |
+ shutil.rmtree(os.path.join(str(tmpdir), 'repo'))
|
|
24 |
+ |
|
22 | 25 |
project = os.path.join(datafiles.dirname, datafiles.basename)
|
23 | 26 |
bin_files_path = os.path.join(project, 'files', 'bin-files')
|
24 | 27 |
element_path = os.path.join(project, 'elements')
|
... | ... | @@ -45,11 +48,12 @@ def open_workspace(cli, tmpdir, datafiles, kind, track, suffix=''): |
45 | 48 |
element_name))
|
46 | 49 |
|
47 | 50 |
# Assert that there is no reference, a track & fetch is needed
|
48 |
- state = cli.get_element_state(project, element_name)
|
|
49 |
- if track:
|
|
50 |
- assert state == 'no reference'
|
|
51 |
- else:
|
|
52 |
- assert state == 'fetch needed'
|
|
51 |
+ if not rerun:
|
|
52 |
+ state = cli.get_element_state(project, element_name)
|
|
53 |
+ if track:
|
|
54 |
+ assert state == 'no reference'
|
|
55 |
+ else:
|
|
56 |
+ assert state == 'fetch needed'
|
|
53 | 57 |
|
54 | 58 |
# Now open the workspace, this should have the effect of automatically
|
55 | 59 |
# tracking & fetching the source from the repo.
|
... | ... | @@ -59,15 +63,19 @@ def open_workspace(cli, tmpdir, datafiles, kind, track, suffix=''): |
59 | 63 |
args.extend([element_name, workspace])
|
60 | 64 |
|
61 | 65 |
result = cli.run(project=project, args=args)
|
62 |
- result.assert_success()
|
|
63 | 66 |
|
64 |
- # Assert that we are now buildable because the source is
|
|
65 |
- # now cached.
|
|
66 |
- assert cli.get_element_state(project, element_name) == 'buildable'
|
|
67 |
+ if not rerun:
|
|
68 |
+ result.assert_success()
|
|
67 | 69 |
|
68 |
- # Check that the executable hello file is found in the workspace
|
|
69 |
- filename = os.path.join(workspace, 'usr', 'bin', 'hello')
|
|
70 |
- assert os.path.exists(filename)
|
|
70 |
+ # Assert that we are now buildable because the source is
|
|
71 |
+ # now cached.
|
|
72 |
+ assert cli.get_element_state(project, element_name) == 'buildable'
|
|
73 |
+ |
|
74 |
+ # Check that the executable hello file is found in the workspace
|
|
75 |
+ filename = os.path.join(workspace, 'usr', 'bin', 'hello')
|
|
76 |
+ assert os.path.exists(filename)
|
|
77 |
+ else:
|
|
78 |
+ result.assert_main_error(ErrorDomain.STREAM, None)
|
|
71 | 79 |
|
72 | 80 |
return (element_name, project, workspace)
|
73 | 81 |
|
... | ... | @@ -78,6 +86,43 @@ def test_open(cli, tmpdir, datafiles, kind): |
78 | 86 |
open_workspace(cli, tmpdir, datafiles, kind, False)
|
79 | 87 |
|
80 | 88 |
|
89 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
90 |
+@pytest.mark.parametrize("kind", repo_kinds)
|
|
91 |
+def test_open_after_move_interally(cli, tmpdir, datafiles, kind):
|
|
92 |
+ open_workspace(cli, tmpdir, datafiles, kind, False)
|
|
93 |
+ workspace = os.path.join(str(tmpdir), 'workspace')
|
|
94 |
+ shutil.move(workspace, os.path.join(str(tmpdir), 'workspace2'))
|
|
95 |
+ open_workspace(cli, tmpdir, datafiles, kind, False, '', True)
|
|
96 |
+ filename = os.path.join(workspace + '2', 'usr', 'bin', 'hello')
|
|
97 |
+ assert os.path.exists(filename)
|
|
98 |
+ |
|
99 |
+ |
|
100 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
101 |
+@pytest.mark.parametrize("kind", repo_kinds)
|
|
102 |
+def test_open_after_move_externally(cli, tmpdir, datafiles, kind):
|
|
103 |
+ open_workspace(cli, tmpdir, datafiles, kind, False)
|
|
104 |
+ workspace = os.path.join(str(tmpdir), 'workspace')
|
|
105 |
+ tmp_dir = os.path.join(str(tmpdir), '2')
|
|
106 |
+ shutil.move(workspace, os.path.join(tmp_dir, 'workspace'))
|
|
107 |
+ open_workspace(cli, tmpdir, datafiles, kind, False, '', True, tmp_dir)
|
|
108 |
+ filename = os.path.join(os.path.join(tmp_dir, 'workspace'), 'usr', 'bin', 'hello')
|
|
109 |
+ assert os.path.exists(filename)
|
|
110 |
+ shutil.rmtree(tmp_dir)
|
|
111 |
+ |
|
112 |
+ |
|
113 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
114 |
+@pytest.mark.parametrize("kind", repo_kinds)
|
|
115 |
+def test_open_after_move_project(cli, tmpdir, datafiles, kind):
|
|
116 |
+ open_workspace(cli, tmpdir, datafiles, kind, False)
|
|
117 |
+ workspace = os.path.join(str(tmpdir), 'workspace')
|
|
118 |
+ tmp_dir = os.path.join(str(tmpdir), '..', 'new_dir')
|
|
119 |
+ shutil.move(workspace, os.path.join(tmp_dir, 'workspace'))
|
|
120 |
+ open_workspace(cli, tmpdir, datafiles, kind, False, '', True, tmp_dir)
|
|
121 |
+ filename = os.path.join(os.path.join(tmp_dir, 'workspace'), 'usr', 'bin', 'hello')
|
|
122 |
+ assert os.path.exists(filename)
|
|
123 |
+ shutil.rmtree(tmp_dir)
|
|
124 |
+ |
|
125 |
+ |
|
81 | 126 |
@pytest.mark.datafiles(DATA_DIR)
|
82 | 127 |
def test_open_bzr_customize(cli, tmpdir, datafiles):
|
83 | 128 |
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "bzr", False)
|
... | ... | @@ -330,6 +330,9 @@ def test_sysroot_workspace_visible(cli, tmpdir, datafiles): |
330 | 330 |
# Obtain a copy of the hello.c content from the workspace
|
331 | 331 |
#
|
332 | 332 |
workspace_hello_path = os.path.join(cli.directory, 'workspace', 'hello.c')
|
333 |
+ print("\n\n\nworkspace_hello_path: {}".format(workspace_hello_path))
|
|
334 |
+ print("build_dir: {}\n\n\n".format(build_dir))
|
|
335 |
+
|
|
333 | 336 |
assert os.path.exists(workspace_hello_path)
|
334 | 337 |
with open(workspace_hello_path, 'r') as f:
|
335 | 338 |
workspace_hello = f.read()
|