Add '--max-retry-times' to support rebuild if build failed. sandbox/xuwc/max_retry_times
authorwanchao.xu <wanchao.xu@samsung.com>
Wed, 4 Dec 2024 08:39:53 +0000 (16:39 +0800)
committerwanchao.xu <wanchao.xu@samsung.com>
Tue, 10 Dec 2024 03:07:35 +0000 (11:07 +0800)
* If build failed because of qemu crash, support to retry rebuild.

Change-Id: I9591e659a464d4c599b1fc29c36cfde9de4219b5
Signed-off-by: wanchao.xu <wanchao.xu@samsung.com>
build

diff --git a/build b/build
index ec07d23288c24ff16fd7ee6a4411f6b4b762e73d..ca14b799f892c80b82b18d6478a2a5bae4197ffe 100644 (file)
--- a/build
+++ b/build
@@ -103,6 +103,7 @@ USEHIGHERDEPS=
 PKG_CCACHE=
 CCACHE_SETUP_START_TIME=
 NOCUMULATE=
+MAX_RETRY_TIMES=0
 
 # This is for insserv
 export YAST_IS_RUNNING=instsys
@@ -357,6 +358,8 @@ Known Parameters:
               Enable creation of a debuginfo package
   --nocumulate
               Enable build without cumulative build.
+  --max-retry-times N
+              Retry N times to rebuild if build failed.
 
 Remember to have fun!
 
@@ -744,6 +747,21 @@ hide_passwords()
 #    echo ${repos[@]}
 }
 
+retry_build_or_not()
+{
+    if test -n "$LOGFILE"; then
+        build_log="$LOGFILE"
+    else
+        build_log="$BUILD_ROOT/.build.log";
+    fi
+    if test -f "$build_log"; then
+        if grep -q "qemu: uncaught target signal" $build_log; then
+            return 0
+        fi
+    fi
+    return 1
+}
+
 #### main ####
 
 trap fail_exit EXIT
@@ -1004,6 +1022,11 @@ while test -n "$1"; do
          -use-higher-deps)
        USEHIGHERDEPS="--use-higher-deps"
          ;;
+      -max-retry-times)
+       needarg
+       MAX_RETRY_TIMES="$ARG"
+       shift
+      ;;
       -*)
        if vm_parse_options "$@" ; then
            set -- "${nextargs[@]}"
@@ -1470,6 +1493,17 @@ for RECIPEFILE in "${RECIPEFILES[@]}" ; do
 
     start_time=`date +%s`
     recipe_build
+    if test "$BUILD_SUCCEEDED" = false -a "$MAX_RETRY_TIMES" -gt 0; then
+        for ((num=0; num<$MAX_RETRY_TIMES; num++)) ; do
+            if retry_build_or_not ; then
+                echo ----- retrying to build $RECIPEFILE
+                recipe_build
+            else
+                break
+            fi
+            test "$BUILD_SUCCEEDED" = true && break
+        done
+    fi
     if test "$DO_STATISTICS" = 1; then
         mkdir -p $TOPDIR/OTHER
         echo "TIME_main_build: $(( `date +%s` - $start_time ))"  >> $TOPDIR/OTHER/_statistics