MCPcopy Create free account
hub / github.com/apache/mesos / GetHeaderGuardCPPVariable

Function GetHeaderGuardCPPVariable

support/cpplint.py:1814–1887  ·  view source on GitHub ↗

Returns the CPP variable that should be used as a header guard. Args: filename: The name of a C++ header file. Returns: The CPP variable that should be used as a header guard in the named file.

(filename)

Source from the content-addressed store, hash-verified

1812 return lst
1813
1814def GetHeaderGuardCPPVariable(filename):
1815 """Returns the CPP variable that should be used as a header guard.
1816
1817 Args:
1818 filename: The name of a C++ header file.
1819
1820 Returns:
1821 The CPP variable that should be used as a header guard in the
1822 named file.
1823
1824 """
1825
1826 # Restores original filename in case that cpplint is invoked from Emacs's
1827 # flymake.
1828 filename = re.sub(r'_flymake\.h$', '.h', filename)
1829 filename = re.sub(r'/\.flymake/([^/]*)$', r'/\1', filename)
1830 # Replace 'c++' with 'cpp'.
1831 filename = filename.replace('C++', 'cpp').replace('c++', 'cpp')
1832
1833 fileinfo = FileInfo(filename)
1834 file_path_from_root = fileinfo.RepositoryName()
1835
1836 def FixupPathFromRoot():
1837 if _root_debug:
1838 sys.stderr.write("\n_root fixup, _root = '%s', repository name = '%s'\n"
1839 %(_root, fileinfo.RepositoryName()))
1840
1841 # Process the file path with the --root flag if it was set.
1842 if not _root:
1843 if _root_debug:
1844 sys.stderr.write("_root unspecified\n")
1845 return file_path_from_root
1846
1847 def StripListPrefix(lst, prefix):
1848 # f(['x', 'y'], ['w, z']) -> None (not a valid prefix)
1849 if lst[:len(prefix)] != prefix:
1850 return None
1851 # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
1852 return lst[(len(prefix)):]
1853
1854 # root behavior:
1855 # --root=subdir , lstrips subdir from the header guard
1856 maybe_path = StripListPrefix(PathSplitToList(file_path_from_root),
1857 PathSplitToList(_root))
1858
1859 if _root_debug:
1860 sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," +
1861 " _root=%s)\n") %(maybe_path, file_path_from_root, _root))
1862
1863 if maybe_path:
1864 return os.path.join(*maybe_path)
1865
1866 # --root=.. , will prepend the outer directory to the header guard
1867 full_path = fileinfo.FullName()
1868 root_abspath = os.path.abspath(_root)
1869
1870 maybe_path = StripListPrefix(PathSplitToList(full_path),
1871 PathSplitToList(root_abspath))

Callers 2

CheckForHeaderGuardFunction · 0.85
CheckStyleFunction · 0.85

Calls 4

RepositoryNameMethod · 0.95
FileInfoClass · 0.85
FixupPathFromRootFunction · 0.85
upperMethod · 0.45

Tested by

no test coverage detected