You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ro...@apache.org on 2020/12/29 13:38:20 UTC

[buildstream] 01/11: Add 'workspacedir' configuration.

This is an automated email from the ASF dual-hosted git repository.

root pushed a commit to branch valentindavid/workspacedir_config
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 9dd928dc7ad033b475ce6a2afd66aef71d5ea8ac
Author: Valentin David <va...@codethink.co.uk>
AuthorDate: Wed Apr 18 14:27:35 2018 +0200

    Add 'workspacedir' configuration.
    
    'workspacedir' is either absolute or relative from project directory.
    
    Fixes #229.
---
 buildstream/_context.py          |  6 +++++-
 buildstream/_frontend/cli.py     | 20 ++++++++++++--------
 buildstream/data/userconfig.yaml |  3 +++
 tests/frontend/workspace.py      | 29 +++++++++++++++++++++++++++--
 4 files changed, 47 insertions(+), 11 deletions(-)

diff --git a/buildstream/_context.py b/buildstream/_context.py
index c0d49b2..b578d44 100644
--- a/buildstream/_context.py
+++ b/buildstream/_context.py
@@ -59,6 +59,9 @@ class Context():
         # The local binary artifact cache directory
         self.artifactdir = None
 
+        # Default root location for workspaces
+        self.workspacedir = None
+
         # The locations from which to push and pull prebuilt artifacts
         self.artifact_cache_specs = []
 
@@ -152,9 +155,10 @@ class Context():
         _yaml.node_validate(defaults, [
             'sourcedir', 'builddir', 'artifactdir', 'logdir',
             'scheduler', 'artifacts', 'logging', 'projects',
+            'workspacedir',
         ])
 
-        for directory in ['sourcedir', 'builddir', 'artifactdir', 'logdir']:
+        for directory in ['sourcedir', 'builddir', 'artifactdir', 'logdir', 'workspacedir']:
             # Allow the ~ tilde expansion and any environment variables in
             # path specification in the config files.
             #
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 5ed967d..2b5483e 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -599,17 +599,21 @@ def workspace():
 def workspace_open(app, no_checkout, force, track_, element, directory):
     """Open a workspace for manual source modification"""
 
-    if os.path.exists(directory):
+    with app.initialized():
 
-        if not os.path.isdir(directory):
-            click.echo("Checkout directory is not a directory: {}".format(directory), err=True)
-            sys.exit(-1)
+        if not os.path.isabs(directory):
+            directory = os.path.join(app.context.workspacedir, directory)
 
-        if not (no_checkout or force) and os.listdir(directory):
-            click.echo("Checkout directory is not empty: {}".format(directory), err=True)
-            sys.exit(-1)
+        if os.path.exists(directory):
+
+            if not os.path.isdir(directory):
+                click.echo("Checkout directory is not a directory: {}".format(directory), err=True)
+                sys.exit(-1)
+
+            if not (no_checkout or force) and os.listdir(directory):
+                click.echo("Checkout directory is not empty: {}".format(directory), err=True)
+                sys.exit(-1)
 
-    with app.initialized():
         app.stream.workspace_open(element, directory,
                                   no_checkout=no_checkout,
                                   track_first=track_,
diff --git a/buildstream/data/userconfig.yaml b/buildstream/data/userconfig.yaml
index 6bb54ff..25b2541 100644
--- a/buildstream/data/userconfig.yaml
+++ b/buildstream/data/userconfig.yaml
@@ -22,6 +22,9 @@ artifactdir: ${XDG_CACHE_HOME}/buildstream/artifacts
 # Location to store build logs
 logdir: ${XDG_CACHE_HOME}/buildstream/logs
 
+# Default root location for workspaces
+workspacedir: .
+
 #
 #    Scheduler
 #
diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py
index 90b5061..9f1a6c0 100644
--- a/tests/frontend/workspace.py
+++ b/tests/frontend/workspace.py
@@ -18,12 +18,15 @@ DATA_DIR = os.path.join(
 )
 
 
-def open_workspace(cli, tmpdir, datafiles, kind, track, suffix=''):
+def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', workspacedir=None):
     project = os.path.join(datafiles.dirname, datafiles.basename)
     bin_files_path = os.path.join(project, 'files', 'bin-files')
     element_path = os.path.join(project, 'elements')
     element_name = 'workspace-test-{}{}.bst'.format(kind, suffix)
-    workspace = os.path.join(str(tmpdir), 'workspace{}'.format(suffix))
+    if workspacedir is None:
+        workspace = os.path.join(str(tmpdir), 'workspace{}'.format(suffix))
+    else:
+        workspace = os.path.join('workspace{}'.format(suffix))
 
     # Create our repo object of the given source type with
     # the bin files, and then collect the initial ref.
@@ -67,6 +70,9 @@ def open_workspace(cli, tmpdir, datafiles, kind, track, suffix=''):
 
     # Check that the executable hello file is found in the workspace
     filename = os.path.join(workspace, 'usr', 'bin', 'hello')
+    if workspacedir is not None:
+        filename = os.path.join(workspacedir, filename)
+
     assert os.path.exists(filename)
 
     return (element_name, project, workspace)
@@ -122,6 +128,25 @@ def test_open_force(cli, tmpdir, datafiles, kind):
     ])
     result.assert_success()
 
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("kind", repo_kinds)
+def test_open_workspacedir_absolute(cli, tmpdir, datafiles, kind):
+    workspacedir = os.path.join(tmpdir, 'workspaces')
+    user_config = {'workspacedir': workspacedir}
+    cli.configure(user_config)
+    open_workspace(cli, tmpdir, datafiles, kind, False,
+                   workspacedir=workspacedir)
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("kind", repo_kinds)
+def test_open_workspacedir_relative(cli, tmpdir, datafiles, kind):
+    workspacedir = os.path.join('workspaces')
+    if os.path.isdir(workspacedir):
+        shutil.rmtree(workspacedir)
+    user_config = {'workspacedir': workspacedir}
+    cli.configure(user_config)
+    open_workspace(cli, tmpdir, datafiles, kind, False,
+                   workspacedir=workspacedir)
 
 @pytest.mark.datafiles(DATA_DIR)
 @pytest.mark.parametrize("kind", repo_kinds)