summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitbake/lib/bb/fetch2/__init__.py2
-rw-r--r--bitbake/lib/bb/utils.py25
2 files changed, 26 insertions, 1 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index d2a30c18f0..4dc94e6f2b 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -34,7 +34,7 @@ _revisions_cache = bb.checksum.RevisionsCache()
34 34
35logger = logging.getLogger("BitBake.Fetcher") 35logger = logging.getLogger("BitBake.Fetcher")
36 36
37CHECKSUM_LIST = [ "md5", "sha256", "sha1", "sha384", "sha512" ] 37CHECKSUM_LIST = [ "goh1", "md5", "sha256", "sha1", "sha384", "sha512" ]
38SHOWN_CHECKSUM_LIST = ["sha256"] 38SHOWN_CHECKSUM_LIST = ["sha256"]
39 39
40class BBFetchException(Exception): 40class BBFetchException(Exception):
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index e722f9113d..135c71c007 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -585,6 +585,31 @@ def sha512_file(filename):
585 import hashlib 585 import hashlib
586 return _hasher(hashlib.sha512(), filename) 586 return _hasher(hashlib.sha512(), filename)
587 587
588def goh1_file(filename):
589 """
590 Return the hex string representation of the Go mod h1 checksum of the
591 filename. The Go mod h1 checksum uses the Go dirhash package. The package
592 defines hashes over directory trees and is used by go mod for mod files and
593 zip archives.
594 """
595 import hashlib
596 import zipfile
597
598 lines = []
599 if zipfile.is_zipfile(filename):
600 with zipfile.ZipFile(filename) as archive:
601 for fn in sorted(archive.namelist()):
602 method = hashlib.sha256()
603 method.update(archive.read(fn))
604 hash = method.hexdigest()
605 lines.append("%s %s\n" % (hash, fn))
606 else:
607 hash = _hasher(hashlib.sha256(), filename)
608 lines.append("%s go.mod\n" % hash)
609 method = hashlib.sha256()
610 method.update("".join(lines).encode('utf-8'))
611 return method.hexdigest()
612
588def preserved_envvars_exported(): 613def preserved_envvars_exported():
589 """Variables which are taken from the environment and placed in and exported 614 """Variables which are taken from the environment and placed in and exported
590 from the metadata""" 615 from the metadata"""