Add logic to re-downloading packages in reorder step if some packages is missed! 39/279039/1
authorbiao716.wang <biao716.wang@samsung.com>
Mon, 1 Aug 2022 02:22:13 +0000 (11:22 +0900)
committerbiao716.wang <biao716.wang@samsung.com>
Mon, 1 Aug 2022 02:22:17 +0000 (11:22 +0900)
https://github.sec.samsung.net/RS-tizen-build/issues/issues/920

Change-Id: I4ca5d1515ecb9d0e1e89e70242e4ccf690e9b445
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
init_buildsystem
order

index 6876514380618d548ef4d665875bde50e74084ee..dfab8e34f4ef83ed2733404b48af74bb9e943215 100755 (executable)
@@ -270,15 +270,6 @@ run_pkg_scripts() {
     done
 }
 
-reorder() {
-    test -z "$*" && return
-    rm -f "$BUILD_ROOT"/.init_b_cache/order.manifest
-    for PKG in "$@" ; do
-       echo "$PKG" >> "$BUILD_ROOT"/.init_b_cache/order.manifest
-    done
-    $BUILD_DIR/order --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir $CONFIG_DIR --manifest "$BUILD_ROOT"/.init_b_cache/order.manifest "$BUILD_ROOT"/.init_b_cache/rpms || touch "$BUILD_ROOT"/exit
-    rm -f "$BUILD_ROOT"/.init_b_cache/order.manifest
-}
 
 create_devs() {
     local com file mode arg
@@ -445,7 +436,9 @@ downloadpkg() {
 
     local destdir="$cachedir/tmp_$$"
     mkdir -p "$destdir"
-    echo "downloading $url ... ";
+    if [ ! -f "$BUILD_ROOT"/exit ] ; then
+        echo "downloading $url ... ";
+    fi
     $BUILD_DIR/download "$destdir" "$url" || cleanup_and_exit 1
     local destfile="$destdir/${url##*/}"
     if test ! -e "$destfile" ; then
@@ -468,6 +461,61 @@ downloadpkg() {
     rm -rf $destdir
 }
 
+reorder() {
+    test -z "$*" && return
+    rm -f "$BUILD_ROOT"/.init_b_cache/order.manifest
+    for PKG in "$@" ; do
+       echo "$PKG" >> "$BUILD_ROOT"/.init_b_cache/order.manifest
+    done
+
+    #NOTICE: in reorder, you can't print any logs, or it will treate the logs as pacakges outside
+    #Change: If reorder failed because of missing packages, add logic to re-download the missed packages.
+    touch "$BUILD_ROOT"/missedPKG
+    echo "" > "$BUILD_ROOT"/missedPKG
+    while true
+    do
+       #remove exit file, it will create exit file if reorder fail.
+       rm -f "$BUILD_ROOT"/exit
+       #call order operation
+        $BUILD_DIR/order --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir $CONFIG_DIR --manifest "$BUILD_ROOT"/.init_b_cache/order.manifest "$BUILD_ROOT"/.init_b_cache/rpms "$BUILD_ROOT"/missedPKG || touch "$BUILD_ROOT"/exit
+
+       #order operation OK, exit reorder funciton
+       if [ ! -f "$BUILD_ROOT"/exit ]; then
+           #after reorder again, if reorder is normal, should delete tmp file.
+           rm -f "$BUILD_ROOT"/missedPKG
+           rm -f "$BUILD_ROOT"/.init_b_cache/rpmlist_reorder_check.download
+           break
+       fi
+        #order operation failed!
+       if [ -f "$BUILD_ROOT"/exit ]; then
+           #fail reason: binary not found. To try to download packages again.
+           if test -s "$BUILD_ROOT"/missedPKG; then
+                for line in `cat "$BUILD_ROOT"/missedPKG`; do
+                   while read PKG SRC; do
+                       if [ "$PKG" = "$line" ]; then
+                           downloadpkg "$SRC"
+                            # downloadpkg missed packages
+                            SRCSUF=${SRC/%.pkg.tar.?z/.arch}
+                           #remove the soft link that already existed.
+                           rm -f "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRCSUF##*.}"
+                            ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRCSUF##*.}"
+                           break
+                       fi
+                   done < "$BUILD_ROOT"/.init_b_cache/rpmlist_reorder_check.download
+               done
+               #clear file. use it next loop if needed.
+               echo "" > "$BUILD_ROOT"/missedPKG
+           #Other fail reason. Exit!
+           else
+               rm -f "$BUILD_ROOT"/missedPKG
+                rm -f "$BUILD_ROOT"/.init_b_cache/rpmlist_reorder_check.download
+               break
+           fi
+       fi
+    done
+    rm -f "$BUILD_ROOT"/.init_b_cache/order.manifest
+}
+
 getcachedir() {
     local url=$1
     for repo in "${repos[@]}" ; do
@@ -838,6 +886,7 @@ else
            SRCSUF=${SRCSUF/%.pkg.tar.?z/.arch}
            ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRCSUF##*.}"
         done < "$BUILD_ROOT"/.init_b_cache/rpmlist.download
+       cp "$BUILD_ROOT"/.init_b_cache/rpmlist.download "$BUILD_ROOT"/.init_b_cache/rpmlist_reorder_check.download
         rm -f "$BUILD_ROOT"/.init_b_cache/rpmlist.download
         echo
     fi
@@ -973,7 +1022,7 @@ if ! test -e "$BUILD_ROOT"/.build/init_buildsystem.data ; then
     echo -n 'reordering...'
     PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL`
     check_exit
-    echo 'done'
+    echo 'reordering done'
 fi
 
 #
diff --git a/order b/order
index a3c9d8e71994cec4facf4e0c2e675995d46b8d41..398c8ab063ab38a9767fd360e742f9f52b46abc8 100755 (executable)
--- a/order
+++ b/order
@@ -57,7 +57,7 @@ while (@ARGV)  {
 
 die("usage: order [--manifest manifest] cachedir [packages...]\n") unless @ARGV;
 my $cachedir = shift @ARGV;
-
+my $missedpkgfile = shift @ARGV;
 my @p;
 if ($manifest) {
   if ($manifest eq '-') {
@@ -92,7 +92,12 @@ for my $p (@p) {
     delete $q->{'filelist'};
     last;
   }
-  die("binary not found: $p\n") unless $q;
+  unless ($q)  {
+    open(MISS, ">$missedpkgfile");
+    print MISS "$p";
+    close(MISS);
+    die("binary not found: $p, try to download it again!\n");
+  }
   $deps{$p} = $q;
 }