MCPcopy Create free account
hub / github.com/SIPp/sipp / FilesBelongToSameModule

Function FilesBelongToSameModule

cpplint.py:3573–3625  ·  view source on GitHub ↗

Check if these two filenames belong to the same module. The concept of a 'module' here is a as follows: foo.h, foo-inl.h, foo.cc, foo_test.cc and foo_unittest.cc belong to the same 'module' if they are in the same directory. some/path/public/xyzzy and some/path/internal/xyzzy are also consi

(filename_cc, filename_h)

Source from the content-addressed store, hash-verified

3571
3572
3573def FilesBelongToSameModule(filename_cc, filename_h):
3574 """Check if these two filenames belong to the same module.
3575
3576 The concept of a 'module' here is a as follows:
3577 foo.h, foo-inl.h, foo.cc, foo_test.cc and foo_unittest.cc belong to the
3578 same 'module' if they are in the same directory.
3579 some/path/public/xyzzy and some/path/internal/xyzzy are also considered
3580 to belong to the same module here.
3581
3582 If the filename_cc contains a longer path than the filename_h, for example,
3583 '/absolute/path/to/base/sysinfo.cc', and this file would include
3584 'base/sysinfo.h', this function also produces the prefix needed to open the
3585 header. This is used by the caller of this function to more robustly open the
3586 header file. We don't have access to the real include paths in this context,
3587 so we need this guesswork here.
3588
3589 Known bugs: tools/base/bar.cc and base/bar.h belong to the same module
3590 according to this implementation. Because of this, this function gives
3591 some false positives. This should be sufficiently rare in practice.
3592
3593 Args:
3594 filename_cc: is the path for the .cc file
3595 filename_h: is the path for the header path
3596
3597 Returns:
3598 Tuple with a bool and a string:
3599 bool: True if filename_cc and filename_h belong to the same module.
3600 string: the additional prefix needed to open the header file.
3601 """
3602
3603 if not filename_cc.endswith('.cc'):
3604 return (False, '')
3605 filename_cc = filename_cc[:-len('.cc')]
3606 if filename_cc.endswith('_unittest'):
3607 filename_cc = filename_cc[:-len('_unittest')]
3608 elif filename_cc.endswith('_test'):
3609 filename_cc = filename_cc[:-len('_test')]
3610 filename_cc = filename_cc.replace('/public/', '/')
3611 filename_cc = filename_cc.replace('/internal/', '/')
3612
3613 if not filename_h.endswith('.h'):
3614 return (False, '')
3615 filename_h = filename_h[:-len('.h')]
3616 if filename_h.endswith('-inl'):
3617 filename_h = filename_h[:-len('-inl')]
3618 filename_h = filename_h.replace('/public/', '/')
3619 filename_h = filename_h.replace('/internal/', '/')
3620
3621 files_belong_to_same_module = filename_cc.endswith(filename_h)
3622 common_path = ''
3623 if files_belong_to_same_module:
3624 common_path = filename_cc[:-len(filename_h)]
3625 return files_belong_to_same_module, common_path
3626
3627
3628def UpdateIncludeState(filename, include_state, io=codecs):

Callers 1

Calls 1

replaceMethod · 0.80

Tested by

no test coverage detected