Commit a70817b2 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Teach gen_fuzzer_owners.py about GN groups.

In gen_fuzzer_owners.py, GetSourcesFromDeps() receives a list of
dependencies based on the fuzzer_tests in the GN build configuration.
Existing configurations are fairly simple, with source_sets as direct
dependencies. Introducing a GN group into a fuzzer_test will break
gen_fuzzer_owners.py.

This CL augments GetSourcesFromDeps() to look through the list of
dependencies for groups and replace the groups with their direct
dependencies. Since groups can depend on other groups, traverse the
dependencies graph until all groups have been replaced.

Change-Id: Ib0e15a18c7916af6790f41b1c752ab18bda970d9
Reviewed-on: https://chromium-review.googlesource.com/1077071Reviewed-by: default avatarMax Moroz <mmoroz@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564989}
parent c10b8178
......@@ -86,13 +86,70 @@ def GetOwnersForFuzzer(sources):
return None
def FindGroupsAndDepsInDeps(deps_list, build_dir):
"""Return list of groups, as well as their deps, from a list of deps."""
groups = []
deps_for_groups = {}
for deps in deps_list:
output = subprocess.check_output([GNPath(), 'desc', build_dir, deps])
needle = 'Type: '
for line in output.splitlines():
if needle and not line.startswith(needle):
continue
if needle == 'Type: ':
if line != 'Type: group':
break
groups.append(deps)
assert deps not in deps_for_groups
deps_for_groups[deps] = []
needle = 'Direct dependencies'
elif needle == 'Direct dependencies':
needle = ''
else:
assert needle == ''
if needle == line:
break
deps_for_groups[deps].append(line.strip())
return groups, deps_for_groups
def TraverseGroups(deps_list, build_dir):
"""Filter out groups from a deps list. Add groups' direct dependencies."""
full_deps_set = set(deps_list)
deps_to_check = full_deps_set.copy()
# Keep track of groups to break circular dependendies, if any.
seen_groups = set()
while deps_to_check:
# Look for groups from the deps set.
groups, deps_for_groups = FindGroupsAndDepsInDeps(deps_to_check, build_dir)
groups = set(groups).difference(seen_groups)
if not groups:
break
# Update sets. Filter out groups from the full deps set.
full_deps_set.difference_update(groups)
deps_to_check.clear()
seen_groups.update(groups)
# Get the direct dependencies, and filter out known groups there too.
for group in groups:
deps_to_check.update(deps_for_groups[group])
deps_to_check.difference_update(seen_groups)
full_deps_set.update(deps_to_check)
return list(full_deps_set)
def GetSourcesFromDeps(deps_list, build_dir):
"""Return list of sources from parsing deps."""
if not deps_list:
return None
full_deps_list = TraverseGroups(deps_list, build_dir)
all_sources = []
for deps in deps_list:
for deps in full_deps_list:
output = subprocess.check_output(
[GNPath(), 'desc', build_dir, deps, 'sources'])
for source in output.splitlines():
......@@ -117,11 +174,7 @@ def GNPath():
def SubStringExistsIn(substring_list, string):
"""Return true if one of the substring in the list is found in |string|."""
for substring in substring_list:
if substring in string:
return True
return False
return any([substring in string for substring in substring_list])
def main():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment