Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/buildstream/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ def create_source_info(
version: str,
*,
version_guess: Optional[str] = None,
provenance_node: Optional[MappingNode] = None,
extra_data: Optional[Dict[str, str]] = None,
) -> SourceInfo:
"""Create a :class:`.SourceInfo` object
Expand All @@ -1386,15 +1387,23 @@ def create_source_info(
choice depicting the type of version.
version: A string which represents a unique version of this source input
version_guess: An optional string representing the guessed human readable version
provenance_node: The optional YAML node with source provenance attributes,
defaults to the provenance specified at the top level of the source.
extra_data: Additional plugin defined key/values

*Since: 2.5*
"""
homepage = None
issue_tracker = None
if self.__provenance is not None:
homepage = self.__provenance.homepage
issue_tracker = self.__provenance.issue_tracker

if provenance_node is not None:
provenance: Optional[_SourceProvenance] = _SourceProvenance.new_from_node(provenance_node)
else:
provenance = self.__provenance

if provenance is not None:
homepage = provenance.homepage
issue_tracker = provenance.issue_tracker

return SourceInfo(
self.get_kind(),
Expand Down
30 changes: 30 additions & 0 deletions tests/frontend/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,3 +814,33 @@ def test_source_info_workspace(cli, datafiles, tmpdir):

# There is no version guessing for a workspace
assert source_info.get_str("version-guess", None) is None


@pytest.mark.datafiles(os.path.join(DATA_DIR, "source-info"))
def test_multi_source_info(cli, datafiles):
project = str(datafiles)
result = cli.run(
project=project, silent=True, args=["show", "--format", "%{name}:\n%{source-info}", "multisource.bst"]
)
result.assert_success()

loaded = _yaml.load_data(result.output)
sources = loaded.get_sequence("multisource.bst")

source_info = sources.mapping_at(0)
assert source_info.get_str("kind") == "multisource"
assert source_info.get_str("url") == "http://ponyfarm.com/ponies"
assert source_info.get_str("medium") == "pony-ride"
assert source_info.get_str("version-type") == "pony-age"
assert source_info.get_str("version") == "1234567"
assert source_info.get_str("version-guess", None) == "12"
assert source_info.get_str("homepage") == "https://flying-ponies.com/index.html"

source_info = sources.mapping_at(1)
assert source_info.get_str("kind") == "multisource"
assert source_info.get_str("url") == "http://ponyfarm.com/happy"
assert source_info.get_str("medium") == "pony-ride"
assert source_info.get_str("version-type") == "pony-age"
assert source_info.get_str("version") == "1234567"
assert source_info.get_str("version-guess", None) == "12"
assert source_info.get_str("homepage") == "http://happy.ponyfarm.com"
6 changes: 6 additions & 0 deletions tests/frontend/source-info/elements/multisource.bst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: import

sources:
- kind: multisource
provenance:
homepage: https://flying-ponies.com/index.html
46 changes: 46 additions & 0 deletions tests/frontend/source-info/plugins/multisource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from buildstream import Node, Source


class MultiSource(Source):
BST_MIN_VERSION = "2.0"

def configure(self, node):
pass

def preflight(self):
pass

def get_unique_key(self):
return {}

def load_ref(self, node):
pass

def get_ref(self):
return {}

def set_ref(self, ref, node):
pass

def is_cached(self):
return False

def collect_source_info(self):
return [
self.create_source_info(
"http://ponyfarm.com/ponies", "pony-ride", "pony-age", "1234567", version_guess="12"
),
self.create_source_info(
"http://ponyfarm.com/happy",
"pony-ride",
"pony-age",
"1234567",
version_guess="12",
provenance_node=Node.from_dict({"homepage": "http://happy.ponyfarm.com"}),
),
]


# Plugin entry point
def setup():
return MultiSource
1 change: 1 addition & 0 deletions tests/frontend/source-info/project.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ plugins:
path: plugins
sources:
- extradata
- multisource
- testsource
- unimplemented
Loading