From 1cc9e86fccae6f7c9df79ee73655f31b342c7a79 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 21 Nov 2023 11:13:16 +0100 Subject: reposubset: New --- rtemsspec/packagebuildfactory.py | 3 + rtemsspec/reposubset.py | 66 ++++++++++++++++++++++ rtemsspec/tests/spec-packagebuild/build/bsp.yml | 17 ++++++ .../tests/spec-packagebuild/qdp/package-build.yml | 2 + .../tests/spec-packagebuild/qdp/source/repo.yml | 15 +++++ .../spec-packagebuild/qdp/source/sub-repo.yml | 13 +++++ .../qdp/steps/repository-subset.yml | 23 ++++++++ rtemsspec/tests/test-files/repo/bsp.c | 0 rtemsspec/tests/test_packagebuild.py | 8 +++ spec-qdp/spec/qdp-repository-subset.yml | 54 ++++++++++++++++++ 10 files changed, 201 insertions(+) create mode 100644 rtemsspec/reposubset.py create mode 100644 rtemsspec/tests/spec-packagebuild/build/bsp.yml create mode 100644 rtemsspec/tests/spec-packagebuild/qdp/source/repo.yml create mode 100644 rtemsspec/tests/spec-packagebuild/qdp/source/sub-repo.yml create mode 100644 rtemsspec/tests/spec-packagebuild/qdp/steps/repository-subset.yml create mode 100644 rtemsspec/tests/test-files/repo/bsp.c create mode 100644 spec-qdp/spec/qdp-repository-subset.yml 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 @@ -9,6 +9,8 @@ links: uid: steps/b - role: build-step uid: steps/c +- role: build-step + uid: steps/repository-subset - role: build-step uid: steps/run-actions - role: build-step 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 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")) diff --git a/spec-qdp/spec/qdp-repository-subset.yml b/spec-qdp/spec/qdp-repository-subset.yml new file mode 100644 index 00000000..aeccc871 --- /dev/null +++ b/spec-qdp/spec/qdp-repository-subset.yml @@ -0,0 +1,54 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +copyrights: +- Copyright (C) 2020, 2023 embedded brains GmbH & Co. KG +enabled-by: true +links: +- role: spec-member + uid: root +- role: spec-refinement + spec-key: build-step-type + spec-value: repository-subset + uid: qdp-build-step +spec-description: | + Items of this type shall have the following links: + + * There shall be exactly one link to a ${qdp-directory-state:/spec-name} item + with the ${qdp-input-role:/spec-name} and the name ``variant``. This link + defines the package variant. + + * There shall be exactly one link to a ${qdp-directory-state:/spec-name} item + with the ${qdp-input-role:/spec-name} and the name ``source``. This link + defines the source repository. + + * There shall be exactly one link to a ${qdp-directory-state:/spec-name} item + with the ${qdp-output-role:/spec-name} and the name ``destination``. The + link target directory state item defines the location of the subset of the + repository. +spec-example: null +spec-info: + dict: + attributes: + build-uids: + description: | + It shall be the list of UIDs to build items. The source files of + enabled build items are included in the source subset. + spec-type: list-str + enabled: + description: | + It shall be the list of enable values used to evaluate the + ${enabled-by:/spec-name} of the visited build items. + spec-type: list-str + extra-files: + description: | + It shall be the list of extra files copied from the source directory. + spec-type: list-str + description: | + This set of attributes specifies a subset of repository files. It may be + used to create a subset of the RTEMS sources which contains only the + pre-qualified feature set. These sources can be used to verify the build + of the pre-qualified libraries. It can be also used to build the SDD + with Doxygen restricted to the pre-qualified feature set. + mandatory-attributes: all +spec-name: Repository Subset Item Type +spec-type: qdp-repository-subset +type: spec -- cgit v1.2.3