Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1#!/usr/bin/env python3
2import sys
3import json
4
5if len(sys.argv) != 2:
6 print("usage: ./this-script src-deps.json < WORKSPACE", file=sys.stderr)
7 print("Takes the bazel WORKSPACE file and reads all archives into a json dict (by evaling it as python code)", file=sys.stderr)
8 print("Hail Eris.", file=sys.stderr)
9 sys.exit(1)
10
11http_archives = []
12
13# just the kw args are the dict { name, sha256, urls … }
14def http_archive(**kw):
15 http_archives.append(kw)
16# like http_file
17def http_file(**kw):
18 http_archives.append(kw)
19
20# this is inverted from http_archive/http_file and bundles multiple archives
21def _distdir_tar(**kw):
22 for archive_name in kw['archives']:
23 http_archives.append({
24 "name": archive_name,
25 "sha256": kw['sha256'][archive_name],
26 "urls": kw['urls'][archive_name]
27 })
28
29# TODO?
30def git_repository(**kw):
31 print(json.dumps(kw, sort_keys=True, indent=4), file=sys.stderr)
32 sys.exit(1)
33
34# execute the WORKSPACE like it was python code in this module,
35# using all the function stubs from above.
36exec(sys.stdin.read())
37
38# transform to a dict with the names as keys
39d = { el['name']: el for el in http_archives }
40
41def has_urls(el):
42 return ('url' in el and el['url']) or ('urls' in el and el['urls'])
43def has_sha256(el):
44 return 'sha256' in el and el['sha256']
45bad_archives = list(filter(lambda el: not has_urls(el) or not has_sha256(el), d.values()))
46if bad_archives:
47 print('Following bazel dependencies are missing url or sha256', file=sys.stderr)
48 print('Check bazel sources for master or non-checksummed dependencies', file=sys.stderr)
49 for el in bad_archives:
50 print(json.dumps(el, sort_keys=True, indent=4), file=sys.stderr)
51 sys.exit(1)
52
53with open(sys.argv[1], "w") as f:
54 print(json.dumps(d, sort_keys=True, indent=4), file=f)