Skip to content

Commit

Permalink
Explicitly specify Google Test path in clang-tidy script
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 committed Jan 30, 2019
1 parent 2c16f55 commit 0e7c5e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions doc/contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ from the top level source tree:

.. code-black:: bash
cd /path/to/xgboost/
python3 tests/ci_build/tidy.py
python3 tests/ci_build/tidy.py --gtest-path=/path/to/google-test

The script accepts two optional integer arguments, namely --cpp and --cuda.
The script requires the full path of Google Test library via the ``--gtest-path`` argument.

Also, the script accepts two optional integer arguments, namely ``--cpp`` and ``--cuda``.
By default they are both set to 1. If you want to exclude CUDA source from
linting, use:

Expand Down
11 changes: 8 additions & 3 deletions tests/ci_build/tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ class ClangTidy(object):
'''
clang tidy wrapper.
Args:
gtest_path: Full path of Google Test library.
cpp_lint: Run linter on C++ source code.
cuda_lint: Run linter on CUDA source code.
'''
def __init__(self, cpp_lint, cuda_lint):
def __init__(self, gtest_path, cpp_lint, cuda_lint):
self.gtest_path = gtest_path
self.cpp_lint = cpp_lint
self.cuda_lint = cuda_lint
print('Using Google Test from {}'.format(self.gtest_path))
print('Run linter on CUDA: ', self.cuda_lint)
print('Run linter on C++:', self.cpp_lint)
if not self.cpp_lint and not self.cuda_lint:
Expand All @@ -58,7 +61,7 @@ def _generate_cdb(self):
os.mkdir(self.cdb_path)
os.chdir(self.cdb_path)
cmake_args = ['cmake', '..', '-DGENERATE_COMPILATION_DATABASE=ON',
'-DGOOGLE_TEST=ON']
'-DGOOGLE_TEST=ON', '-DGTEST_ROOT={}'.format(self.gtest_path)]
if self.cuda_lint:
cmake_args.extend(['-DUSE_CUDA=ON', '-DUSE_NCCL=ON'])
subprocess.run(cmake_args)
Expand Down Expand Up @@ -141,8 +144,10 @@ def run(self):
parser = argparse.ArgumentParser(description='Run clang-tidy.')
parser.add_argument('--cpp', type=int, default=1)
parser.add_argument('--cuda', type=int, default=1)
parser.add_argument('--gtest-path', required=True,
help='Full path of Google Test library directory')
args = parser.parse_args()
with ClangTidy(args.cpp, args.cuda) as linter:
with ClangTidy(args.gtest_path, args.cpp, args.cuda) as linter:
passed = linter.run()
# Uncomment it once the code base is clang-tidy conformant.
# if not passed:
Expand Down

0 comments on commit 0e7c5e6

Please sign in to comment.