juergbi commented on code in PR #1903:
URL: https://github.com/apache/buildstream/pull/1903#discussion_r1543314696


##########
src/buildstream/source.py:
##########
@@ -721,31 +727,64 @@ def translate_url(
            the URL was previously marked with 
:func:`Source.mark_download_url() <buildstream.source.Source.mark_download_url>`
            at :func:`Plugin.configure() <buildstream.plugin.Plugin.configure>` 
time.
         """
+        project = self._get_project()
+
         # Ensure that the download URL is also marked
         self.mark_download_url(url, primary=primary)
 
         if suffix:
             url = url + suffix
 
+        # Here we are called either:
+        #   * From a source fetcher with "alias_override" specified
+        #   * From a cloned source with self.__alias_override specified
+        #   * From the default source, with a possibly aliased source
+        #     * In this last case, mirrors are ignored
+        #
+        # In both relevant cases, we need to have the SourceMirror in context, 
and
+        # then we can delegate the translation to the SourceMirror while 
providing
+        # the original "url" to the SourceMirror method.
+        #
+        # Use the `self.__active_mirror` object
+
         # 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:
+
             url_alias, url_body = url.split(utils._ALIAS_SEPARATOR, 1)
-            if url_alias:
-                if alias_override:
-                    url = alias_override + url_body
-                else:
-                    # Implicit alias overrides may only be done for one
-                    # specific alias, so that sources that fetch from multiple
-                    # URLs and use different aliases default to only overriding
-                    # one alias, rather than getting confused.
-                    override_alias = self.__alias_override[0]  # type: ignore
-                    override_url = self.__alias_override[1]  # type: ignore
-                    if url_alias == override_alias:
-                        url = override_url + url_body
-            return url
+            project_alias_url = project.get_alias_url(url_alias, 
first_pass=self.__first_pass)
+
+            if self.__alias_override is not None:
+                override_alias = self.__alias_override[0]  # type: ignore
+                override_mirror = self.__alias_override[1]  # type: ignore
+
+                # Implicit alias overrides may only be done for one
+                # specific alias, so that sources that fetch from multiple
+                # URLs and use different aliases default to only overriding
+                # one alias, rather than getting confused.
+                #
+                if url_alias != override_alias:
+                    return url
+
+            elif alias_override is not None:
+                override_mirror = alias_override
+
+            assert override_mirror is not None, f"{alias_override} or 
{self.__alias_override}"
+
+            if isinstance(override_mirror, str):
+                return override_mirror + url_body
+            #
+            # Delegate the URL translation to the SourceMirror plugin
+            #
+            return override_mirror.translate_url(
+                project_name=project.name,

Review Comment:
   The `project_name` parameter has been removed from 
`SourceMirror.translate_url()`.



##########
tests/frontend/project/sourcemirrors/mirror.py:
##########
@@ -0,0 +1,39 @@
+from typing import Optional, Dict, Any
+
+from buildstream import SourceMirror, MappingNode
+
+
+# This mirror plugin basically implements the default behavior
+# by loading the alias definitions as custom "config" configuration
+# instead, and implementing the translate_url method.
+#
+class Sample(SourceMirror):
+    BST_MIN_VERSION = "2.0"
+
+    def configure(self, node):
+        node.validate_keys(SourceMirror.COMMON_CONFIG_KEYS + ["aliases"])
+
+        self.aliases = {}
+
+        aliases = node.get_mapping("aliases")
+        for alias_name, url_list in aliases.items():
+            self.aliases[alias_name] = url_list.as_str_list()
+
+        self.set_supported_aliases(self.aliases.keys())
+
+    def translate_url(
+        self,
+        *,
+        project_name: str,

Review Comment:
   The `project_name` parameter has been removed from 
`SourceMirror.translate_url()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to