diff --git a/.clang-tidy b/.clang-tidy index fae404cddb40..5a289a1e1444 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -28,7 +28,6 @@ Checks: ' ,performance-* ,-performance-noexcept-move-constructor ' -WarningsAsErrors: '*' HeaderFilterRegex: 'torch/csrc/.*' AnalyzeTemporaryDtors: false CheckOptions: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index bd981991edf7..54f16600f014 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -46,3 +46,88 @@ jobs: regex: '^(?.*?):(?\d+):(?\d+): (?\w\d+) (?.*)' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + clang-tidy: + runs-on: ubuntu-latest + steps: + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.7.4 + architecture: x64 + - name: Checkout PyTorch + uses: actions/checkout@master + - name: Checkout PR tip + run: | + set -eux + git checkout ${GITHUB_HEAD_REF} + echo ::set-output name=commit_sha::$(git rev-parse ${GITHUB_HEAD_REF}) + id: get_pr_tip + - name: Install dependencies + run: | + set -eux + # Install dependencies + pip install pyyaml + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main" + sudo apt-get update + sudo apt-get install -y clang-tidy-8 + sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-8 1000 + - name: Run clang-tidy + run: | + set -eux + BASE_BRANCH=master + if [[ $SYSTEM_PULLREQUEST_TARGETBRANCH ]]; then + git remote add upstream https://github.com/pytorch/pytorch + git fetch upstream "$SYSTEM_PULLREQUEST_TARGETBRANCH" + BASE_BRANCH="upstream/$SYSTEM_PULLREQUEST_TARGETBRANCH" + fi + + if [[ ! -d build ]]; then + git submodule update --init --recursive + + mkdir build + pushd build + # We really only need compile_commands.json, so no need to build! + time cmake .. + popd + + # Generate ATen files. + time python aten/src/ATen/gen.py \ + -s aten/src/ATen \ + -d build/aten/src/ATen \ + aten/src/ATen/Declarations.cwrap \ + aten/src/THNN/generic/THNN.h \ + aten/src/THCUNN/generic/THCUNN.h \ + aten/src/ATen/nn.yaml \ + aten/src/ATen/native/native_functions.yaml + + # Generate PyTorch files. + time python tools/setup_helpers/generate_code.py \ + --declarations-path build/aten/src/ATen/Declarations.yaml \ + --nn-path aten/src + fi + + # Run Clang-Tidy + # The negative filters below are to exclude files that include onnx_pb.h or + # caffe2_pb.h, otherwise we'd have to build protos as part of this CI job. + python tools/clang_tidy.py \ + --paths torch/csrc/ \ + --diff "$BASE_BRANCH" \ + -g"-torch/csrc/jit/export.cpp" \ + -g"-torch/csrc/jit/import.cpp" \ + -g"-torch/csrc/jit/netdef_converter.cpp" \ + "$@" > ${GITHUB_WORKSPACE}/clang-tidy-output.txt + + cat ${GITHUB_WORKSPACE}/clang-tidy-output.txt + env: + SYSTEM_PULLREQUEST_TARGETBRANCH: ${{ github.base_ref }} + - name: Add annotations + uses: suo/add-annotations-github-action@master + with: + check_name: 'clang-tidy' + linter_output_path: 'clang-tidy-output.txt' + commit_sha: ${{ steps.get_pr_tip.outputs.commit_sha }} + regex: '^(?.*?):(?\d+):(?\d+): (?.*?) (?\[.*\])' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/tools/clang_tidy.py b/tools/clang_tidy.py index 3bd9c095cd8f..0baac9e36f1b 100755 --- a/tools/clang_tidy.py +++ b/tools/clang_tidy.py @@ -18,6 +18,7 @@ import collections import fnmatch import json +import os import os.path import re import shlex @@ -172,7 +173,7 @@ def run_clang_tidy(options, line_filters, files): with open(options.config_file) as config: # Here we convert the YAML config file to a JSON blob. - command += ["-config", json.dumps(yaml.load(config))] + command += ["-config", json.dumps(yaml.load(config, Loader=yaml.FullLoader))] command += options.extra_args if line_filters: @@ -293,8 +294,13 @@ def main(): if options.diff: line_filters = [get_changed_lines(options.diff, f) for f in files] - print(run_clang_tidy(options, line_filters, files), file=sys.stderr) + pwd = os.getcwd() + "/" + clang_tidy_output = run_clang_tidy(options, line_filters, files) + formatted_output = [] + for line in clang_tidy_output.splitlines(): + if line.startswith(pwd): + print(line[len(pwd):]) if __name__ == "__main__": main() diff --git a/torch/csrc/jit/script/init.cpp b/torch/csrc/jit/script/init.cpp index dac7007178ab..9da37ba5de15 100644 --- a/torch/csrc/jit/script/init.cpp +++ b/torch/csrc/jit/script/init.cpp @@ -1017,8 +1017,10 @@ void initJitScriptBindings(PyObject* module) { return pythonResolver(rcb)->resolveType(name, range); }); - py::class_>( + + py::class_>( m, "LoggerBase"); + py::enum_(m, "AggregationType") .value("SUM", logging::LockingLogger::AggregationType::SUM) .value("AVG", logging::LockingLogger::AggregationType::AVG)