[gjs/iwyu-job: 6/8] CI: Fix exit code of IWYU script
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/iwyu-job: 6/8] CI: Fix exit code of IWYU script
- Date: Wed, 3 Jun 2020 22:50:19 +0000 (UTC)
commit d38db7f29e585acbd2b344333179bbfd2e2fa45b
Author: Philip Chimento <philip chimento gmail com>
Date: Wed Jun 3 14:29:03 2020 -0700
CI: Fix exit code of IWYU script
When this was mainly being run manually, the exit code didn't matter
much since the main thing was to look at the output. Running in CI, it
does matter, so make sure it is correct everywhere.
tools/process_iwyu.py | 7 ++++-
tools/run_iwyu.sh | 80 +++++++++++++++++++++++++++++++++++----------------
2 files changed, 61 insertions(+), 26 deletions(-)
---
diff --git a/tools/process_iwyu.py b/tools/process_iwyu.py
index f91778a2..dd6656b2 100755
--- a/tools/process_iwyu.py
+++ b/tools/process_iwyu.py
@@ -22,6 +22,7 @@ file = None
add = {}
remove = {}
all_includes = {}
+there_were_errors = False
# When encountering one of these lines, move to a different state
MATCHERS = {
@@ -69,7 +70,7 @@ FALSE_POSITIVES = (
def output():
- global file, state, add_fwd_header
+ global file, state, add_fwd_header, there_were_errors
if add_fwd_header:
if FWD_HEADER not in all_includes:
@@ -88,6 +89,7 @@ def output():
if why:
why = ' // ' + why
print(f'{Colors.RED}-{line}{Colors.NORMAL}{why}')
+ there_were_errors = True
state = None
file = None
@@ -143,3 +145,6 @@ for line in sys.stdin:
remove[line] = why
elif state == FULL:
all_includes[line] = why
+
+if there_were_errors:
+ sys.exit(1)
diff --git a/tools/run_iwyu.sh b/tools/run_iwyu.sh
index 0ff6a5e1..f46d807c 100755
--- a/tools/run_iwyu.sh
+++ b/tools/run_iwyu.sh
@@ -44,6 +44,7 @@ IWYU="python3 $(which iwyu_tool) -p ."
PRIVATE_MAPPING="-Xiwyu --mapping_file=$SRCDIR/tools/gjs-private-iwyu.imp -Xiwyu --keep=config.h"
PUBLIC_MAPPING="-Xiwyu --mapping_file=$SRCDIR/tools/gjs-public-iwyu.imp"
POSTPROCESS="python3 $SRCDIR/tools/process_iwyu.py"
+EXIT=0
for FILE in $SRCDIR/gi/*.cpp $SRCDIR/gjs/atoms.cpp $SRCDIR/gjs/byteArray.cpp \
$SRCDIR/gjs/coverage.cpp $SRCDIR/gjs/debugger.cpp \
@@ -55,40 +56,69 @@ 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
- should_analyze $FILE && $IWYU $FILE -- $PRIVATE_MAPPING | $POSTPROCESS
+ if should_analyze $FILE; then
+ if ! $IWYU $FILE -- $PRIVATE_MAPPING | $POSTPROCESS; then
+ EXIT=1
+ fi
+ fi
done
-should_analyze $SRCDIR/gjs/context.cpp && \
-$IWYU $SRCDIR/gjs/context.cpp -- $PRIVATE_MAPPING \
- -Xiwyu --check_also=*/gjs/context-private.h | $POSTPROCESS
+if should_analyze $SRCDIR/gjs/context.cpp; then
+ if ! $IWYU $SRCDIR/gjs/context.cpp -- $PRIVATE_MAPPING \
+ -Xiwyu --check_also=*/gjs/context-private.h | $POSTPROCESS; then
+ EXIT=1
+ fi
+fi
-( 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
+if ( should_analyze $SRCDIR/gjs/jsapi-dynamic-class.cpp || \
+ should_analyze $SRCDIR/gjs/jsapi-class.h ); then
+ if ! $IWYU $SRCDIR/gjs/jsapi-dynamic-class.cpp -- $PRIVATE_MAPPING \
+ -Xiwyu --check_also=*/gjs/jsapi-class.h | $POSTPROCESS; then
+ EXIT=1
+ fi
+fi
-( should_analyze $SRCDIR/gjs/jsapi-util.cpp ||
+if ( 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/jsapi-util-root.h ); then
+ if ! $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; then
+ EXIT=1
+ fi
+fi
-should_analyze $SRCDIR/gjs/mem.cpp && \
-$IWYU $SRCDIR/gjs/mem.cpp -- $PRIVATE_MAPPING \
- -Xiwyu --check_also=*/gjs/mem-private.h | $POSTPROCESS
+if should_analyze $SRCDIR/gjs/mem.cpp; then
+ if ! $IWYU $SRCDIR/gjs/mem.cpp -- $PRIVATE_MAPPING \
+ -Xiwyu --check_also=*/gjs/mem-private.h | $POSTPROCESS; then
+ EXIT=1
+ fi
+fi
-should_analyze $SRCDIR/gjs/profiler.cpp && \
-$IWYU $SRCDIR/gjs/profiler.cpp -- $PRIVATE_MAPPING \
- -Xiwyu --check_also=*/gjs/profiler-private.h | $POSTPROCESS
+if should_analyze $SRCDIR/gjs/profiler.cpp; then
+ if ! $IWYU $SRCDIR/gjs/profiler.cpp -- $PRIVATE_MAPPING \
+ -Xiwyu --check_also=*/gjs/profiler-private.h | $POSTPROCESS; then
+ EXIT=1
+ fi
+fi
-( 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
+if ( should_analyze $SRCDIR/modules/cairo.cpp ||
+ should_analyze $SRCDIR/modules/cairo-module.h ); then
+ if ! $IWYU $SRCDIR/modules/cairo.cpp -- $PRIVATE_MAPPING \
+ -Xiwyu --check_also=*/modules/cairo-module.h \
+ -Xiwyu --check_also=*/modules/cairo-private.h | $POSTPROCESS; then
+ EXIT=1
+ fi
+fi
for FILE in $SRCDIR/gjs/console.cpp $SRCDIR/installed-tests/minijasmine.cpp
do
- should_analyze $FILE && $IWYU $FILE -- $PUBLIC_MAPPING | $POSTPROCESS
+ if should_analyze $FILE; then
+ if ! $IWYU $FILE -- $PUBLIC_MAPPING | $POSTPROCESS; then
+ EXIT=1
+ fi
+ fi
done
+
+if test $EXIT -eq 0; then echo "No changes needed."; fi
+exit $EXIT
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]