[gjs/iwyu-job] fix



commit 601b5ec16a6583f01027439d0a6dd38efaf57e99
Author: Philip Chimento <philip chimento gmail com>
Date:   Wed Jun 3 12:01:50 2020 -0700

    fix

 .gitlab-ci.yml        |  2 +-
 tools/process_iwyu.py |  7 +++-
 tools/run_iwyu.sh     | 90 +++++++++++++++++++++++++++++++++++----------------
 3 files changed, 69 insertions(+), 30 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 22d228c5..b34b6d97 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -193,7 +193,7 @@ iwyu:
   stage: source_check
   image: registry.gitlab.gnome.org/ptomato/gjs:fedora.mozjs68-debug
   script:
-    - ./tools/run_iwyu.sh master
+    - ./tools/run_iwyu.sh origin/master
   only:
     - branches
     - merge_requests
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 e718f31d..0217f4ce 100755
--- a/tools/run_iwyu.sh
+++ b/tools/run_iwyu.sh
@@ -14,11 +14,12 @@ fi
 if [ $# -eq 0 ]; then
     files=all
 else
+    # make stat changes not show up as modifications
+    git update-index -q --really-refresh
+
     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
@@ -37,10 +38,14 @@ if ! meson setup _build; then
 fi
 cd ${BUILDDIR:-_build}
 
-IWYU="iwyu_tool -p ."
+git diff-index HEAD
+echo "files: $files"
+
+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 \
@@ -52,40 +57,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]