Add an apply-include-cleaner tool

Since iwyu is now deprecated, we need to enable use of include-cleaner.
This approach gives some error messages when running, but does the job.

Bug: webrtc:15874
Change-Id: I431deef0f2e5ce99eb256a4d82aa32769ae58b41
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/347642
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42085}
This commit is contained in:
Harald Alvestrand 2024-04-16 12:34:13 +00:00 committed by WebRTC LUCI CQ
parent 525df59762
commit 3997df3f28
3 changed files with 88 additions and 0 deletions

View File

@ -76,6 +76,7 @@ if (!build_with_chromium) {
]
deps = [
":enable_media",
":field_trials_view",
":libjingle_peerconnection_api",
":scoped_refptr",
"../api/rtc_event_log:rtc_event_log_factory",
@ -84,6 +85,7 @@ if (!build_with_chromium) {
"../pc:peer_connection_factory",
"../pc:webrtc_sdp",
"../rtc_base:threading",
"../rtc_base/system:rtc_export",
"../stats:rtc_stats",
"audio:audio_mixer_api",
"audio_codecs:audio_codecs_api",

View File

@ -16,10 +16,12 @@
#include "api/audio/audio_mixer.h"
#include "api/audio_codecs/audio_decoder_factory.h"
#include "api/audio_codecs/audio_encoder_factory.h"
#include "api/field_trials_view.h"
#include "api/peer_connection_interface.h"
#include "api/scoped_refptr.h"
#include "api/video_codecs/video_decoder_factory.h"
#include "api/video_codecs/video_encoder_factory.h"
#include "rtc_base/system/rtc_export.h"
namespace rtc {
// TODO(bugs.webrtc.org/9987): Move rtc::Thread to api/ or expose a better

View File

@ -0,0 +1,84 @@
#!/usr/bin/env bash
#
# Run the include-cleaner tool (iwyu replacement) on a file in the webrtc source
# directory.
#
#
# In order to handle include paths correctly, you need to provide
# a compile DB (aka compile_commands.json).
# You can create it in one of the following ways:
# "gn gen --export-compile-commands path/to/out"
# "tools/clang/scripts/generate_compdb.py -p path/to/out > compile_commands.json"
# If "out/Default" exists, the script will attempt to generate it for you.
#
# To get include-cleaner:
# - in google3: define an alias and/or point to it below
# - in debian distros: sudo apt install clang-tools-17 (or later, and fix below)
# Ignore errors of the type "this argument doesn't exist".
CLEANER=/usr/bin/clang-include-cleaner-17
# Debug level, also controlled by the "-d" argument.
# Set this to 1 to get more debug information.
# Set this to 2 to also get a dump of the iwyu tool output.
DEBUG=0
set -e
if [ $DEBUG -gt 0 ]; then
set -x
fi
error() {
echo "$*" >&2
exit 1
}
WORKDIR=out/Default
usage() {
echo "Usage: $0 [ -c compile-commands-file.json ] [-r] file.cc"
echo "Runs the include-cleaner tool on a file"
echo "Arguments:"
echo " -n : just print changes, don't do them"
echo " -r : Remove non-required includes from .h file"
echo " -d <n> : Set debug level to <n>"
echo " -h : Print this help message"
}
COMMAND=" --edit"
INCLUDE_ARGS=""
while getopts 'd:rnh' opts; do
case "${opts}" in
n) COMMAND=" --print=changes" ;;
r) INCLUDE_ARGS=" --remove" ;;
d) DEBUG=${OPTARG};if [ $DEBUG -gt 0 ]; then set -x; fi ;;
h) usage; exit 1 ;;
*) error "Unexpected option ${opts}" ;;
esac
done
shift $(expr $OPTIND - 1 )
if [[ -z "$COMPILE_COMMANDS" ]]; then
if [ -d "$WORKDIR" ]; then
if [ ! -f "$WORKDIR/compile_commands.json" ]; then
echo "Generating compile commands file"
gn gen --export-compile-commands $WORKDIR
fi
COMPILE_COMMANDS="$WORKDIR/compile_commands.json"
else
error "Could not generate $WORKDIR/compile_commands.json."
fi
fi
FILE="$1"
if [ ! -f $FILE ]; then
error "File $FILE is not found"
fi
cd $WORKDIR
$CLEANER $INCLUDE_ARGS $COMMAND ../../$FILE
echo "Finished. Check diff, compile, gn gen --check and git cl format"
echo "before uploading."