You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 08:18:49 UTC
[buildstream] branch 214-filter-workspacing-rework created (now
572e34d)
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a change to branch 214-filter-workspacing-rework
in repository https://gitbox.apache.org/repos/asf/buildstream.git.
at 572e34d tests: Add workspace tests for filters
This branch includes the following new commits:
new 9b42cf1 Use a _get_real_element() method in workspace commands
new 11571c4 filter.py: Redirect _get_real_element() calls to its build depend
new 572e34d tests: Add workspace tests for filters
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[buildstream] 02/03: filter.py: Redirect _get_real_element() calls
to its build depend
Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch 214-filter-workspacing-rework
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 11571c4cadc4249a1e61355c446af5215f0a73c1
Author: Jonathan Maw <jo...@codethink.co.uk>
AuthorDate: Wed Mar 21 15:34:56 2018 +0000
filter.py: Redirect _get_real_element() calls to its build depend
We do this because trying to open/close/reset a workspace on a filter
element doesn't make sense, but is probably meant for the element that
the filter element filters.
---
buildstream/plugins/elements/filter.py | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/buildstream/plugins/elements/filter.py b/buildstream/plugins/elements/filter.py
index 2487a97..68f54db 100644
--- a/buildstream/plugins/elements/filter.py
+++ b/buildstream/plugins/elements/filter.py
@@ -32,6 +32,11 @@ they must be runtime dependencies only. This can be useful to propagate
runtime dependencies forward from this filter element onto its reverse
dependencies.
+When workspaces are opened, closed or reset on this element, instead
+of erroring due to a lack of sources, this element will transparently
+pass on the workspace opening/closing/resetting to its sole
+build-dependency.
+
The default configuration and possible options are as such:
.. literalinclude:: ../../../buildstream/plugins/elements/filter.yaml
:language: yaml
@@ -102,6 +107,13 @@ class FilterElement(Element):
exclude=self.exclude, orphans=self.include_orphans)
return ""
+ def _get_real_element(self):
+ # Filter elements act as proxies for their sole build-dependency
+ build_deps = list(self.dependencies(Scope.BUILD, recurse=False))
+ assert len(build_deps) == 1
+ output_elm = build_deps[0]._get_real_element()
+ return output_elm
+
def setup():
return FilterElement
[buildstream] 03/03: tests: Add workspace tests for filters
Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch 214-filter-workspacing-rework
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 572e34dbf2c6e525221c83fbfb6b95ef059d4c03
Author: Jonathan Maw <jo...@codethink.co.uk>
AuthorDate: Wed Mar 14 14:42:04 2018 +0000
tests: Add workspace tests for filters
---
tests/plugins/filter.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/tests/plugins/filter.py b/tests/plugins/filter.py
index a8e7257..f38bc43 100644
--- a/tests/plugins/filter.py
+++ b/tests/plugins/filter.py
@@ -1,5 +1,6 @@
import os
import pytest
+import shutil
from tests.testutils.runcli import cli
from buildstream._exceptions import ErrorDomain
@@ -85,3 +86,72 @@ def test_filter_forbid_also_rdep(datafiles, cli):
project = os.path.join(datafiles.dirname, datafiles.basename)
result = cli.run(project=project, args=['build', 'forbidden-also-rdep.bst'])
result.assert_main_error(ErrorDomain.PIPELINE, 'filter-bdepend-also-rdepend')
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
+def test_filter_workspace_open(datafiles, cli, tmpdir):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ workspace_dir = os.path.join(tmpdir.dirname, tmpdir.basename, "workspace")
+ result = cli.run(project=project, args=['workspace', 'open', 'deps-permitted.bst', workspace_dir])
+ result.assert_success()
+ assert os.path.exists(os.path.join(workspace_dir, "foo"))
+ assert os.path.exists(os.path.join(workspace_dir, "bar"))
+ assert os.path.exists(os.path.join(workspace_dir, "baz"))
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
+def test_filter_workspace_build(datafiles, cli, tmpdir):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
+ workspace_dir = os.path.join(tempdir, "workspace")
+ result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
+ result.assert_success()
+ src = os.path.join(workspace_dir, "foo")
+ dst = os.path.join(workspace_dir, "quux")
+ shutil.copyfile(src, dst)
+ result = cli.run(project=project, args=['build', 'output-orphans.bst'])
+ result.assert_success()
+ checkout_dir = os.path.join(tempdir, "checkout")
+ result = cli.run(project=project, args=['checkout', 'output-orphans.bst', checkout_dir])
+ result.assert_success()
+ assert os.path.exists(os.path.join(checkout_dir, "quux"))
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
+def test_filter_workspace_close(datafiles, cli, tmpdir):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
+ workspace_dir = os.path.join(tempdir, "workspace")
+ result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
+ result.assert_success()
+ src = os.path.join(workspace_dir, "foo")
+ dst = os.path.join(workspace_dir, "quux")
+ shutil.copyfile(src, dst)
+ result = cli.run(project=project, args=['workspace', 'close', 'deps-permitted.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['build', 'output-orphans.bst'])
+ result.assert_success()
+ checkout_dir = os.path.join(tempdir, "checkout")
+ result = cli.run(project=project, args=['checkout', 'output-orphans.bst', checkout_dir])
+ result.assert_success()
+ assert not os.path.exists(os.path.join(checkout_dir, "quux"))
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
+def test_filter_workspace_reset(datafiles, cli, tmpdir):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
+ workspace_dir = os.path.join(tempdir, "workspace")
+ result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
+ result.assert_success()
+ src = os.path.join(workspace_dir, "foo")
+ dst = os.path.join(workspace_dir, "quux")
+ shutil.copyfile(src, dst)
+ result = cli.run(project=project, args=['workspace', 'reset', 'deps-permitted.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['build', 'output-orphans.bst'])
+ result.assert_success()
+ checkout_dir = os.path.join(tempdir, "checkout")
+ result = cli.run(project=project, args=['checkout', 'output-orphans.bst', checkout_dir])
+ result.assert_success()
+ assert not os.path.exists(os.path.join(checkout_dir, "quux"))
[buildstream] 01/03: Use a _get_real_element() method in workspace
commands
Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch 214-filter-workspacing-rework
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 9b42cf1ae51cd8fb75273438288f7ccabd4c514b
Author: Jonathan Maw <jo...@codethink.co.uk>
AuthorDate: Wed Mar 21 15:33:21 2018 +0000
Use a _get_real_element() method in workspace commands
The _get_real_element() method is used in case some elements decide that
workspace commands should be redirected to another element.
---
buildstream/_frontend/cli.py | 7 +++++--
buildstream/_pipeline.py | 16 ++++++++++++++++
buildstream/element.py | 3 +++
3 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index c0bf741..6003b30 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -618,7 +618,7 @@ def workspace():
def workspace_open(app, no_checkout, force, track_, element, directory):
"""Open a workspace for manual source modification"""
- app.initialize((element,), rewritable=track_, track_elements=[element] if track_ else None)
+ app.initialize((element,), rewritable=track_)
try:
app.pipeline.open_workspace(app.scheduler, directory, no_checkout, track_, force)
click.echo("", err=True)
@@ -641,7 +641,10 @@ def workspace_close(app, remove_dir, element):
app.initialize((element,))
- if app.pipeline.project._get_workspace(app.pipeline.targets[0].name) is None:
+ target = app.pipeline.targets[0]
+ target = target._get_real_element()
+
+ if app.pipeline.project._get_workspace(target.name) is None:
click.echo("ERROR: Workspace '{}' does not exist".format(element), err=True)
sys.exit(-1)
diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py
index d4f65b4..18bef5c 100644
--- a/buildstream/_pipeline.py
+++ b/buildstream/_pipeline.py
@@ -616,6 +616,15 @@ class Pipeline():
def open_workspace(self, scheduler, directory, no_checkout, track_first, force):
# When working on workspaces we only have one target
target = self.targets[0]
+
+ # Some elements act as proxies for other elements
+ target = target._get_real_element()
+
+ # Ordinarily, this would be done by pipeline initialization, but we need the
+ # elements initialized before we know which ones to track.
+ if track_first:
+ self.resolve_cache_keys([target.name])
+
workdir = os.path.abspath(directory)
if not list(target.sources()):
@@ -698,6 +707,9 @@ class Pipeline():
# When working on workspaces we only have one target
target = self.targets[0]
+ # Some elements act as proxies for other elements
+ target = target._get_real_element()
+
# Remove workspace directory if prompted
if remove_dir:
path = self.project._get_workspace(target.name)
@@ -738,6 +750,10 @@ class Pipeline():
def reset_workspace(self, scheduler, track, no_checkout):
# When working on workspaces we only have one target
target = self.targets[0]
+
+ # Some elements act as proxies for other elements
+ target = target._get_real_element()
+
workspace_dir = self.project._get_workspace(target.name)
if workspace_dir is None:
diff --git a/buildstream/element.py b/buildstream/element.py
index b62945f..f1f34b3 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1958,6 +1958,9 @@ class Element(Plugin):
def _subst_string(self, value):
return self.__variables.subst(value)
+ def _get_real_element(self):
+ return self
+
def _overlap_error_detail(f, forbidden_overlap_elements, elements):
if forbidden_overlap_elements: