summaryrefslogtreecommitdiff
path: root/rtemsspec
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2023-11-21 11:13:16 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2023-11-21 11:15:25 +0100
commit1cc9e86fccae6f7c9df79ee73655f31b342c7a79 (patch)
tree819c0ab3ba75757ff8324d95e0c1c4aa19774ae1 /rtemsspec
parentcd6cbe8792f038fc7a27d37c0804afa0a244eca9 (diff)
reposubset: New
Diffstat (limited to 'rtemsspec')
-rw-r--r--rtemsspec/packagebuildfactory.py3
-rw-r--r--rtemsspec/reposubset.py66
-rw-r--r--rtemsspec/tests/spec-packagebuild/build/bsp.yml17
-rw-r--r--rtemsspec/tests/spec-packagebuild/qdp/package-build.yml2
-rw-r--r--rtemsspec/tests/spec-packagebuild/qdp/source/repo.yml15
-rw-r--r--rtemsspec/tests/spec-packagebuild/qdp/source/sub-repo.yml13
-rw-r--r--rtemsspec/tests/spec-packagebuild/qdp/steps/repository-subset.yml23
-rw-r--r--rtemsspec/tests/test-files/repo/bsp.c0
-rw-r--r--rtemsspec/tests/test_packagebuild.py8
9 files changed, 147 insertions, 0 deletions
diff --git a/rtemsspec/packagebuildfactory.py b/rtemsspec/packagebuildfactory.py
index 600c58de..22ba8ded 100644
--- a/rtemsspec/packagebuildfactory.py
+++ b/rtemsspec/packagebuildfactory.py
@@ -27,6 +27,7 @@
from rtemsspec.archiver import Archiver
from rtemsspec.directorystate import DirectoryState
from rtemsspec.packagebuild import BuildItemFactory, PackageVariant
+from rtemsspec.reposubset import RepositorySubset
from rtemsspec.runactions import RunActions
@@ -34,6 +35,8 @@ def create_build_item_factory() -> BuildItemFactory:
""" Creates the default build item factory. """
factory = BuildItemFactory()
factory.add_constructor("qdp/build-step/archive", Archiver)
+ factory.add_constructor("qdp/build-step/repository-subset",
+ RepositorySubset)
factory.add_constructor("qdp/build-step/run-actions", RunActions)
factory.add_constructor("qdp/directory-state/generic", DirectoryState)
factory.add_constructor("qdp/directory-state/repository", DirectoryState)
diff --git a/rtemsspec/reposubset.py b/rtemsspec/reposubset.py
new file mode 100644
index 00000000..bc3a20d0
--- /dev/null
+++ b/rtemsspec/reposubset.py
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: BSD-2-Clause
+""" Build step to create a subset of a repository. """
+
+# Copyright (C) 2021 EDISOFT (https://www.edisoft.pt/)
+# Copyright (C) 2020, 2023 embedded brains GmbH & Co. KG
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+import logging
+from typing import List
+
+from rtemsspec.build import gather_files
+from rtemsspec.directorystate import DirectoryState
+from rtemsspec.packagebuild import BuildItem
+
+
+class RepositorySubset(BuildItem):
+ """
+ Creates a directory containing only the specified subset of the
+ repository.
+ """
+
+ def gather_files(self) -> List[str]:
+ """ Gathers the files of the repository subset. """
+ variant = self.input("variant")
+
+ logging.info("%s: gather repository subset", self.uid)
+ config = {
+ "bsp": variant["bsp"],
+ "arch": variant["arch"],
+ "extra-files": self["extra-files"],
+ "enabled": self.enabled_set + self["enabled"],
+ "build-uids": self["build-uids"]
+ }
+ return gather_files(config, self.item.cache)
+
+ def run(self):
+ source = self.input("source")
+ assert isinstance(source, DirectoryState)
+
+ destination = self.output("destination")
+ assert isinstance(destination, DirectoryState)
+
+ destination.clear()
+
+ logging.info("%s: copy gathered files", self.uid)
+ destination.copy_files(source.directory, self.gather_files())
diff --git a/rtemsspec/tests/spec-packagebuild/build/bsp.yml b/rtemsspec/tests/spec-packagebuild/build/bsp.yml
new file mode 100644
index 00000000..0a64bf27
--- /dev/null
+++ b/rtemsspec/tests/spec-packagebuild/build/bsp.yml
@@ -0,0 +1,17 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+arch: sparc
+bsp: gr712rc
+build-type: bsp
+cflags: []
+copyrights:
+- Copyright (C) 2023 embedded brains GmbH & Co. KG
+cppflags: []
+enabled-by: true
+family: leon3
+includes: []
+enabled-by: true
+install: []
+links: []
+source:
+- bsp.c
+type: build
diff --git a/rtemsspec/tests/spec-packagebuild/qdp/package-build.yml b/rtemsspec/tests/spec-packagebuild/qdp/package-build.yml
index 1d7a18c8..02c4b721 100644
--- a/rtemsspec/tests/spec-packagebuild/qdp/package-build.yml
+++ b/rtemsspec/tests/spec-packagebuild/qdp/package-build.yml
@@ -10,6 +10,8 @@ links:
- role: build-step
uid: steps/c
- role: build-step
+ uid: steps/repository-subset
+- role: build-step
uid: steps/run-actions
- role: build-step
uid: steps/archive
diff --git a/rtemsspec/tests/spec-packagebuild/qdp/source/repo.yml b/rtemsspec/tests/spec-packagebuild/qdp/source/repo.yml
new file mode 100644
index 00000000..6cd825a8
--- /dev/null
+++ b/rtemsspec/tests/spec-packagebuild/qdp/source/repo.yml
@@ -0,0 +1,15 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2023 embedded brains GmbH & Co. KG
+copyrights-by-license: {}
+directory: ${../variant:/prefix-directory}/repo
+directory-state-type: generic
+enabled-by: true
+files:
+- file: bsp.c
+ hash: null
+hash: null
+links: []
+patterns: []
+qdp-type: directory-state
+type: qdp
diff --git a/rtemsspec/tests/spec-packagebuild/qdp/source/sub-repo.yml b/rtemsspec/tests/spec-packagebuild/qdp/source/sub-repo.yml
new file mode 100644
index 00000000..fa2d99ec
--- /dev/null
+++ b/rtemsspec/tests/spec-packagebuild/qdp/source/sub-repo.yml
@@ -0,0 +1,13 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2023 embedded brains GmbH & Co. KG
+copyrights-by-license: {}
+directory: ${../variant:/deployment-directory}/sub-repo
+directory-state-type: generic
+enabled-by: true
+files: []
+hash: null
+links: []
+patterns: []
+qdp-type: directory-state
+type: qdp
diff --git a/rtemsspec/tests/spec-packagebuild/qdp/steps/repository-subset.yml b/rtemsspec/tests/spec-packagebuild/qdp/steps/repository-subset.yml
new file mode 100644
index 00000000..8d473fc9
--- /dev/null
+++ b/rtemsspec/tests/spec-packagebuild/qdp/steps/repository-subset.yml
@@ -0,0 +1,23 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+build-step-type: repository-subset
+build-uids: []
+copyrights:
+- Copyright (C) 2023 embedded brains GmbH & Co. KG
+description: Description.
+enabled: []
+enabled-by: repository-subset
+extra-files: []
+links:
+- hash: null
+ name: variant
+ role: input
+ uid: ../variant
+- hash: null
+ name: source
+ role: input
+ uid: ../source/repo
+- name: destination
+ role: output
+ uid: ../source/sub-repo
+qdp-type: build-step
+type: qdp
diff --git a/rtemsspec/tests/test-files/repo/bsp.c b/rtemsspec/tests/test-files/repo/bsp.c
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/rtemsspec/tests/test-files/repo/bsp.c
diff --git a/rtemsspec/tests/test_packagebuild.py b/rtemsspec/tests/test_packagebuild.py
index fc4ae327..aad59c63 100644
--- a/rtemsspec/tests/test_packagebuild.py
+++ b/rtemsspec/tests/test_packagebuild.py
@@ -57,6 +57,7 @@ def _create_item_cache(tmp_dir: Path, spec_dir: Path) -> ItemCache:
_copy_dir(test_dir / spec_dir, spec_dst)
_copy_dir(test_dir / "test-files", tmp_dir)
_copy_dir(test_dir.parent.parent / "spec-spec", spec_dst)
+ _copy_dir(test_dir.parent.parent / "spec" / "spec", spec_dst / "spec")
_copy_dir(test_dir.parent.parent / "spec-qdp" / "spec", spec_dst / "spec")
cache_dir = os.path.join(tmp_dir, "cache")
config = {
@@ -213,3 +214,10 @@ def test_packagebuild(caplog, tmpdir):
assert f"/qdp/steps/run-actions: remove directory tree: {tmp_dir}/pkg/build/some" in log
assert f"/qdp/steps/run-actions: run in '{tmp_dir}/pkg/build': 'git' 'foobar'" in log
assert f"/qdp/steps/run-actions: run in '{tmp_dir}/pkg/build': 'git' 'status'" in log
+
+ # Test RepositorySubset
+ variant["enabled"] = ["repository-subset"]
+ director["/qdp/source/repo"].load()
+ assert not os.path.exists(os.path.join(tmpdir, "pkg", "sub-repo", "bsp.c"))
+ director.build_package(None, None)
+ assert os.path.exists(os.path.join(tmpdir, "pkg", "sub-repo", "bsp.c"))