Skip to content

Commit

Permalink
Merge pull request grpc#6088 from murgatroid99/proto_gen_build_yaml_w…
Browse files Browse the repository at this point in the history
…ell_known_types

Handle google/protobuf includes in src/proto
  • Loading branch information
nicolasnoble committed Apr 7, 2016
2 parents 4560356 + 0d4b13c commit d6ac251
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/proto/gen_build_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,49 @@
import re
import sys

def update_deps(key, proto_filename, deps, is_trans, visited):
def update_deps(key, proto_filename, deps, deps_external, 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)
# This indicates an external dependency, which we should handle
# differently and not traverse recursively
if imp_proto.startswith('google/'):
if key not in deps_external:
deps_external[key] = []
deps_external[key].append(imp_proto[:-6])
continue
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)
update_deps(key, imp_proto, deps, deps_external, is_trans, visited)

def main():
proto_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
os.chdir(os.path.join(proto_dir, '../..'))

deps = {}
deps_trans = {}
deps_external = {}
deps_external_trans = {}
for root, dirs, files in os.walk('src/proto'):
for f in files:
if f[-6:] != '.proto': continue
look_at = os.path.join(root, f)
deps_for = look_at[:-6]
update_deps(deps_for, look_at, deps, False, []) # First level deps
update_deps(deps_for, look_at, deps_trans, True, []) # Transitive deps
# First level deps
update_deps(deps_for, look_at, deps, deps_external, False, [])
# Transitive deps
update_deps(deps_for, look_at, deps_trans, deps_external_trans, True, [])

json = {
'proto_deps': deps,
'proto_transitive_deps': deps_trans
'proto_transitive_deps': deps_trans,
'proto_external_deps': deps_external,
'proto_transitive_external_deps': deps_external_trans
}

print yaml.dump(json)
Expand Down

0 comments on commit d6ac251

Please sign in to comment.