···11+#!/usr/bin/env python3
22+import sys
33+import json
44+55+if len(sys.argv) != 2:
66+ print("usage: ./this-script src-deps.json < WORKSPACE", file=sys.stderr)
77+ print("Takes the bazel WORKSPACE file and reads all archives into a json dict (by evaling it as python code)", file=sys.stderr)
88+ print("Hail Eris.", file=sys.stderr)
99+ sys.exit(1)
1010+1111+http_archives = []
1212+1313+# just the kw args are the dict { name, sha256, urls … }
1414+def http_archive(**kw):
1515+ http_archives.append(kw)
1616+# like http_file
1717+def http_file(**kw):
1818+ http_archives.append(kw)
1919+2020+# this is inverted from http_archive/http_file and bundles multiple archives
2121+def distdir_tar(**kw):
2222+ for archive_name in kw['archives']:
2323+ http_archives.append({
2424+ "name": archive_name,
2525+ "sha256": kw['sha256'][archive_name],
2626+ "urls": kw['urls'][archive_name]
2727+ })
2828+2929+# TODO?
3030+def git_repository(**kw):
3131+ print(json.dumps(kw, sort_keys=True, indent=4), file=sys.stderr)
3232+ sys.exit(1)
3333+3434+# execute the WORKSPACE like it was python code in this module,
3535+# using all the function stubs from above.
3636+exec(sys.stdin.read())
3737+3838+# transform to a dict with the names as keys
3939+d = { el['name']: el for el in http_archives }
4040+4141+def has_urls(el):
4242+ return ('url' in el and el['url']) or ('urls' in el and el['urls'])
4343+def has_sha256(el):
4444+ return 'sha256' in el and el['sha256']
4545+bad_archives = list(filter(lambda el: not has_urls(el) or not has_sha256(el), d.values()))
4646+if bad_archives:
4747+ print('Following bazel dependencies are missing url or sha256', file=sys.stderr)
4848+ print('Check bazel sources for master or non-checksummed dependencies', file=sys.stderr)
4949+ for el in bad_archives:
5050+ print(json.dumps(el, sort_keys=True, indent=4), file=sys.stderr)
5151+ sys.exit(1)
5252+5353+with open(sys.argv[1], "w") as f:
5454+ print(json.dumps(d, sort_keys=True, indent=4), file=f)