This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch tristan/sboms in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit d81b78fd5d3e617cdcd88c20e9ed2f58419040fe Author: Tristan van Berkom <[email protected]> AuthorDate: Tue Mar 4 15:27:46 2025 +0900 source.py: Add collect_source_info() abstract method. This comes with some data classes to describe source provenance and versioning information. --- src/buildstream/__init__.py | 2 +- src/buildstream/source.py | 101 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/src/buildstream/__init__.py b/src/buildstream/__init__.py index b96a2b405..97db87820 100644 --- a/src/buildstream/__init__.py +++ b/src/buildstream/__init__.py @@ -31,7 +31,7 @@ if "_BST_COMPLETION" not in os.environ: from .types import CoreWarnings, OverlapAction, FastEnum, SourceRef from .node import MappingNode, Node, ProvenanceInformation, ScalarNode, SequenceNode from .plugin import Plugin - from .source import Source, SourceError, SourceFetcher + from .source import Source, SourceError, SourceFetcher, SourceInfo, SourceInfoMedium, SourceVersionType from .sourcemirror import SourceMirror, SourceMirrorError from .downloadablefilesource import DownloadableFileSource from .element import Element, ElementError, DependencyConfiguration diff --git a/src/buildstream/source.py b/src/buildstream/source.py index d92479d5f..800cd292c 100644 --- a/src/buildstream/source.py +++ b/src/buildstream/source.py @@ -224,7 +224,7 @@ from . import _yaml, utils from .node import MappingNode from .plugin import Plugin from .sourcemirror import SourceMirror -from .types import SourceRef, CoreWarnings +from .types import SourceRef, CoreWarnings, FastEnum from ._exceptions import BstError, ImplError, PluginError from .exceptions import ErrorDomain from ._loader.metasource import MetaSource @@ -271,6 +271,92 @@ class AliasSubstitution: _mirror: Union[SourceMirror, str] +class SourceInfoMedium(FastEnum): + """ + Indicates the meduim in which the source is obtained + + *Since: 2.5* + """ + + LOCAL = "local" + """ + Files stored locally in the project + """ + + ARCHIVE = "archive" + """ + An archive file + """ + + GIT = "git" + """ + A git repository + """ + + +class SourceVersionType(FastEnum): + """ + Indicates the type of the version string + + *Since: 2.5* + """ + + VERSION = "version" + """ + The upstream version string, which may be semantic version + """ + + COMMIT = "commit" + """ + A commit string which accurately represents a version in a source + code repository or VCS + """ + + SHA256 = "sha256" + """ + An sha256 checksum + """ + + DIGEST = "digest" + """ + A CAS digest representing the unique version of this source input + """ + +class SourceInfo: + """SourceInfo() + + An object representing the provenance of input reported by + :func:`Source.collect_source_info() <buildstream.source.Source.collect_source_info>` + + *Since: 2.5* + """ + + def __init__( + self, url: str, medium: str, version_type: str, version: str + ): + # XXX assert medium and version_type are valid values for the enums + + self.url: str = url + """ + The url of the source input + """ + + self.medium: str = medium + """ + The :class:`.SourceInfoMedium` of the source input + """ + + self.version_type: str = version_type + """ + The :class:`.SourceVersionType` of the source input + """ + + self.version: str = version + """ + A string which represents a unique version of this source input + """ + + class SourceFetcher: """SourceFetcher() @@ -690,6 +776,19 @@ class Source(Plugin): """ raise ImplError("Source plugin '{}' does not implement is_cached()".format(self.get_kind())) + def collect_source_info(self) -> Iterable[SourceInfo]: + """Get the :class:`.SourceInfo` objects describing this source + + This method is guaranteed to only be called whenever + :func:`Source.is_resolved() <buildstream.source.Source.is_resolved>` + returns `True`. + + Returns: the :class:`.SourceInfo` objects describing this source + + *Since: 2.5* + """ + raise ImplError("Source plugin '{}' does not implement collect_source_info()".format(self.get_kind())) + ############################################################# # Public Methods # #############################################################
