summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2020-05-16 11:44:19 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2020-05-20 22:41:26 -0700
commit50a6812079243399b2b3f5936ed0a549a83a75b4 (patch)
tree8a8d0683e785ad79f3bec1d7b7a3f1847825f203 /tools
parentabc7683e4a75c51ac67f00783d5ff34e8e00e938 (diff)
downloadgjs-50a6812079243399b2b3f5936ed0a549a83a75b4.tar.gz
build: Add some smarts to IWYU script
If passing a commit to tools/run_iwyu.sh, check only the files changed in that commit or later, including uncommitted files. This allows running IWYU with much less friction and opens the door to running it automatically in CI.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/run_iwyu.sh49
1 files changed, 47 insertions, 2 deletions
diff --git a/tools/run_iwyu.sh b/tools/run_iwyu.sh
index 5773289f..e67f4818 100755
--- a/tools/run_iwyu.sh
+++ b/tools/run_iwyu.sh
@@ -2,6 +2,35 @@
SRCDIR=$(pwd)
+if [ "$1" == '--help' -o "$1" == '-h' ]; then
+ echo "usage: $0 [ COMMIT ]"
+ echo "Run include-what-you-use on the GJS codebase."
+ echo "If COMMIT is given, analyze only the files changed since that commit,"
+ echo "including uncommitted changes."
+ echo "Otherwise, analyze all files."
+ exit 0
+fi
+
+if [ $# -eq 0 ]; then
+ files=all
+else
+ files="$(git diff-tree --name-only -r $1..) $(git diff-index --name-only HEAD)"
+fi
+
+echo "files: $files"
+
+should_analyze () {
+ file=$(realpath --relative-to=$SRCDIR $1)
+ case "$files" in
+ all) return 0 ;;
+ *$file*) return 0 ;;
+ *${file%.cpp}.h*) return 0 ;;
+ *${file%.cpp}-private.h*) return 0 ;;
+ *${file%.c}.h*) return 0 ;;
+ *) return 1 ;;
+ esac
+}
+
cd ${BUILDDIR:-_build}
if ! ninja; then
echo 'Build failed.'
@@ -23,24 +52,40 @@ for FILE in $SRCDIR/gi/*.cpp $SRCDIR/gjs/atoms.cpp $SRCDIR/gjs/byteArray.cpp \
$SRCDIR/modules/system.cpp $SRCDIR/test/*.cpp $SRCDIR/util/*.cpp \
$SRCDIR/libgjs-private/*.c
do
- $IWYU $FILE -- $PRIVATE_MAPPING | $POSTPROCESS
+ should_analyze $FILE && $IWYU $FILE -- $PRIVATE_MAPPING | $POSTPROCESS
done
+
+should_analyze $SRCDIR/gjs/context.cpp && \
$IWYU $SRCDIR/gjs/context.cpp -- $PRIVATE_MAPPING \
-Xiwyu --check_also=*/gjs/context-private.h | $POSTPROCESS
+
+( should_analyze $SRCDIR/gjs/jsapi-dynamic-class.cpp || \
+ should_analyze $SRCDIR/gjs/jsapi-class.h ) && \
$IWYU $SRCDIR/gjs/jsapi-dynamic-class.cpp -- $PRIVATE_MAPPING \
-Xiwyu --check_also=*/gjs/jsapi-class.h | $POSTPROCESS
+
+( should_analyze $SRCDIR/gjs/jsapi-util.cpp ||
+ should_analyze $SRCDIR/gjs/jsapi-util-args.h || \
+ should_analyze $SRCDIR/gjs/jsapi-util-root.h ) && \
$IWYU $SRCDIR/gjs/jsapi-util.cpp -- $PRIVATE_MAPPING \
-Xiwyu --check_also=*/gjs/jsapi-util-args.h \
-Xiwyu --check_also=*/gjs/jsapi-util-root.h | $POSTPROCESS
+
+should_analyze $SRCDIR/gjs/mem.cpp && \
$IWYU $SRCDIR/gjs/mem.cpp -- $PRIVATE_MAPPING \
-Xiwyu --check_also=*/gjs/mem-private.h | $POSTPROCESS
+
+should_analyze $SRCDIR/gjs/profiler.cpp && \
$IWYU $SRCDIR/gjs/profiler.cpp -- $PRIVATE_MAPPING \
-Xiwyu --check_also=*/gjs/profiler-private.h | $POSTPROCESS
+
+( should_analyze $SRCDIR/modules/cairo.cpp ||
+ should_analyze $SRCDIR/modules/cairo-module.h ) && \
$IWYU $SRCDIR/modules/cairo.cpp -- $PRIVATE_MAPPING \
-Xiwyu --check_also=*/modules/cairo-module.h \
-Xiwyu --check_also=*/modules/cairo-private.h | $POSTPROCESS
for FILE in $SRCDIR/gjs/console.cpp $SRCDIR/installed-tests/minijasmine.cpp
do
- $IWYU $FILE -- $PUBLIC_MAPPING | $POSTPROCESS
+ should_analyze $FILE && $IWYU $FILE -- $PUBLIC_MAPPING | $POSTPROCESS
done