Skip to content
Snippets Groups Projects
Commit f8eacca8 authored by Craig Tiller's avatar Craig Tiller
Browse files

Merge pull request #4729 from sreecha/import_issues_proto

Generate transitive dependencies as well in gen_build_yaml.py for protos
parents 21c0ebf6 a193faf0
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
# Copyright 2015, Google Inc. # Copyright 2015-2016, Google Inc.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
...@@ -36,21 +36,36 @@ import os ...@@ -36,21 +36,36 @@ import os
import re import re
import sys import sys
def update_deps(key, proto_filename, deps, is_trans, visited):
if not proto_filename in visited:
visited.append(proto_filename)
with open(proto_filename) as inp:
for line in inp:
imp = re.search(r'import "([^"]*)"', line)
if not imp: continue
imp_proto = imp.group(1)
if key not in deps: deps[key] = []
deps[key].append(imp_proto[:-6])
if is_trans:
update_deps(key, imp_proto, deps, is_trans, visited)
def main(): def main():
proto_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
os.chdir(os.path.join(proto_dir, '../..'))
deps = {} deps = {}
for root, dirs, files in os.walk(os.path.dirname(sys.argv[0])): deps_trans = {}
for root, dirs, files in os.walk('src/proto'):
for f in files: for f in files:
if f[-6:] != '.proto': continue if f[-6:] != '.proto': continue
look_at = os.path.join(root, f) look_at = os.path.join(root, f)
with open(look_at) as inp: deps_for = look_at[:-6]
for line in inp: update_deps(deps_for, look_at, deps, False, []) # First level deps
imp = re.search(r'import "([^"]*)"', line) update_deps(deps_for, look_at, deps_trans, True, []) # Transitive deps
if not imp: continue
if look_at[:-6] not in deps: deps[look_at[:-6]] = []
deps[look_at[:-6]].append(imp.group(1)[:-6])
json = { json = {
'proto_deps': deps 'proto_deps': deps,
'proto_transitive_deps': deps_trans
} }
print yaml.dump(json) print yaml.dump(json)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment