Code Duplication    Length = 76-76 lines in 2 locations

sdk/build-support/cpplint.py 1 location

@@ 4673-4748 (lines=76) @@
4670
4671
4672
4673
def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
4674
  """Check rules that are applicable to #include lines.
4675
4676
  Strings on #include lines are NOT removed from elided line, to make
4677
  certain tasks easier. However, to prevent false positives, checks
4678
  applicable to #include lines in CheckLanguage must be put here.
4679
4680
  Args:
4681
    filename: The name of the current file.
4682
    clean_lines: A CleansedLines instance containing the file.
4683
    linenum: The number of the line to check.
4684
    include_state: An _IncludeState instance in which the headers are inserted.
4685
    error: The function to call with any errors found.
4686
  """
4687
  fileinfo = FileInfo(filename)
4688
  line = clean_lines.lines[linenum]
4689
4690
  # "include" should use the new style "foo/bar.h" instead of just "bar.h"
4691
  # Only do this check if the included header follows google naming
4692
  # conventions.  If not, assume that it's a 3rd party API that
4693
  # requires special include conventions.
4694
  #
4695
  # We also make an exception for Lua headers, which follow google
4696
  # naming convention but not the include convention.
4697
  match = Match(r'#include\s*"([^/]+\.h)"', line)
4698
  if match and not _THIRD_PARTY_HEADERS_PATTERN.match(match.group(1)):
4699
    error(filename, linenum, 'build/include_subdir', 4,
4700
          'Include the directory when naming .h files')
4701
4702
  # we shouldn't include a file more than once. actually, there are a
4703
  # handful of instances where doing so is okay, but in general it's
4704
  # not.
4705
  match = _RE_PATTERN_INCLUDE.search(line)
4706
  if match:
4707
    include = match.group(2)
4708
    is_system = (match.group(1) == '<')
4709
    duplicate_line = include_state.FindHeader(include)
4710
    if duplicate_line >= 0:
4711
      error(filename, linenum, 'build/include', 4,
4712
            '"%s" already included at %s:%s' %
4713
            (include, filename, duplicate_line))
4714
      return
4715
4716
    for extension in GetNonHeaderExtensions():
4717
      if (include.endswith('.' + extension) and
4718
          os.path.dirname(fileinfo.RepositoryName()) != os.path.dirname(include)):
4719
        error(filename, linenum, 'build/include', 4,
4720
              'Do not include .' + extension + ' files from other packages')
4721
        return
4722
4723
    if not _THIRD_PARTY_HEADERS_PATTERN.match(include):
4724
      include_state.include_list[-1].append((include, linenum))
4725
4726
      # We want to ensure that headers appear in the right order:
4727
      # 1) for foo.cc, foo.h  (preferred location)
4728
      # 2) c system files
4729
      # 3) cpp system files
4730
      # 4) for foo.cc, foo.h  (deprecated location)
4731
      # 5) other google headers
4732
      #
4733
      # We classify each include statement as one of those 5 types
4734
      # using a number of techniques. The include_state object keeps
4735
      # track of the highest type seen, and complains if we see a
4736
      # lower type after that.
4737
      error_message = include_state.CheckNextIncludeOrder(
4738
          _ClassifyInclude(fileinfo, include, is_system))
4739
      if error_message:
4740
        error(filename, linenum, 'build/include_order', 4,
4741
              '%s. Should be: %s.h, c system, c++ system, other.' %
4742
              (error_message, fileinfo.BaseName()))
4743
      canonical_include = include_state.CanonicalizeAlphabeticalOrder(include)
4744
      if not include_state.IsInAlphabeticalOrder(
4745
          clean_lines, linenum, canonical_include):
4746
        error(filename, linenum, 'build/include_alpha', 4,
4747
              'Include "%s" not in alphabetical order' % include)
4748
      include_state.SetLastHeader(canonical_include)
4749
4750
4751

core/build-support/cpplint.py 1 location

@@ 4673-4748 (lines=76) @@
4670
4671
4672
4673
def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
4674
  """Check rules that are applicable to #include lines.
4675
4676
  Strings on #include lines are NOT removed from elided line, to make
4677
  certain tasks easier. However, to prevent false positives, checks
4678
  applicable to #include lines in CheckLanguage must be put here.
4679
4680
  Args:
4681
    filename: The name of the current file.
4682
    clean_lines: A CleansedLines instance containing the file.
4683
    linenum: The number of the line to check.
4684
    include_state: An _IncludeState instance in which the headers are inserted.
4685
    error: The function to call with any errors found.
4686
  """
4687
  fileinfo = FileInfo(filename)
4688
  line = clean_lines.lines[linenum]
4689
4690
  # "include" should use the new style "foo/bar.h" instead of just "bar.h"
4691
  # Only do this check if the included header follows google naming
4692
  # conventions.  If not, assume that it's a 3rd party API that
4693
  # requires special include conventions.
4694
  #
4695
  # We also make an exception for Lua headers, which follow google
4696
  # naming convention but not the include convention.
4697
  match = Match(r'#include\s*"([^/]+\.h)"', line)
4698
  if match and not _THIRD_PARTY_HEADERS_PATTERN.match(match.group(1)):
4699
    error(filename, linenum, 'build/include_subdir', 4,
4700
          'Include the directory when naming .h files')
4701
4702
  # we shouldn't include a file more than once. actually, there are a
4703
  # handful of instances where doing so is okay, but in general it's
4704
  # not.
4705
  match = _RE_PATTERN_INCLUDE.search(line)
4706
  if match:
4707
    include = match.group(2)
4708
    is_system = (match.group(1) == '<')
4709
    duplicate_line = include_state.FindHeader(include)
4710
    if duplicate_line >= 0:
4711
      error(filename, linenum, 'build/include', 4,
4712
            '"%s" already included at %s:%s' %
4713
            (include, filename, duplicate_line))
4714
      return
4715
4716
    for extension in GetNonHeaderExtensions():
4717
      if (include.endswith('.' + extension) and
4718
          os.path.dirname(fileinfo.RepositoryName()) != os.path.dirname(include)):
4719
        error(filename, linenum, 'build/include', 4,
4720
              'Do not include .' + extension + ' files from other packages')
4721
        return
4722
4723
    if not _THIRD_PARTY_HEADERS_PATTERN.match(include):
4724
      include_state.include_list[-1].append((include, linenum))
4725
4726
      # We want to ensure that headers appear in the right order:
4727
      # 1) for foo.cc, foo.h  (preferred location)
4728
      # 2) c system files
4729
      # 3) cpp system files
4730
      # 4) for foo.cc, foo.h  (deprecated location)
4731
      # 5) other google headers
4732
      #
4733
      # We classify each include statement as one of those 5 types
4734
      # using a number of techniques. The include_state object keeps
4735
      # track of the highest type seen, and complains if we see a
4736
      # lower type after that.
4737
      error_message = include_state.CheckNextIncludeOrder(
4738
          _ClassifyInclude(fileinfo, include, is_system))
4739
      if error_message:
4740
        error(filename, linenum, 'build/include_order', 4,
4741
              '%s. Should be: %s.h, c system, c++ system, other.' %
4742
              (error_message, fileinfo.BaseName()))
4743
      canonical_include = include_state.CanonicalizeAlphabeticalOrder(include)
4744
      if not include_state.IsInAlphabeticalOrder(
4745
          clean_lines, linenum, canonical_include):
4746
        error(filename, linenum, 'build/include_alpha', 4,
4747
              'Include "%s" not in alphabetical order' % include)
4748
      include_state.SetLastHeader(canonical_include)
4749
4750
4751