commit:     97423cbcc271276d24899f528c879ab011f28d1b
Author:     Matt Jolly <kangie <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 10 10:01:54 2024 +0000
Commit:     Matt Jolly <kangie <AT> gentoo <DOT> org>
CommitDate: Thu Oct 10 10:01:54 2024 +0000
URL:        
https://gitweb.gentoo.org/proj/chromium-tools.git/commit/?id=97423cbc

New script: iterate-over-ebuild.sh

Iterates over a chromium ebuild provided as an argument and
updates `keeplibs` when the build fails.

Signed-off-by: Matt Jolly <kangie <AT> gentoo.org>

 iterate-over-ebuild.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/iterate-over-ebuild.sh b/iterate-over-ebuild.sh
new file mode 100755
index 0000000..5013a45
--- /dev/null
+++ b/iterate-over-ebuild.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+# spdx-license-identifier: GPL-2.0-or-later
+# Script to iterate over `ebuild foo-1.2.3.ebuild clean merge` and 
automatically add values to keeplibs.
+# Usage: ./iterate-over-ebuild.sh foo-1.2.3.ebuild
+# This script will run until the ebuild is merged, or until you interrupt it 
with Ctrl+C.
+# It will add the libraries to keeplibs in the ebuild as it goes.
+
+package="${1%.ebuild}"
+tmpfile=$(mktemp)
+iter=0
+added=()
+
+# Trap for Ctrl+C
+trap 'cleanup' INT
+
+cleanup() {
+  echo "[$(date)]: Script interrupted."
+  echo "$tmpfile" for this iteration\'s logs.
+  exit 1
+}
+
+while true; do
+  libs=()
+  echo "[$(date)]: Processing $package; iteration $((++iter))"
+  echo "So far, we've added:"
+  if [ ${#added[@]} -eq 0 ]; then
+    echo "  Nothing"
+  fi
+  for i in "${added[@]}"; do
+    echo "  $i"
+  done
+  ebuild "${1}" clean merge 2>&1 | tee "$tmpfile"
+
+  # Should only ever be one but whatever
+  mapfile -t libs < <(grep 'ninja: error:' "$tmpfile" | awk '{print $3}' | cut 
-c 8- | awk -F/ '{OFS="/"; NF--; print}')
+
+  if [ ${#libs[@]} -eq 0 ]; then
+    echo "[$(date)]: No new libraries to whitelist."
+  else
+    for lib in "${libs[@]}"; do
+      echo "[$(date)]: Whitelisting $lib"
+      if grep -q "$lib" "${1}"; then
+        # Something went wrong if we're here but whatever.
+        echo "[$(date)]: $lib already exists in keeplibs"
+      else
+        echo "[$(date)]: Adding $lib to keeplibs"
+        sed -i "/^\s*local keeplibs=/a \t\t$lib" "${1}"
+        added+=("$lib")
+      fi
+    done
+  fi
+
+  if grep -q "www-client/$package merged" "$tmpfile"; then
+    rm "$tmpfile"
+    break
+  fi
+  # Start with a clean slate for the next iteration
+  rm "$tmpfile"
+done

Reply via email to