@@ -2116,6 +2116,7 @@ from . import az
from . import crate
from . import gcp
from . import gomod
+from . import gosum
methods.append(local.Local())
methods.append(wget.Wget())
@@ -2140,3 +2141,4 @@ methods.append(gcp.GCP())
methods.append(gomod.GoMod())
methods.append(gomod.GoModGit())
methods.extend(npmsw.methods)
+methods.extend(gosum.methods)
new file mode 100644
@@ -0,0 +1,51 @@
+# Copyright (C) 2024-2025 Weidmueller Interface GmbH & Co. KG
+# Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
+#
+# SPDX-License-Identifier: MIT
+#
+"""
+BitBake 'Fetch' implementation for go.sum
+
+The gosum, gosum+https and gosum+git fetchers are used to download
+Go mod dependencies via a go.sum file.
+"""
+
+import os
+import bb
+import base64
+from bb.fetch2 import ParameterError
+from bb.fetch2 import URI
+from bb.fetch2.dependency import create_methods
+
+class GoSumMixin:
+ def resolve_dependencies(self, ud, localpath, d):
+ urls = []
+
+ def resolve_dependency(module_path, version, hash):
+ uri = URI(f"gomod://{module_path}")
+ if version.endswith("/go.mod"):
+ uri.params["version"] = version[:-7]
+ uri.params["mod"] = "1"
+ else:
+ uri.params["version"] = version
+ if hash.startswith("h1:"):
+ uri.params["h1sum"] = base64.b64decode(hash[3:]).hex()
+ else:
+ raise ParameterError(f"Invalid hash: {hash}", ud.url)
+ urls.append(str(uri))
+
+ if os.path.isdir(localpath):
+ localpath = os.path.join(localpath, "go.sum")
+ try:
+ with open(localpath, "r") as f:
+ for line in f:
+ fields = line.strip().split()
+ if len(fields) != 3:
+ raise ParameterError(f"Invalid go.sum line: {line}", ud.url)
+ resolve_dependency(*fields)
+ except Exception as e:
+ raise ParameterError(f"Invalid go.sum file: {str(e)}", ud.url)
+
+ return urls
+
+methods = create_methods("gosum", GoSumMixin)