| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 3 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 4 # | 4 # |
| 5 # Use of this source code is governed by a BSD-style license | 5 # Use of this source code is governed by a BSD-style license |
| 6 # that can be found in the LICENSE file in the root of the source | 6 # that can be found in the LICENSE file in the root of the source |
| 7 # tree. An additional intellectual property rights grant can be found | 7 # tree. An additional intellectual property rights grant can be found |
| 8 # in the file PATENTS. All contributing project authors may | 8 # in the file PATENTS. All contributing project authors may |
| 9 # be found in the AUTHORS file in the root of the source tree. | 9 # be found in the AUTHORS file in the root of the source tree. |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 ERROR_MESSAGE = ("{}:{} in target '{}':\n" | 32 ERROR_MESSAGE = ("{}:{} in target '{}':\n" |
| 33 " Source file '{}'\n" | 33 " Source file '{}'\n" |
| 34 " crosses boundary of package '{}'.\n") | 34 " crosses boundary of package '{}'.\n") |
| 35 | 35 |
| 36 | 36 |
| 37 class Logger(object): | 37 class Logger(object): |
| 38 def __init__(self, messages_left=None): | 38 def __init__(self, messages_left=None): |
| 39 self.log_level = DISPLAY_LEVEL | 39 self.log_level = DISPLAY_LEVEL |
| 40 self.messages_left = messages_left | 40 self.messages_left = messages_left |
| 41 | 41 |
| 42 def log(self, build_file_path, line_number, target_name, source_file, | 42 def Log(self, build_file_path, line_number, target_name, source_file, |
| 43 subpackage): | 43 subpackage): |
| 44 if self.messages_left is not None: | 44 if self.messages_left is not None: |
| 45 if not self.messages_left: | 45 if not self.messages_left: |
| 46 self.log_level = IGNORE_LEVEL | 46 self.log_level = IGNORE_LEVEL |
| 47 else: | 47 else: |
| 48 self.messages_left -= 1 | 48 self.messages_left -= 1 |
| 49 message = ERROR_MESSAGE.format(build_file_path, line_number, target_name, | 49 message = ERROR_MESSAGE.format(build_file_path, line_number, target_name, |
| 50 source_file, subpackage) | 50 source_file, subpackage) |
| 51 logging.log(self.log_level, message) | 51 logging.log(self.log_level, message) |
| 52 | 52 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 target_name = target_match.group('target_name') | 84 target_name = target_match.group('target_name') |
| 85 target_contents = target_match.group('target_contents') | 85 target_contents = target_match.group('target_contents') |
| 86 for sources_match in SOURCES_RE.finditer(target_contents): | 86 for sources_match in SOURCES_RE.finditer(target_contents): |
| 87 sources = sources_match.group('sources') | 87 sources = sources_match.group('sources') |
| 88 for subpackages_match in subpackages_re.finditer(sources): | 88 for subpackages_match in subpackages_re.finditer(sources): |
| 89 subpackage = subpackages_match.group('subpackage') | 89 subpackage = subpackages_match.group('subpackage') |
| 90 source_file = subpackages_match.group('source_file') | 90 source_file = subpackages_match.group('source_file') |
| 91 line_number = subpackages_match.group('line_number') | 91 line_number = subpackages_match.group('line_number') |
| 92 if subpackage: | 92 if subpackage: |
| 93 found_violations = True | 93 found_violations = True |
| 94 logger.log(build_file_path, line_number, target_name, source_file, | 94 logger.Log(build_file_path, line_number, target_name, source_file, |
| 95 subpackage) | 95 subpackage) |
| 96 | 96 |
| 97 return found_violations | 97 return found_violations |
| 98 | 98 |
| 99 | 99 |
| 100 def CheckPackageBoundaries(root_dir, logger, build_files=None): | 100 def CheckPackageBoundaries(root_dir, logger, build_files=None): |
| 101 packages = [root for root, _, files in os.walk(root_dir) | 101 packages = [root for root, _, files in os.walk(root_dir) |
| 102 if 'BUILD.gn' in files] | 102 if 'BUILD.gn' in files] |
| 103 default_build_files = [os.path.join(package, 'BUILD.gn') | 103 default_build_files = [os.path.join(package, 'BUILD.gn') |
| 104 for package in packages] | 104 for package in packages] |
| (...skipping 23 matching lines...) Expand all Loading... |
| 128 | 128 |
| 129 logging.basicConfig(format=LOG_FORMAT) | 129 logging.basicConfig(format=LOG_FORMAT) |
| 130 logging.getLogger().setLevel(DISPLAY_LEVEL) | 130 logging.getLogger().setLevel(DISPLAY_LEVEL) |
| 131 logger = Logger(args.max_messages) | 131 logger = Logger(args.max_messages) |
| 132 | 132 |
| 133 return CheckPackageBoundaries(args.root_dir, logger, args.build_files) | 133 return CheckPackageBoundaries(args.root_dir, logger, args.build_files) |
| 134 | 134 |
| 135 | 135 |
| 136 if __name__ == '__main__': | 136 if __name__ == '__main__': |
| 137 sys.exit(main()) | 137 sys.exit(main()) |
| OLD | NEW |