First pass IWYU tooling (#27857 )
* First pass IWYU tooling * fix * Automated change: Fix sanity tests * Update iwyu.sh * Update iwyu.sh * Update Dockerfile.template * Update iwyu.sh * Automated change: Fix sanity tests Co-authored-by: ctiller <ctiller@users.noreply.github.com>pull/27955/head
parent
f4c18944e2
commit
e602169fa0
30 changed files with 275 additions and 3 deletions
@ -0,0 +1,35 @@ |
|||||||
|
%YAML 1.2 |
||||||
|
--- | |
||||||
|
# Copyright 2021 gRPC authors. |
||||||
|
# |
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
# you may not use this file except in compliance with the License. |
||||||
|
# You may obtain a copy of the License at |
||||||
|
# |
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
# |
||||||
|
# Unless required by applicable law or agreed to in writing, software |
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
# See the License for the specific language governing permissions and |
||||||
|
# limitations under the License. |
||||||
|
|
||||||
|
FROM debian:bullseye |
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y clang-11 llvm-11-dev libclang-11-dev clang-format-11 jq git cmake python |
||||||
|
|
||||||
|
ENV CLANG_FORMAT=clang-format-11 |
||||||
|
|
||||||
|
RUN git clone https://github.com/include-what-you-use/include-what-you-use.git /iwyu |
||||||
|
# latest commit on the clang 11 branch |
||||||
|
RUN cd /iwyu && git checkout 5db414ac448004fe019871c977905cb7c2cff23f |
||||||
|
|
||||||
|
RUN mkdir /iwyu_build && cd /iwyu_build && cmake -G "Unix Makefiles" -DCMAKE_PREFIX_PATH=/usr/lib/llvm-11 /iwyu && make |
||||||
|
|
||||||
|
ADD iwyu.sh / |
||||||
|
|
||||||
|
# When running locally, we'll be impersonating the current user, so we need |
||||||
|
# to make the script runnable by everyone. |
||||||
|
RUN chmod a+rx /iwyu.sh |
||||||
|
|
||||||
|
CMD ["echo 'Run with tools/distrib/iwyu.sh'"] |
@ -0,0 +1,55 @@ |
|||||||
|
#!/bin/bash |
||||||
|
# Copyright 2021 gRPC authors. |
||||||
|
# |
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
# you may not use this file except in compliance with the License. |
||||||
|
# You may obtain a copy of the License at |
||||||
|
# |
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
# |
||||||
|
# Unless required by applicable law or agreed to in writing, software |
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
# See the License for the specific language governing permissions and |
||||||
|
# limitations under the License. |
||||||
|
|
||||||
|
echo "NOTE: to automagically apply fixes, invoke with --fix" |
||||||
|
|
||||||
|
set -ex |
||||||
|
|
||||||
|
# change to root directory |
||||||
|
cd $(dirname $0)/../.. |
||||||
|
REPO_ROOT=$(pwd) |
||||||
|
|
||||||
|
# grep targets with manual tag, which is not included in a result of bazel build using ... |
||||||
|
# let's get a list of them using query command and pass it to gen_compilation_database.py |
||||||
|
export MANUAL_TARGETS=$(bazel query 'attr("tags", "manual", tests(//test/cpp/...))' | grep -v _on_ios) |
||||||
|
|
||||||
|
# generate a clang compilation database for all C/C++ sources in the repo. |
||||||
|
tools/distrib/gen_compilation_database.py \ |
||||||
|
--include_headers \ |
||||||
|
--ignore_system_headers \ |
||||||
|
--dedup_targets \ |
||||||
|
"//:*" \ |
||||||
|
"//src/core/..." \ |
||||||
|
"//src/compiler/..." \ |
||||||
|
"//test/core/..." \ |
||||||
|
"//test/cpp/..." \ |
||||||
|
$MANUAL_TARGETS |
||||||
|
|
||||||
|
# build clang-tidy docker image |
||||||
|
docker build -t grpc_iwyu tools/dockerfile/grpc_iwyu |
||||||
|
|
||||||
|
# run clang-tidy against the checked out codebase |
||||||
|
# when modifying the checked-out files, the current user will be impersonated |
||||||
|
# so that the updated files don't end up being owned by "root". |
||||||
|
docker run \ |
||||||
|
-e TEST="$TEST" \ |
||||||
|
-e CHANGED_FILES="$CHANGED_FILES" \ |
||||||
|
-e IWYU_ROOT="/local-code" \ |
||||||
|
--rm=true \ |
||||||
|
-v "${REPO_ROOT}":/local-code \ |
||||||
|
-v "${HOME/.cache/bazel}":"${HOME/.cache/bazel}" \ |
||||||
|
--user "$(id -u):$(id -g)" \ |
||||||
|
-t grpc_iwyu /iwyu.sh "$@" |
||||||
|
|
@ -0,0 +1,33 @@ |
|||||||
|
# Copyright 2021 gRPC authors. |
||||||
|
# |
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
# you may not use this file except in compliance with the License. |
||||||
|
# You may obtain a copy of the License at |
||||||
|
# |
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
# |
||||||
|
# Unless required by applicable law or agreed to in writing, software |
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
# See the License for the specific language governing permissions and |
||||||
|
# limitations under the License. |
||||||
|
|
||||||
|
FROM debian:bullseye |
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y clang-11 llvm-11-dev libclang-11-dev clang-format-11 jq git cmake python |
||||||
|
|
||||||
|
ENV CLANG_FORMAT=clang-format-11 |
||||||
|
|
||||||
|
RUN git clone https://github.com/include-what-you-use/include-what-you-use.git /iwyu |
||||||
|
# latest commit on the clang 11 branch |
||||||
|
RUN cd /iwyu && git checkout 5db414ac448004fe019871c977905cb7c2cff23f |
||||||
|
|
||||||
|
RUN mkdir /iwyu_build && cd /iwyu_build && cmake -G "Unix Makefiles" -DCMAKE_PREFIX_PATH=/usr/lib/llvm-11 /iwyu && make |
||||||
|
|
||||||
|
ADD iwyu.sh / |
||||||
|
|
||||||
|
# When running locally, we'll be impersonating the current user, so we need |
||||||
|
# to make the script runnable by everyone. |
||||||
|
RUN chmod a+rx /iwyu.sh |
||||||
|
|
||||||
|
CMD ["echo 'Run with tools/distrib/iwyu.sh'"] |
@ -0,0 +1,43 @@ |
|||||||
|
#!/bin/sh |
||||||
|
# Copyright 2017 gRPC authors. |
||||||
|
# |
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
# you may not use this file except in compliance with the License. |
||||||
|
# You may obtain a copy of the License at |
||||||
|
# |
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
# |
||||||
|
# Unless required by applicable law or agreed to in writing, software |
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
# See the License for the specific language governing permissions and |
||||||
|
# limitations under the License. |
||||||
|
|
||||||
|
set -ex |
||||||
|
|
||||||
|
cd ${IWYU_ROOT} |
||||||
|
|
||||||
|
export PATH=${PATH}:/iwyu_build/bin |
||||||
|
|
||||||
|
cat compile_commands.json | sed "s,\"file\": \",\"file\": \"${IWYU_ROOT}/,g" > compile_commands_for_iwyu.json |
||||||
|
|
||||||
|
# figure out which files to include |
||||||
|
cat compile_commands.json | jq -r '.[].file' \ |
||||||
|
| grep -E "^src/core/lib/promise/" \ |
||||||
|
| grep -v -E "/upb-generated/|/upbdefs-generated/" \ |
||||||
|
| sort \ |
||||||
|
| tee iwyu_files.txt |
||||||
|
|
||||||
|
# run iwyu, filtering out changes to port_platform.h |
||||||
|
xargs -a iwyu_files.txt /iwyu/iwyu_tool.py -p compile_commands_for_iwyu.json -j 16 \ |
||||||
|
| grep -v -E "port_platform.h" \ |
||||||
|
| tee iwyu.out |
||||||
|
|
||||||
|
# apply the suggested changes |
||||||
|
/iwyu/fix_includes.py --nocomments < iwyu.out || true |
||||||
|
|
||||||
|
# reformat sources, since iwyu gets this wrong |
||||||
|
xargs -a iwyu_files.txt $CLANG_FORMAT -i |
||||||
|
|
||||||
|
# TODO(ctiller): expand this to match the clang-tidy directories: |
||||||
|
# | grep -E "(^include/|^src/core/|^src/cpp/|^test/core/|^test/cpp/)" |
Loading…
Reference in new issue