forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_dependencies.py
executable file
·76 lines (59 loc) · 2.02 KB
/
print_dependencies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
# Quick-and-dirty python to fetch dependency information
import imp
import json
import os.path
import re
import subprocess
import sys
API_DEPS = imp.load_source('api', 'api/bazel/repository_locations.bzl')
DEPS = imp.load_source('deps', 'bazel/repository_locations.bzl')
RECIPE_MAP = imp.load_source('deps', 'bazel/target_recipes.bzl')
RECIPE_INFO = imp.load_source('recipes', 'ci/build_container/build_recipes/versions.py')
def print_deps(deps):
print(json.dumps(deps, sort_keys=True, indent=2))
if __name__ == '__main__':
deps = []
DEPS.REPOSITORY_LOCATIONS.update(API_DEPS.REPOSITORY_LOCATIONS)
for key, loc in DEPS.REPOSITORY_LOCATIONS.items():
deps.append({
'identifier': key,
'file-sha256': loc.get('sha256'),
'file-url': loc.get('urls')[0],
'file-prefix': loc.get('strip_prefix', ''),
})
for key, loc in RECIPE_INFO.RECIPES.items():
deps.append({
'identifier': key,
'file-sha256': loc.get('sha256'),
'file-url': loc.get('url'),
'file-prefix': loc.get('strip_prefix', ''),
})
deps = sorted(deps, key=lambda k: k['identifier'])
# Print all dependencies if a target is unspecified
if len(sys.argv) == 1:
print_deps(deps)
exit(0)
# Bazel target to print
target = sys.argv[1]
output = subprocess.check_output(['bazel', 'query', 'deps(%s)' % target])
repos = set()
# Gather the explicit list of repositories
repo_regex = re.compile('^@(.*)\/\/')
for line in output.split('\n'):
match = repo_regex.match(line)
if match:
repos.add(match.group(1))
# Gather the build recipes repositories
# These are part of @envoy_deps repository ie @envoy_deps//:luajit
recipe_regex = re.compile('^@envoy_deps//:(\w+)$')
for line in output.split('\n'):
match = recipe_regex.match(line)
if not match:
continue
key = match.group(1)
repo = RECIPE_MAP.TARGET_RECIPES[key]
if repo:
repos.add(repo)
deps = filter(lambda dep: dep['identifier'] in repos, deps)
print_deps(deps)