|
4 | 4 |
|
5 | 5 | from argparse import ArgumentParser
|
6 | 6 | from hashlib import sha256
|
7 |
| -from functools import reduce |
| 7 | +from os.path import join as join_path |
8 | 8 |
|
9 | 9 | if __name__ == "__main__":
|
10 | 10 | parser = ArgumentParser(description='Generate id by computing a hash of the generated headers')
|
11 | 11 | parser.add_argument("headers", nargs='+', help='List of headers to generate id from')
|
| 12 | + # On Windows, we cannot list the realpath for every individual header since we hit cmd.exe's |
| 13 | + # maximum command line lenght. As a workaround, we pass the pwd and the headers separately. |
| 14 | + parser.add_argument("--parent-directory", help='Parent directory for the headers', required=True) |
12 | 15 | parser.add_argument("--varname", help='Name of the variable to generate', required=True)
|
13 | 16 | parser.add_argument("--output", help='Name of the header to generate', required=True)
|
14 | 17 |
|
15 | 18 | args = parser.parse_args()
|
16 | 19 | args.headers.sort()
|
17 | 20 |
|
18 | 21 | hash = sha256()
|
19 |
| - for x in args.headers: |
20 |
| - hash.update(open(x, 'rb').read()) |
| 22 | + for header in args.headers: |
| 23 | + hash.update(open(join_path(args.parent_directory, header), 'rb').read()) |
21 | 24 | digest_uchar = hash.digest()
|
22 | 25 | digest_elts = ", ".join(map(str, digest_uchar))
|
23 | 26 | print(f"static const unsigned char {args.varname}[] = {{{digest_elts}, 0}};", file=open(args.output, 'w'))
|
0 commit comments