···1+#!/usr/bin/env python3
2+import sys
3+import json
4+5+if 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+11+http_archives = []
12+13+# just the kw args are the dict { name, sha256, urls … }
14+def http_archive(**kw):
15+ http_archives.append(kw)
16+# like http_file
17+def http_file(**kw):
18+ http_archives.append(kw)
19+20+# this is inverted from http_archive/http_file and bundles multiple archives
21+def 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?
30+def 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.
36+exec(sys.stdin.read())
37+38+# transform to a dict with the names as keys
39+d = { el['name']: el for el in http_archives }
40+41+def has_urls(el):
42+ return ('url' in el and el['url']) or ('urls' in el and el['urls'])
43+def has_sha256(el):
44+ return 'sha256' in el and el['sha256']
45+bad_archives = list(filter(lambda el: not has_urls(el) or not has_sha256(el), d.values()))
46+if 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+53+with open(sys.argv[1], "w") as f:
54+ print(json.dumps(d, sort_keys=True, indent=4), file=f)