diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2015-09-05 15:44:21 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-09-06 09:28:42 +0200 |
commit | a493dab2e72d19ddd226cd2094463ddb2354af06 (patch) | |
tree | 11252a1752631ff6de0d972340cdf0f5ca715e37 /tools/cpplint.py | |
parent | ba02bd02e91773be161e03a9ed67745fba8f22db (diff) | |
download | node-new-a493dab2e72d19ddd226cd2094463ddb2354af06.tar.gz |
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: https://github.com/nodejs/node/issues/2693
PR-URL: https://github.com/nodejs/node/pull/2710
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'tools/cpplint.py')
-rw-r--r-- | tools/cpplint.py | 35 |
1 files changed, 4 insertions, 31 deletions
diff --git a/tools/cpplint.py b/tools/cpplint.py index 5ab156124a..4c4f577b34 100644 --- a/tools/cpplint.py +++ b/tools/cpplint.py @@ -695,37 +695,10 @@ class FileInfo: locations won't see bogus errors. """ fullname = self.FullName() - - if os.path.exists(fullname): - project_dir = os.path.dirname(fullname) - - if os.path.exists(os.path.join(project_dir, ".svn")): - # If there's a .svn file in the current directory, we recursively look - # up the directory tree for the top of the SVN checkout - root_dir = project_dir - one_up_dir = os.path.dirname(root_dir) - while os.path.exists(os.path.join(one_up_dir, ".svn")): - root_dir = os.path.dirname(root_dir) - one_up_dir = os.path.dirname(one_up_dir) - - prefix = os.path.commonprefix([root_dir, project_dir]) - return fullname[len(prefix) + 1:] - - # Not SVN? Try to find a git or hg top level directory by searching up - # from the current path. - root_dir = os.path.dirname(fullname) - while (root_dir != os.path.dirname(root_dir) and - not os.path.exists(os.path.join(root_dir, ".git")) and - not os.path.exists(os.path.join(root_dir, ".hg"))): - root_dir = os.path.dirname(root_dir) - - if (os.path.exists(os.path.join(root_dir, ".git")) or - os.path.exists(os.path.join(root_dir, ".hg"))): - prefix = os.path.commonprefix([root_dir, project_dir]) - return fullname[len(prefix) + 1:] - - # Don't know what to do; header guard warnings may be wrong... - return fullname + # XXX(bnoordhuis) Expects that cpplint.py lives in the tools/ directory. + toplevel = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) + prefix = os.path.commonprefix([fullname, toplevel]) + return fullname[len(prefix) + 1:] def Split(self): """Splits the file into the directory, basename, and extension. |