diff options
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r-- | bitbake/lib/bb/utils.py | 25 |
1 files changed, 25 insertions, 0 deletions
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 | ||
588 | def 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 | |||
588 | def preserved_envvars_exported(): | 613 | def 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""" |