This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch jonathan/mirror-client in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 2b725046ae71534004f20736c4492acf2794b05d Author: Jonathan Maw <[email protected]> AuthorDate: Mon Apr 9 16:20:05 2018 +0100 source: Store the url aliases or use an override This is part of a later plan to implement mirroring without forcing everyone to update their sources. We use the expected calls to Source.translate_url() when running Source.configure() to extract the aliases from the URL. Multiple aliases must be extracted because sources exist that may fetch from multiple aliases (for example, git submodules) Later, we want to substitute another URI where the alias normally reads from the project - We accomplish this by re-instantiating the Source with the alias overrides passed as an argument to the constructor. --- buildstream/source.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/buildstream/source.py b/buildstream/source.py index fa547d6..48803ee 100644 --- a/buildstream/source.py +++ b/buildstream/source.py @@ -125,7 +125,7 @@ class Source(Plugin): __defaults = {} # The defaults from the project __defaults_set = False # Flag, in case there are not defaults at all - def __init__(self, context, project, meta): + def __init__(self, context, project, meta, *, alias_overrides=None): provenance = _yaml.node_get_provenance(meta.config) super().__init__("{}-{}".format(meta.element_name, meta.element_index), context, project, provenance, "source") @@ -135,6 +135,8 @@ class Source(Plugin): self.__element_kind = meta.element_kind # The kind of the element owning this source self.__directory = meta.directory # Staging relative directory self.__consistency = Consistency.INCONSISTENT # Cached consistency state + self.__alias_overrides = alias_overrides # Aliases to use instead of the one from the project + self._expected_aliases = set() # A hacky way to store which aliases the source used # Collect the composited element configuration and # ask the element to configure itself. @@ -310,8 +312,22 @@ class Source(Plugin): Returns: str: The fully qualified url, with aliases resolved """ - project = self._get_project() - return project.translate_url(url) + if self.__alias_overrides: + if url and utils._ALIAS_SEPARATOR in url: + url_alias, url_body = url.split(utils._ALIAS_SEPARATOR, 1) + url = self.__alias_overrides[url_alias] + url_body + return url + else: + project = self._get_project() + # Sneakily store the alias + if url and utils._ALIAS_SEPARATOR in url: + url_alias, _ = url.split(utils._ALIAS_SEPARATOR, 1) + # The alias must already be defined in the project's aliases + # otherwise http://foo gets treated like it contains an alias + if project.get_alias_uri(url_alias): + self._expected_aliases.add(url_alias) + + return project.translate_url(url) def get_project_directory(self): """Fetch the project base directory
