Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Checks: '
,performance-*
,-performance-noexcept-move-constructor
'
WarningsAsErrors: '*'
HeaderFilterRegex: 'torch/csrc/.*'
AnalyzeTemporaryDtors: false
CheckOptions:
Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,88 @@ jobs:
regex: '^(?<filename>.*?):(?<lineNumber>\d+):(?<columnNumber>\d+): (?<errorCode>\w\d+) (?<errorDesc>.*)'
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: '^(?<filename>.*?):(?<lineNumber>\d+):(?<columnNumber>\d+): (?<errorDesc>.*?) (?<errorCode>\[.*\])'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 8 additions & 2 deletions tools/clang_tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import collections
import fnmatch
import json
import os
import os.path
import re
import shlex
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
4 changes: 3 additions & 1 deletion torch/csrc/jit/script/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,10 @@ void initJitScriptBindings(PyObject* module) {
return pythonResolver(rcb)->resolveType(name, range);
});

py::class_<logging::LoggerBase, std::shared_ptr<logging::LoggerBase>>(

py::class_<logging::LoggerBase, std::shared_ptr<logging::LoggerBase>>(
m, "LoggerBase");

py::enum_<logging::LockingLogger::AggregationType>(m, "AggregationType")
.value("SUM", logging::LockingLogger::AggregationType::SUM)
.value("AVG", logging::LockingLogger::AggregationType::AVG)
Expand Down