Code Duplication    Length = 56-56 lines in 2 locations

core/build-support/cpplint.py 1 location

@@ 5571-5626 (lines=56) @@
5568
         _header))
5569
5570
5571
def FilesBelongToSameModule(filename_cc, filename_h):
5572
  """Check if these two filenames belong to the same module.
5573
5574
  The concept of a 'module' here is a as follows:
5575
  foo.h, foo-inl.h, foo.cc, foo_test.cc and foo_unittest.cc belong to the
5576
  same 'module' if they are in the same directory.
5577
  some/path/public/xyzzy and some/path/internal/xyzzy are also considered
5578
  to belong to the same module here.
5579
5580
  If the filename_cc contains a longer path than the filename_h, for example,
5581
  '/absolute/path/to/base/sysinfo.cc', and this file would include
5582
  'base/sysinfo.h', this function also produces the prefix needed to open the
5583
  header. This is used by the caller of this function to more robustly open the
5584
  header file. We don't have access to the real include paths in this context,
5585
  so we need this guesswork here.
5586
5587
  Known bugs: tools/base/bar.cc and base/bar.h belong to the same module
5588
  according to this implementation. Because of this, this function gives
5589
  some false positives. This should be sufficiently rare in practice.
5590
5591
  Args:
5592
    filename_cc: is the path for the source (e.g. .cc) file
5593
    filename_h: is the path for the header path
5594
5595
  Returns:
5596
    Tuple with a bool and a string:
5597
    bool: True if filename_cc and filename_h belong to the same module.
5598
    string: the additional prefix needed to open the header file.
5599
  """
5600
  fileinfo_cc = FileInfo(filename_cc)
5601
  if not fileinfo_cc.Extension().lstrip('.') in GetNonHeaderExtensions():
5602
    return (False, '')
5603
5604
  fileinfo_h = FileInfo(filename_h)
5605
  if not fileinfo_h.Extension().lstrip('.') in GetHeaderExtensions():
5606
    return (False, '')
5607
5608
  filename_cc = filename_cc[:-(len(fileinfo_cc.Extension()))]
5609
  matched_test_suffix = Search(_TEST_FILE_SUFFIX, fileinfo_cc.BaseName())
5610
  if matched_test_suffix:
5611
    filename_cc = filename_cc[:-len(matched_test_suffix.group(1))]
5612
5613
  filename_cc = filename_cc.replace('/public/', '/')
5614
  filename_cc = filename_cc.replace('/internal/', '/')
5615
5616
  filename_h = filename_h[:-(len(fileinfo_h.Extension()))]
5617
  if filename_h.endswith('-inl'):
5618
    filename_h = filename_h[:-len('-inl')]
5619
  filename_h = filename_h.replace('/public/', '/')
5620
  filename_h = filename_h.replace('/internal/', '/')
5621
5622
  files_belong_to_same_module = filename_cc.endswith(filename_h)
5623
  common_path = ''
5624
  if files_belong_to_same_module:
5625
    common_path = filename_cc[:-len(filename_h)]
5626
  return files_belong_to_same_module, common_path
5627
5628
5629
def UpdateIncludeState(filename, include_dict, io=codecs):

sdk/build-support/cpplint.py 1 location

@@ 5571-5626 (lines=56) @@
5568
         _header))
5569
5570
5571
def FilesBelongToSameModule(filename_cc, filename_h):
5572
  """Check if these two filenames belong to the same module.
5573
5574
  The concept of a 'module' here is a as follows:
5575
  foo.h, foo-inl.h, foo.cc, foo_test.cc and foo_unittest.cc belong to the
5576
  same 'module' if they are in the same directory.
5577
  some/path/public/xyzzy and some/path/internal/xyzzy are also considered
5578
  to belong to the same module here.
5579
5580
  If the filename_cc contains a longer path than the filename_h, for example,
5581
  '/absolute/path/to/base/sysinfo.cc', and this file would include
5582
  'base/sysinfo.h', this function also produces the prefix needed to open the
5583
  header. This is used by the caller of this function to more robustly open the
5584
  header file. We don't have access to the real include paths in this context,
5585
  so we need this guesswork here.
5586
5587
  Known bugs: tools/base/bar.cc and base/bar.h belong to the same module
5588
  according to this implementation. Because of this, this function gives
5589
  some false positives. This should be sufficiently rare in practice.
5590
5591
  Args:
5592
    filename_cc: is the path for the source (e.g. .cc) file
5593
    filename_h: is the path for the header path
5594
5595
  Returns:
5596
    Tuple with a bool and a string:
5597
    bool: True if filename_cc and filename_h belong to the same module.
5598
    string: the additional prefix needed to open the header file.
5599
  """
5600
  fileinfo_cc = FileInfo(filename_cc)
5601
  if not fileinfo_cc.Extension().lstrip('.') in GetNonHeaderExtensions():
5602
    return (False, '')
5603
5604
  fileinfo_h = FileInfo(filename_h)
5605
  if not fileinfo_h.Extension().lstrip('.') in GetHeaderExtensions():
5606
    return (False, '')
5607
5608
  filename_cc = filename_cc[:-(len(fileinfo_cc.Extension()))]
5609
  matched_test_suffix = Search(_TEST_FILE_SUFFIX, fileinfo_cc.BaseName())
5610
  if matched_test_suffix:
5611
    filename_cc = filename_cc[:-len(matched_test_suffix.group(1))]
5612
5613
  filename_cc = filename_cc.replace('/public/', '/')
5614
  filename_cc = filename_cc.replace('/internal/', '/')
5615
5616
  filename_h = filename_h[:-(len(fileinfo_h.Extension()))]
5617
  if filename_h.endswith('-inl'):
5618
    filename_h = filename_h[:-len('-inl')]
5619
  filename_h = filename_h.replace('/public/', '/')
5620
  filename_h = filename_h.replace('/internal/', '/')
5621
5622
  files_belong_to_same_module = filename_cc.endswith(filename_h)
5623
  common_path = ''
5624
  if files_belong_to_same_module:
5625
    common_path = filename_cc[:-len(filename_h)]
5626
  return files_belong_to_same_module, common_path
5627
5628
5629
def UpdateIncludeState(filename, include_dict, io=codecs):