コード例 #1
0
ファイル: cpp_checker.py プロジェクト: Havok380/chromium-test
  def CheckLine(self, rules, line, dependee_path, fail_on_temp_allow=False):
    """Checks the given line with the given rule set.

    Returns a tuple (is_include, dependency_violation) where
    is_include is True only if the line is an #include or #import
    statement, and dependency_violation is an instance of
    results.DependencyViolation if the line violates a rule, or None
    if it does not.
    """
    found_item = self._EXTRACT_INCLUDE_PATH.match(line)
    if not found_item:
      return False, None  # Not a match

    include_path = found_item.group(1)

    if '\\' in include_path:
      return True, results.DependencyViolation(
          include_path,
          MessageRule('Include paths may not include backslashes.'),
          rules)

    if '/' not in include_path:
      # Don't fail when no directory is specified. We may want to be more
      # strict about this in the future.
      if self._verbose:
        print ' WARNING: directory specified with no path: ' + include_path
      return True, None

    rule = rules.RuleApplyingTo(include_path, dependee_path)
    if (rule.allow == Rule.DISALLOW or
        (fail_on_temp_allow and rule.allow == Rule.TEMP_ALLOW)):
      return True, results.DependencyViolation(include_path, rule, rules)
    return True, None
コード例 #2
0
    def CheckLine(self, rules, line, filepath, fail_on_temp_allow=False):
        """Checks the given line with the given rule set.

    Returns a tuple (is_import, dependency_violation) where
    is_import is True only if the line is an import
    statement, and dependency_violation is an instance of
    results.DependencyViolation if the line violates a rule, or None
    if it does not.
    """
        found_item = self._EXTRACT_IMPORT_PATH.match(line)
        if not found_item:
            return False, None  # Not a match
        clazz = found_item.group(1)
        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.
            return True, None
        import_path = os.path.relpath(self._classmap[clazz],
                                      self._base_directory)
        # Convert Windows paths to Unix style, as used in DEPS files.
        import_path = import_path.replace(os.path.sep, '/')
        rule = rules.RuleApplyingTo(import_path, filepath)
        if (rule.allow == Rule.DISALLOW
                or (fail_on_temp_allow and rule.allow == Rule.TEMP_ALLOW)):
            return True, results.DependencyViolation(import_path, rule, rules)
        return True, None
コード例 #3
0
ファイル: java_checker.py プロジェクト: sriram90/arangodb
    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
コード例 #4
0
    def CheckLine(self, rules, line, dependee_path, fail_on_temp_allow=False):
        """Checks the given line with the given rule set.

    Returns a tuple (is_import, dependency_violation) where
    is_import is True only if the line is an import
    statement, and dependency_violation is an instance of
    results.DependencyViolation if the line violates a rule, or None
    if it does not.
    """
        found_item = self._EXTRACT_IMPORT_PATH.match(line)
        if not found_item:
            return False, None  # Not a match

        import_path = found_item.group(1)

        if '\\' in import_path:
            return True, results.DependencyViolation(
                import_path,
                MessageRule('Import paths may not include backslashes.'),
                rules)

        if '/' not in import_path:
            # Don't fail when no directory is specified. We may want to be more
            # strict about this in the future.
            if self._verbose:
                print(' WARNING: import specified with no directory: ' +
                      import_path)
            return True, None

        if self._resolve_dotdot and '../' in import_path:
            dependee_dir = os.path.dirname(dependee_path)
            import_path = os.path.join(dependee_dir, import_path)
            import_path = os.path.relpath(import_path, self._root_dir)

        if not self.IsFullPath(import_path):
            return True, None

        rule = rules.RuleApplyingTo(import_path, dependee_path)

        if (rule.allow == Rule.DISALLOW
                or (fail_on_temp_allow and rule.allow == Rule.TEMP_ALLOW)):
            return True, results.DependencyViolation(import_path, rule, rules)
        return True, None