check_message_owners.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python
  2. # Copyright 2014 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Make sure all of the per-file *_messages.h OWNERS are consistent"""
  6. from __future__ import print_function
  7. import os
  8. import re
  9. import sys
  10. def main():
  11. file_path = os.path.dirname(__file__);
  12. root_dir = os.path.abspath(os.path.join(file_path, '..', '..'))
  13. owners = collect_owners(root_dir)
  14. all_owners = get_all_owners(owners)
  15. print_missing_owners(owners, all_owners)
  16. return 0
  17. def collect_owners(root_dir):
  18. result = {}
  19. for root, dirs, files in os.walk(root_dir):
  20. if "OWNERS" in files:
  21. owner_file_path = os.path.join(root, "OWNERS")
  22. owner_set = extract_owners_from_file(owner_file_path)
  23. if owner_set:
  24. result[owner_file_path] = owner_set
  25. return result
  26. def extract_owners_from_file(owner_file_path):
  27. result = set()
  28. regexp = re.compile('^per-file.*_messages[^=]*=\s*(.*)@([^#]*)')
  29. with open(owner_file_path) as f:
  30. for line in f:
  31. match = regexp.match(line)
  32. if match:
  33. result.add(match.group(1).strip())
  34. return result
  35. def get_all_owners(owner_dict):
  36. result = set()
  37. for key in owner_dict:
  38. result = result.union(owner_dict[key])
  39. return result
  40. def print_missing_owners(owner_dict, owner_set):
  41. for key in owner_dict:
  42. for owner in owner_set:
  43. if not owner in owner_dict[key]:
  44. print(key + " is missing " + owner)
  45. if '__main__' == __name__:
  46. sys.exit(main())