xref: /openbmc/qemu/scripts/qemu-stamp.py (revision 75bbe5e5)
1#! /usr/bin/env python3
2
3# Usage: scripts/qemu-stamp.py STRING1 STRING2... -- FILE1 FILE2...
4import hashlib
5import os
6import sys
7
8sha = hashlib.sha1()
9is_file = False
10for arg in sys.argv[1:]:
11    if arg == '--':
12        is_file = True
13        continue
14    if is_file:
15        with open(arg, 'rb') as f:
16            for chunk in iter(lambda: f.read(65536), b''):
17                sha.update(chunk)
18    else:
19        sha.update(os.fsencode(arg))
20        sha.update(b'\n')
21
22# The hash can start with a digit, which the compiler doesn't
23# like as an symbol. So prefix it with an underscore
24print("_" + sha.hexdigest())
25