Debian Codegraph @

tools/distrib/clang_tidy_code.sh

raw
1 #!/bin/bash
2 # Copyright 2015 gRPC authors.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 echo "NOTE: to automagically apply fixes, invoke with --fix"
17
18 set -ex
19
20 # change to root directory
21 cd $(dirname $0)/../..
22 REPO_ROOT=$(pwd)
23
24 # grep targets with manual tag, which is not included in a result of bazel build using ...
25 # let's get a list of them using query command and pass it to gen_compilation_database.py
26 export MANUAL_TARGETS=$(bazel query 'attr("tags", "manual", tests(//test/cpp/...))' | grep -v _on_ios)
27
28 # generate a clang compilation database for all C/C++ sources in the repo.
29 tools/distrib/gen_compilation_database.py \
30 --include_headers \
31 --ignore_system_headers \
32 --dedup_targets \
33 "//:*" \
34 "//src/core/..." \
35 "//src/compiler/..." \
36 "//test/core/..." \
37 "//test/cpp/..." \
38 $MANUAL_TARGETS
39
40 if [ "$CLANG_TIDY_SKIP_DOCKER" == "" ]
41 then
42 # build clang-tidy docker image
43 docker build -t grpc_clang_tidy tools/dockerfile/grpc_clang_tidy
44
45 # run clang-tidy against the checked out codebase
46 # when modifying the checked-out files, the current user will be impersonated
47 # so that the updated files don't end up being owned by "root".
48 docker run \
49 -e TEST="$TEST" \
50 -e CHANGED_FILES="$CHANGED_FILES" \
51 -e CLANG_TIDY_ROOT="/local-code" \
52 --rm=true \
53 -v "${REPO_ROOT}":/local-code \
54 -v "${HOME/.cache/bazel}":"${HOME/.cache/bazel}" \
55 --user "$(id -u):$(id -g)" \
56 -t grpc_clang_tidy /clang_tidy_all_the_things.sh "$@"
57 else
58 CLANG_TIDY_ROOT="${REPO_ROOT}" tools/dockerfile/grpc_clang_tidy/clang_tidy_all_the_things.sh "$@"
59 fi