about summary refs log tree commit diff
path: root/maintainers
diff options
context:
space:
mode:
authorAlexei Robyn <shados@shados.net>2019-06-13 20:00:00 +1000
committerAlexei Robyn <shados@shados.net>2019-06-13 20:00:00 +1000
commit46c6b27633637bde724ffddd2bc3c68447bf1fa6 (patch)
treee43569cf7af6012228fcdcc8a459d489ee1ba277 /maintainers
parentb7e6161b4dec02b3280bcde7c30679f95ef278f2 (diff)
downloadnixlib-46c6b27633637bde724ffddd2bc3c68447bf1fa6.tar
nixlib-46c6b27633637bde724ffddd2bc3c68447bf1fa6.tar.gz
nixlib-46c6b27633637bde724ffddd2bc3c68447bf1fa6.tar.bz2
nixlib-46c6b27633637bde724ffddd2bc3c68447bf1fa6.tar.lz
nixlib-46c6b27633637bde724ffddd2bc3c68447bf1fa6.tar.xz
nixlib-46c6b27633637bde724ffddd2bc3c68447bf1fa6.tar.zst
nixlib-46c6b27633637bde724ffddd2bc3c68447bf1fa6.zip
update-luarocks: Several improvements
Changes:
- Fetches rocks and builds Nix expressions for them in parallel
- Passes 'maintainers' list to luarocks-nix
- Constructs the luarocks argument list more cleanly, by using an
  indexed array
- Made indentation consistent
Diffstat (limited to 'maintainers')
-rwxr-xr-xmaintainers/scripts/update-luarocks-packages100
1 files changed, 58 insertions, 42 deletions
diff --git a/maintainers/scripts/update-luarocks-packages b/maintainers/scripts/update-luarocks-packages
index e2f2cc6bbd2e..b553286affad 100755
--- a/maintainers/scripts/update-luarocks-packages
+++ b/maintainers/scripts/update-luarocks-packages
@@ -1,5 +1,5 @@
 #!/usr/bin/env nix-shell
-#!nix-shell -p nix-prefetch-scripts luarocks-nix -i bash
+#!nix-shell -p parallel nix-prefetch-scripts luarocks-nix -i bash
 
 # You'll likely want to use
 # ``
@@ -8,17 +8,15 @@
 # to update all libraries in that folder.
 # to debug, redirect stderr to stdout with 2>&1
 
-
 # stop the script upon C-C
 set -eu -o pipefail
 
 CSV_FILE="maintainers/scripts/luarocks-packages.csv"
 TMP_FILE="$(mktemp)"
 
-exit_trap()
-{
-  local lc="$BASH_COMMAND" rc=$?
-  test $rc -eq 0 || echo -e "*** error $rc: $lc.\nGenerated temporary file in $TMP_FILE" >&2
+exit_trap() {
+    local lc="$BASH_COMMAND" rc=$?
+    test $rc -eq 0 || echo -e "*** error $rc: $lc.\nGenerated temporary file in $TMP_FILE" >&2
 }
 
 print_help() {
@@ -37,19 +35,19 @@ fi
 trap exit_trap EXIT
 
 while getopts ":hc:" opt; do
-  case $opt in
+    case $opt in
     h)
-      print_help
-      ;;
+        print_help
+        ;;
     c)
-      echo "Loading package list from $OPTARG !" >&2
-      CSV_FILE="$OPTARG"
-      ;;
+        echo "Loading package list from $OPTARG !" >&2
+        CSV_FILE="$OPTARG"
+        ;;
     \?)
-      echo "Invalid option: -$OPTARG" >&2
-      ;;
-  esac
-  shift $((OPTIND-1))
+        echo "Invalid option: -$OPTARG" >&2
+        ;;
+    esac
+    shift $((OPTIND - 1))
 done
 
 GENERATED_NIXFILE="$1"
@@ -72,43 +70,61 @@ FOOTER="
 /* GENERATED */
 "
 
-
-function convert_pkg () {
+function convert_pkg() {
     nix_pkg_name="$1"
     lua_pkg_name="$2"
-    server="${3:+--only-server=$3}"
-    pkg_version="${4:-}"
-    lua_version="${5:+--lua-dir=$(nix path-info nixpkgs.$5)/bin}"
-
-    echo "looking at $lua_pkg_name (version $pkg_version) from server [$server]" >&2
-    cmd="luarocks nix $server $lua_version $lua_pkg_name $pkg_version"
-    echo "Running $cmd" >&2
-    drv="$nix_pkg_name = $($cmd)"
-    if [ $? -ne 0 ]; then
-        echo "Failed to convert $pkg" >&2
+    server="$3"
+    pkg_version="$4"
+    lua_version="$5"
+    maintainers="$6"
+
+    if [ "${nix_pkg_name:0:1}" == "#" ]; then
+        echo "Skipping comment ${*}" >&2
+        return
+    fi
+    if [ -z "$lua_pkg_name" ]; then
+        echo "Using nix_name as lua_pkg_name for '$nix_pkg_name'" >&2
+        lua_pkg_name="$nix_pkg_name"
+    fi
+
+    echo "Building expression for $lua_pkg_name (version $pkg_version) from server [$server]" >&2
+    luarocks_args=(nix)
+    if [[ -n $server ]]; then
+        luarocks_args+=("--only-server=$server")
+    fi
+    if [[ -n $maintainers ]]; then
+        luarocks_args+=("--maintainers=$maintainers")
+    fi
+    if [[ -n $lua_version ]]; then
+        luarocks_args+=("--lua-dir=$(nix path-info "nixpkgs.$lua_version")/bin")
+    fi
+    luarocks_args+=("$lua_pkg_name")
+    if [[ -n $pkg_version ]]; then
+        luarocks_args+=("$pkg_version")
+    fi
+    echo "Running 'luarocks ${luarocks_args[*]}'" >&2
+    if drv="$nix_pkg_name = $(luarocks "${luarocks_args[@]}")"; then
+        # echo "$drv" | tee -a "$TMP_FILE"
+        echo "$drv"
     else
-        echo "$drv" | tee -a "$TMP_FILE"
+        echo "Failed to convert $nix_pkg_name" >&2
+        return 1
     fi
 }
 
 # params needed when called via callPackage
 echo "$HEADER" | tee "$TMP_FILE"
 
-# list of packages with format
-while IFS=, read -r nix_pkg_name lua_pkg_name server pkg_version luaversion
-do
-    if [ "${nix_pkg_name:0:1}" == "#" ]; then
-        echo "Skipping comment ${nix_pkg_name}" >&2
-        continue
-    fi
-    if [ -z "$lua_pkg_name" ]; then
-        echo "Using nix_name as lua_pkg_name" >&2
-        lua_pkg_name="$nix_pkg_name"
-    fi
-    convert_pkg "$nix_pkg_name" "$lua_pkg_name" "$server" "$pkg_version" "$luaversion"
-done < "$CSV_FILE"
+export -f convert_pkg
+export SHELL=bash
+# Read each line in the csv file and run convert_pkg for each, in parallel
+# 10 is a pretty arbitrary number of simultaneous jobs, but it is generally
+# impolite to hit a webserver with *too* many simultaneous connections :)
+parallel --group --keep-order --halt now,fail=1 --jobs 10 --colsep ',' convert_pkg {} <"$CSV_FILE" | tee -a "$TMP_FILE"
 
 # close the set
 echo "$FOOTER" | tee -a "$TMP_FILE"
 
 cp "$TMP_FILE" "$GENERATED_NIXFILE"
+
+# vim: set ts=4 sw=4 ft=sh: