1#!/bin/bash 2# Copyright 2021 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 16echo "NOTE: to automagically apply fixes, invoke with --fix" 17 18set -ex 19 20# change to root directory 21cd $(dirname $0)/../.. 22REPO_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 26export 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. 29tools/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 "//fuzztest/..." \ 39 $MANUAL_TARGETS 40 41# run iwyu against the checked out codebase 42# when modifying the checked-out files, the current user will be impersonated 43# so that the updated files don't end up being owned by "root". 44if [ "$IWYU_SKIP_DOCKER" == "" ] 45then 46 # build iwyu docker image 47 docker build -t grpc_iwyu tools/dockerfile/grpc_iwyu 48 49 docker run \ 50 -e TEST="$TEST" \ 51 -e CHANGED_FILES="$CHANGED_FILES" \ 52 -e IWYU_ROOT="/local-code" \ 53 --rm=true \ 54 -v "${REPO_ROOT}":/local-code \ 55 -v "${HOME/.cache/bazel}":"${HOME/.cache/bazel}" \ 56 --user "$(id -u):$(id -g)" \ 57 -t grpc_iwyu /iwyu.sh "$@" 58else 59 IWYU_ROOT="${REPO_ROOT}" tools/dockerfile/grpc_iwyu/iwyu.sh 60fi 61