summaryrefslogtreecommitdiff
path: root/buildstream/source.py
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-09-02 17:41:56 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-09-02 18:37:12 +0900
commit1f9c41476313614aec4f0444f0eef6055cf3cb14 (patch)
treedded059aace75bed66b68170b6c4169bece3f0ec /buildstream/source.py
parent16462e9cd2007ae9e90fd94a7af5ba4c142cf83e (diff)
downloadbuildstream-1f9c41476313614aec4f0444f0eef6055cf3cb14.tar.gz
source.py: Added `primary` argument to URL marking APIs
The Source must now mention whether the marked or translated URL is "primary" or not. Even when a Source may have multiple URLs, the auxilliary URLs are derived from the primary one, not only is this true for git, but it is mandated by our tracking API which assumes there is a primary URL. This adjusts the `git` source and the test `fetch_source.py` source to behave properly and advertize it's primary URL properly. This is a part of #620
Diffstat (limited to 'buildstream/source.py')
-rw-r--r--buildstream/source.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/buildstream/source.py b/buildstream/source.py
index 412970ae4..f9f306904 100644
--- a/buildstream/source.py
+++ b/buildstream/source.py
@@ -296,8 +296,10 @@ 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
+
+ # The alias_override is only set on a re-instantiated Source
self.__alias_override = alias_override # Tuple of alias and its override to use instead
- self.__expected_alias = None # A hacky way to store the first alias used
+ self.__expected_alias = None # The primary alias
# FIXME: Reconstruct a MetaSource from a Source instead of storing it.
self.__meta = meta # MetaSource stored so we can copy this source later.
@@ -503,17 +505,17 @@ class Source(Plugin):
os.makedirs(directory, exist_ok=True)
return directory
- def translate_url(self, url, *, alias_override=None):
+ def translate_url(self, url, *, alias_override=None, primary=True):
"""Translates the given url which may be specified with an alias
into a fully qualified url.
Args:
- url (str): A url, which may be using an alias
+ url (str): A URL, which may be using an alias
alias_override (str): Optionally, an URI to override the alias with. (*Since: 1.2*)
+ primary (bool): Whether this is the primary URL for the source. (*Since: 1.2*)
Returns:
- str: The fully qualified url, with aliases resolved
-
+ str: The fully qualified URL, with aliases resolved
.. note::
This must be called for every URL in the configuration during
@@ -521,6 +523,9 @@ class Source(Plugin):
:func:`Source.mark_download_url() <buildstream.source.Source.mark_download_url>`
is not called.
"""
+ # Ensure that the download URL is also marked
+ self.mark_download_url(url, primary=primary)
+
# Alias overriding can happen explicitly (by command-line) or
# implicitly (the Source being constructed with an __alias_override).
if alias_override or self.__alias_override:
@@ -539,18 +544,15 @@ class Source(Plugin):
url = override_url + url_body
return url
else:
- # Sneakily store the alias if it hasn't already been stored
- if not self.__expected_alias and url and utils._ALIAS_SEPARATOR in url:
- self.mark_download_url(url)
-
project = self._get_project()
return project.translate_url(url, first_pass=self.__first_pass)
- def mark_download_url(self, url):
+ def mark_download_url(self, url, *, primary=True):
"""Identifies the URL that this Source uses to download
Args:
- url (str): The url used to download
+ url (str): The URL used to download
+ primary (bool): Whether this is the primary URL for the source
.. note::
@@ -561,7 +563,17 @@ class Source(Plugin):
*Since: 1.2*
"""
- self.__expected_alias = _extract_alias(url)
+ # Only mark the Source level aliases on the main instance, not in
+ # a reinstantiated instance in mirroring.
+ if not self.__alias_override:
+ if primary:
+ expected_alias = _extract_alias(url)
+
+ assert (self.__expected_alias is None or
+ self.__expected_alias == expected_alias), \
+ "Primary URL marked twice with different URLs"
+
+ self.__expected_alias = expected_alias
def get_project_directory(self):
"""Fetch the project base directory