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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
53 | 53 |
54 def _BuildSubpackagesPattern(packages, query): | 54 def _BuildSubpackagesPattern(packages, query): |
55 """Returns a regular expression that matches source files inside subpackages | 55 """Returns a regular expression that matches source files inside subpackages |
56 of the given query.""" | 56 of the given query.""" |
57 query += '/' | 57 query += os.path.sep |
58 length = len(query) | 58 length = len(query) |
59 pattern = r'(?P<line_number>\d+)\$\s*"(?P<source_file>(?P<subpackage>' | 59 pattern = r'(?P<line_number>\d+)\$\s*"(?P<source_file>(?P<subpackage>' |
60 pattern += '|'.join(package[length:] for package in packages | 60 pattern += '|'.join(package[length:].replace(os.path.sep, '/') |
61 if package.startswith(query)) | 61 for package in packages if package.startswith(query)) |
62 pattern += r')/[\w\./]*)"' | 62 pattern += r')/[\w\./]*)"' |
63 return re.compile(pattern) | 63 return re.compile(pattern) |
64 | 64 |
65 | 65 |
66 def _ReadFileAndPrependLines(file_path): | 66 def _ReadFileAndPrependLines(file_path): |
67 """Reads the contents of a file and prepends the line number to every line.""" | 67 """Reads the contents of a file and prepends the line number to every line.""" |
68 with open(file_path) as f: | 68 with open(file_path) as f: |
69 return "".join("{}${}".format(line_number, line) | 69 return "".join("{}${}".format(line_number, line) |
70 for line_number, line in enumerate(f, 1)) | 70 for line_number, line in enumerate(f, 1)) |
71 | 71 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |