def CheckDirectory(self, start_dir): """Checks all relevant source files in the specified directory and its subdirectories for compliance with DEPS rules throughout the tree (starting at |self.base_directory|). |start_dir| must be a subdirectory of |self.base_directory|. On completion, self.results_formatter has the results of processing, and calling Report() will print a report of results. """ java = java_checker.JavaChecker(self.base_directory, self.verbose) cpp = cpp_checker.CppChecker(self.verbose, self._resolve_dotdot, self.base_directory) checkers = dict((extension, checker) for checker in [java, cpp] for extension in checker.EXTENSIONS) for rules, file_paths in self.GetAllRulesAndFiles(start_dir): for full_name in file_paths: if self._skip_tests and _IsTestFile( os.path.basename(full_name)): continue file_extension = os.path.splitext(full_name)[1] if not file_extension in checkers: continue checker = checkers[file_extension] file_status = checker.CheckFile(rules, full_name) if file_status.HasViolations(): self.results_formatter.AddError(file_status)
def CheckAddedCppIncludes(self, added_includes): """This is used from PRESUBMIT.py to check new #include statements added in the change being presubmit checked. Args: added_includes: ((file_path, (include_line, include_line, ...), ...) Return: A list of tuples, (bad_file_path, rule_type, rule_description) where rule_type is one of Rule.DISALLOW or Rule.TEMP_ALLOW and rule_description is human-readable. Empty if no problems. """ cpp = cpp_checker.CppChecker(self.verbose) problems = [] for file_path, include_lines in added_includes: if not cpp.IsCppFile(file_path): pass rules_for_file = self.GetDirectoryRules(os.path.dirname(file_path)) if rules_for_file: for line in include_lines: is_include, violation = cpp.CheckLine( rules_for_file, line, file_path, True) if violation: rule_type = violation.violated_rule.allow if rule_type != Rule.ALLOW: violation_text = results.NormalResultsFormatter.FormatViolation( violation, self.verbose) problems.append((file_path, rule_type, violation_text)) return problems
def CheckAddedCppIncludes(self, added_includes): """This is used from PRESUBMIT.py to check new #include statements added in the change being presubmit checked. Args: added_includes: ((file_path, (include_line, include_line, ...), ...) Return: A list of tuples, (bad_file_path, rule_type, rule_description) where rule_type is one of Rule.DISALLOW or Rule.TEMP_ALLOW and rule_description is human-readable. Empty if no problems. """ return self.CheckIncludesAndImports( added_includes, cpp_checker.CppChecker(self.verbose))
def CheckDirectory(self, start_dir): """Checks all relevant source files in the specified directory and its subdirectories for compliance with DEPS rules throughout the tree (starting at |self.base_directory|). |start_dir| must be a subdirectory of |self.base_directory|. On completion, self.results_formatter has the results of processing, and calling Report() will print a report of results. """ java = java_checker.JavaChecker(self.base_directory, self.verbose) cpp = cpp_checker.CppChecker(self.verbose) checkers = dict((extension, checker) for checker in [java, cpp] for extension in checker.EXTENSIONS) self._CheckDirectoryImpl(checkers, start_dir)