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 07:49:12 UTC

[buildstream] 02/08: tests: Add a basic plugin to test variables

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

tvb pushed a commit to branch coldtom/external-plugins
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit dcb65313605dee2efe7e83a9dcb059c9a88a983b
Author: Thomas Coldrick <th...@codethink.co.uk>
AuthorDate: Thu Sep 12 15:40:48 2019 +0100

    tests: Add a basic plugin to test variables
    
    As we're moving all plugins out of this repo, but we still should
    probably test that variables can be loaded from defaults and overrided
    correctly, I've added a very basic test plugin to handle this. It's
    essentially just a BuildElement, like autotools etc, but with basic
    variables to check if they're loaded.
---
 setup.cfg                                          |  8 ++++++-
 tests/format/variables.py                          |  2 ++
 tests/format/variables/defaults/plugins/test.py    | 18 ++++++++++++++
 tests/format/variables/defaults/plugins/test.yaml  | 28 ++++++++++++++++++++++
 tests/format/variables/defaults/project.conf       |  6 +++++
 tests/format/variables/defaults/test.bst           |  2 ++
 tests/format/variables/overrides/plugins/test.py   | 18 ++++++++++++++
 tests/format/variables/overrides/plugins/test.yaml | 28 ++++++++++++++++++++++
 tests/format/variables/overrides/project.conf      |  5 ++++
 tests/format/variables/overrides/test.bst          |  4 ++++
 10 files changed, 118 insertions(+), 1 deletion(-)

diff --git a/setup.cfg b/setup.cfg
index 2264a31..500a415 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -12,7 +12,13 @@ test=pytest
 
 [tool:pytest]
 addopts = --verbose --basetemp ./tmp --durations=20
-norecursedirs = tests/integration/project integration-cache tmp __pycache__ .eggs
+norecursedirs =
+    tests/integration/project
+    tests/format/variables
+    integration-cache
+    tmp
+    __pycache__
+    .eggs
 python_files = tests/*/*.py
 env =
     D:BST_TEST_SUITE=True
diff --git a/tests/format/variables.py b/tests/format/variables.py
index 5c4c94b..177e518 100644
--- a/tests/format/variables.py
+++ b/tests/format/variables.py
@@ -31,6 +31,7 @@ def print_warning(msg):
 ###############################################################
 @pytest.mark.parametrize("target,varname,expected", [
     ('autotools.bst', 'make-install', "make -j1 DESTDIR=\"/buildstream-install\" install"),
+    ('test.bst', 'configure', "foo")
 ])
 @pytest.mark.datafiles(os.path.join(DATA_DIR, 'defaults'))
 def test_defaults(cli, datafiles, target, varname, expected):
@@ -48,6 +49,7 @@ def test_defaults(cli, datafiles, target, varname, expected):
 ################################################################
 @pytest.mark.parametrize("target,varname,expected", [
     ('autotools.bst', 'make-install', "make -j1 DESTDIR=\"/custom/install/root\" install"),
+    ('test.bst', 'configure', "quuz")
 ])
 @pytest.mark.datafiles(os.path.join(DATA_DIR, 'overrides'))
 def test_overrides(cli, datafiles, target, varname, expected):
diff --git a/tests/format/variables/defaults/plugins/test.py b/tests/format/variables/defaults/plugins/test.py
new file mode 100644
index 0000000..0d793dd
--- /dev/null
+++ b/tests/format/variables/defaults/plugins/test.py
@@ -0,0 +1,18 @@
+from buildstream import BuildElement, SandboxFlags
+
+
+# Element implementation for the 'test' kind.
+class TestElement(BuildElement):
+    # Supports virtual directories (required for remote execution)
+    BST_VIRTUAL_DIRECTORY = True
+
+    # Enable command batching across prepare() and assemble()
+    def configure_sandbox(self, sandbox):
+        super().configure_sandbox(sandbox)
+        self.batch_prepare_assemble(SandboxFlags.ROOT_READ_ONLY,
+                                    collect=self.get_variable('install-root'))
+
+
+# Plugin entry point
+def setup():
+    return TestElement
diff --git a/tests/format/variables/defaults/plugins/test.yaml b/tests/format/variables/defaults/plugins/test.yaml
new file mode 100644
index 0000000..432e23e
--- /dev/null
+++ b/tests/format/variables/defaults/plugins/test.yaml
@@ -0,0 +1,28 @@
+# Autotools default configurations
+
+variables:
+
+  configure: foo
+  make: bar
+  make-install: baz
+
+config:
+
+  # Commands for configuring the software
+  #
+  configure-commands:
+  - |
+    %{configure}
+
+  # Commands for building the software
+  #
+  build-commands:
+  - |
+    %{make}
+
+  # Commands for installing the software into a
+  # destination folder
+  #
+  install-commands:
+  - |
+    %{make-install}
diff --git a/tests/format/variables/defaults/project.conf b/tests/format/variables/defaults/project.conf
index 2027cc2..4c1894d 100644
--- a/tests/format/variables/defaults/project.conf
+++ b/tests/format/variables/defaults/project.conf
@@ -1,3 +1,9 @@
 # Basic project configuration that doesnt override anything
 #
 name: pony
+
+plugins:
+- origin: local
+  path: plugins
+  elements:
+    test: 0
diff --git a/tests/format/variables/defaults/test.bst b/tests/format/variables/defaults/test.bst
new file mode 100644
index 0000000..943eac3
--- /dev/null
+++ b/tests/format/variables/defaults/test.bst
@@ -0,0 +1,2 @@
+kind: test
+description: Some kinda test element
diff --git a/tests/format/variables/overrides/plugins/test.py b/tests/format/variables/overrides/plugins/test.py
new file mode 100644
index 0000000..0d793dd
--- /dev/null
+++ b/tests/format/variables/overrides/plugins/test.py
@@ -0,0 +1,18 @@
+from buildstream import BuildElement, SandboxFlags
+
+
+# Element implementation for the 'test' kind.
+class TestElement(BuildElement):
+    # Supports virtual directories (required for remote execution)
+    BST_VIRTUAL_DIRECTORY = True
+
+    # Enable command batching across prepare() and assemble()
+    def configure_sandbox(self, sandbox):
+        super().configure_sandbox(sandbox)
+        self.batch_prepare_assemble(SandboxFlags.ROOT_READ_ONLY,
+                                    collect=self.get_variable('install-root'))
+
+
+# Plugin entry point
+def setup():
+    return TestElement
diff --git a/tests/format/variables/overrides/plugins/test.yaml b/tests/format/variables/overrides/plugins/test.yaml
new file mode 100644
index 0000000..432e23e
--- /dev/null
+++ b/tests/format/variables/overrides/plugins/test.yaml
@@ -0,0 +1,28 @@
+# Autotools default configurations
+
+variables:
+
+  configure: foo
+  make: bar
+  make-install: baz
+
+config:
+
+  # Commands for configuring the software
+  #
+  configure-commands:
+  - |
+    %{configure}
+
+  # Commands for building the software
+  #
+  build-commands:
+  - |
+    %{make}
+
+  # Commands for installing the software into a
+  # destination folder
+  #
+  install-commands:
+  - |
+    %{make-install}
diff --git a/tests/format/variables/overrides/project.conf b/tests/format/variables/overrides/project.conf
index 2027cc2..2fe3a8f 100644
--- a/tests/format/variables/overrides/project.conf
+++ b/tests/format/variables/overrides/project.conf
@@ -1,3 +1,8 @@
 # Basic project configuration that doesnt override anything
 #
 name: pony
+plugins:
+- origin: local
+  path: plugins
+  elements:
+    test: 0
diff --git a/tests/format/variables/overrides/test.bst b/tests/format/variables/overrides/test.bst
new file mode 100644
index 0000000..7094c6c
--- /dev/null
+++ b/tests/format/variables/overrides/test.bst
@@ -0,0 +1,4 @@
+kind: test
+description: Some kinda test element
+variables:
+  configure: quuz