Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] glibc-sourcery: Add hash to glibc PKGVERSION #231

Open
wants to merge 1 commit into
base: cos10-adit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions recipes-sourcery/glibc-sourcery/glibc-pkgversion.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
def glibc_pkgversion (d):
src = d.getVar('S')
if src == None:
return 'INVALID'

# Exclude some files from calculation of hash:
# '.git' leads to unpredictable results,
# '.pc' and 'patches' do not contain sources,
# 'elf/ldd.bash.in' is modified in do_configure_prepend.
skip = ['.git', '.pc', 'patches', os.path.join('elf', 'ldd.bash.in')]

def parse_dir(root, d, h):
ls = sorted(os.listdir(d)) # sort directory entries to ensure reproducibility
for f in ls:
p = os.path.join(d, f) # absolute path
r = os.path.relpath(p, root) # relative path
if r in skip:
return
if os.path.islink(p):
pass # skip symbolic links
elif os.path.isdir(p):
parse_dir(root, p, h) # recursively run this sub-routine
elif os.path.isfile(p):
# Hash all file contents
with open(p, 'rb') as fd:
h.update((r + ' ').encode('utf-8')) # add relative file path
h.update(fd.read()) # add file contents
h.update(b'!@#$%^&*') # add file separator

if os.path.isdir(src):
import hashlib

# SHA256 should be a good choice
h = hashlib.sha256()

# Concatenate all files
parse_dir(src, src, h)

# Calculate hash
return h.hexdigest()

EXTRA_OECONF_append = " --with-pkgversion='built with hash ${@glibc_pkgversion(d)}'"
1 change: 1 addition & 0 deletions recipes-sourcery/glibc-sourcery/glibc-sourcery.bb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require recipes-core/glibc/glibc.inc
require recipes-external/glibc/glibc-external-version.inc
include glibc-pkgversion.inc

FILESPATH .= ":${COREBASE}/meta/recipes-core/glibc/glibc"
EXTERNAL_TOOLCHAIN_SYSROOT ?= "${@external_run(d, 'gcc', *(TARGET_CC_ARCH.split() + ['-print-sysroot'])).rstrip()}"
Expand Down