def CheckFile(self, rules, filepath): if self._verbose: print 'Checking: ' + filepath dependee_status = results.DependeeStatus(filepath) with codecs.open(filepath, encoding='utf-8') as f: for line in f: for clazz in re.findall( '^import\s+(?:static\s+)?([\w\.]+)\s*;', line): if clazz not in self._classmap: # Importing a class from outside the Chromium tree. That's fine -- # it's probably a Java or Android system class. continue include_path = os.path.relpath(self._classmap[clazz], self._base_directory) # Convert Windows paths to Unix style, as used in DEPS files. include_path = include_path.replace(os.path.sep, '/') rule = rules.RuleApplyingTo(include_path, filepath) if rule.allow == Rule.DISALLOW: dependee_status.AddViolation( results.DependencyViolation( include_path, rule, rules)) if '{' in line: # This is code, so we're finished reading imports for this file. break return dependee_status
def CheckFile(self, rules, filepath): if self._verbose: print 'Checking: ' + filepath dependee_status = results.DependeeStatus(filepath) ret_val = '' # We'll collect the error messages in here last_include = 0 with codecs.open(filepath, encoding='utf-8') as f: in_if0 = 0 for line_num, line in enumerate(f): if line_num - last_include > self._MAX_UNINTERESTING_LINES: break line = line.strip() # Check to see if we're at / inside an #if 0 block if line.startswith('#if 0'): in_if0 += 1 continue if in_if0 > 0: if line.startswith('#if'): in_if0 += 1 elif line.startswith('#endif'): in_if0 -= 1 continue is_include, violation = self.CheckLine(rules, line, filepath) if is_include: last_include = line_num if violation: dependee_status.AddViolation(violation) return dependee_status
def CheckFile(self, rules, filepath): if self._verbose: print 'Checking: ' + filepath dependee_status = results.DependeeStatus(filepath) with codecs.open(filepath, encoding='utf-8') as f: for line in f: is_import, violation = self.CheckLine(rules, line, filepath) if violation: dependee_status.AddViolation(violation) if '{' in line: # This is code, so we're finished reading imports for this file. break return dependee_status
def CheckFile(self, rules, filepath): if self._verbose: print('Checking: ' + filepath) dependee_status = results.DependeeStatus(filepath) last_import = 0 with codecs.open(filepath, encoding='utf-8') as f: for line_num, line in enumerate(f): if line_num - last_import > self._MAX_UNINTERESTING_LINES: break line = line.strip() is_import, violation = self.CheckLine(rules, line, filepath) if is_import: last_import = line_num if violation: dependee_status.AddViolation(violation) return dependee_status