Skip to content

Commit 3711934

Browse files
bnoordhuisrvagg
authored andcommittedSep 7, 2015
cpplint: make it possible to run outside git repo
cpplint uses the top-level .git directory to determine what the root is for #include guards. If it doesn't find a .git directory, it walks up all the way to the system root and subsequently complains that guards must be written as HOME_USER_SRC_NODE_SRC_FILENAME_H_. This commit replaces the .git-based path munging with a fixed root path relative to the location of the cpplint script, making it possible to successfully run `make test` from an extracted tarball. Fixes: #2693 PR-URL: #2710 Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent b2c3c6d commit 3711934

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed
 

‎tools/cpplint.py

+4-31
Original file line numberDiff line numberDiff line change
@@ -695,37 +695,10 @@ def RepositoryName(self):
695695
locations won't see bogus errors.
696696
"""
697697
fullname = self.FullName()
698-
699-
if os.path.exists(fullname):
700-
project_dir = os.path.dirname(fullname)
701-
702-
if os.path.exists(os.path.join(project_dir, ".svn")):
703-
# If there's a .svn file in the current directory, we recursively look
704-
# up the directory tree for the top of the SVN checkout
705-
root_dir = project_dir
706-
one_up_dir = os.path.dirname(root_dir)
707-
while os.path.exists(os.path.join(one_up_dir, ".svn")):
708-
root_dir = os.path.dirname(root_dir)
709-
one_up_dir = os.path.dirname(one_up_dir)
710-
711-
prefix = os.path.commonprefix([root_dir, project_dir])
712-
return fullname[len(prefix) + 1:]
713-
714-
# Not SVN? Try to find a git or hg top level directory by searching up
715-
# from the current path.
716-
root_dir = os.path.dirname(fullname)
717-
while (root_dir != os.path.dirname(root_dir) and
718-
not os.path.exists(os.path.join(root_dir, ".git")) and
719-
not os.path.exists(os.path.join(root_dir, ".hg"))):
720-
root_dir = os.path.dirname(root_dir)
721-
722-
if (os.path.exists(os.path.join(root_dir, ".git")) or
723-
os.path.exists(os.path.join(root_dir, ".hg"))):
724-
prefix = os.path.commonprefix([root_dir, project_dir])
725-
return fullname[len(prefix) + 1:]
726-
727-
# Don't know what to do; header guard warnings may be wrong...
728-
return fullname
698+
# XXX(bnoordhuis) Expects that cpplint.py lives in the tools/ directory.
699+
toplevel = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
700+
prefix = os.path.commonprefix([fullname, toplevel])
701+
return fullname[len(prefix) + 1:]
729702

730703
def Split(self):
731704
"""Splits the file into the directory, basename, and extension.

0 commit comments

Comments
 (0)
Please sign in to comment.