1#!/usr/bin/env python3
2import sys
3import json
4
5if len(sys.argv) == 1:
6 print("usage: ./this-script 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# stubs for symbols we are not interested in
30# might need to be expanded if new bazel releases add symbols to the workspace
31def workspace(name): pass
32def load(*args): pass
33def bind(**kw): pass
34def list_source_repository(**kw): pass
35def new_local_repository(**kw): pass
36def local_repository(**kw): pass
37DOC_VERSIONS = []
38def stardoc_repositories(**kw): pass
39def skydoc_repositories(**kw): pass
40def rules_sass_dependencies(**kw): pass
41def node_repositories(**kw): pass
42def sass_repositories(**kw): pass
43def register_execution_platforms(*args): pass
44def rbe_autoconfig(*args, **kw): pass
45def rules_pkg_dependencies(*args, **kw): pass
46def winsdk_configure(*args, **kw): pass
47def register_local_rc_exe_toolchains(*args, **kw): pass
48def register_toolchains(*args, **kw): pass
49def debian_deps(): pass
50def grpc_deps(): pass
51def grpc_extra_deps(): pass
52def bazel_skylib_workspace(): pass
53
54# execute the WORKSPACE like it was python code in this module,
55# using all the function stubs from above.
56with open(sys.argv[1]) as f:
57 exec(f.read())
58
59# transform to a dict with the names as keys
60d = { el['name']: el for el in http_archives }
61
62print(json.dumps(d, sort_keys=True, indent=4))