From 105ddf81f79541b35b67dfa363822ec0a4b4332f Mon Sep 17 00:00:00 2001
From: Filippo Cremonese <filippocremonese@rev.ng>
Date: Fri, 16 Oct 2020 15:24:49 +0200
Subject: [PATCH] More robust handling of build-only components cleanup

---
 .gitlab-ci.yml                                |  2 ++
 .../config/components/revng_distributable.yml | 21 ++++++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f594159..359ad95 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -40,7 +40,9 @@ create-binaries:
 
       EOF
     - orchestra update --no-config
+    # Print graph and component list to aid debugging
     - orchestra -b graph revng-distributable
+    - orchestra -b components --hashes --deps
     - orchestra -b install --create-binary-archives revng-distributable
     - cd .orchestra/binary-archives/personal
     - git config user.email "gitlabci@rev.ng"
diff --git a/.orchestra/config/components/revng_distributable.yml b/.orchestra/config/components/revng_distributable.yml
index 8fa5606..552b4bc 100644
--- a/.orchestra/config/components/revng_distributable.yml
+++ b/.orchestra/config/components/revng_distributable.yml
@@ -30,11 +30,22 @@ install: |
   cd root
 
   echo "Removing build-only components"
-  cat "share/orchestra/glibc.idx" | xargs -n1000 rm -f
-  cat "share/orchestra/boost.idx" | xargs -n1000 rm -f
-  cat "share/orchestra/toolchain_host_binutils.idx" | xargs -n1000 rm -f
-  cat "share/orchestra/toolchain_host_gcc.idx" | grep -v libgcc_s.so | xargs -n1000 rm -f
-  cat "share/orchestra/clang-release.idx" | grep -v 'libc++.so' | grep -v 'libc++abi.so' | xargs -n1000 rm -f
+  index_files=(
+    "share/orchestra/glibc.idx"
+    "share/orchestra/boost.idx"
+    "share/orchestra/toolchain_host_binutils.idx"
+    "share/orchestra/toolchain_host_gcc.idx"
+    "share/orchestra/clang-release.idx"
+  )
+  for index_file in $index_files; do
+    if [ -e "$index_file" ]; then
+      cat "$index_file" | \
+        grep -v libgcc_s.so | \
+        grep -v 'libc++.so' | \
+        grep -v 'libc++abi.so' | \
+        xargs -n1000 rm -f
+    fi
+  done
 
   echo "Stripping components"
   find "share/orchestra" -name "*.idx" -type f | grep -vE 'revng|caliban'| xargs cat | while read EXECUTABLE; do
-- 
GitLab