summary refs log tree commit diff
path: root/pkgs/common-updater
diff options
context:
space:
mode:
authortaku0 <mxxouy6x3m_github@tatapa.org>2018-03-14 23:24:34 +0900
committertaku0 <mxxouy6x3m_github@tatapa.org>2018-03-16 23:17:07 +0900
commit186de9ca9ef5650180f2f0cf0a9efdc7dfb16e2e (patch)
tree98702edd9838c25a0d1a1d53a6ba914e0399ec66 /pkgs/common-updater
parentcb51341d122d4c22ae180844025e071ab0b8fed5 (diff)
downloadnixpkgs-186de9ca9ef5650180f2f0cf0a9efdc7dfb16e2e.tar
nixpkgs-186de9ca9ef5650180f2f0cf0a9efdc7dfb16e2e.tar.gz
nixpkgs-186de9ca9ef5650180f2f0cf0a9efdc7dfb16e2e.tar.bz2
nixpkgs-186de9ca9ef5650180f2f0cf0a9efdc7dfb16e2e.tar.lz
nixpkgs-186de9ca9ef5650180f2f0cf0a9efdc7dfb16e2e.tar.xz
nixpkgs-186de9ca9ef5650180f2f0cf0a9efdc7dfb16e2e.tar.zst
nixpkgs-186de9ca9ef5650180f2f0cf0a9efdc7dfb16e2e.zip
common-updater: support updating source URL
Diffstat (limited to 'pkgs/common-updater')
-rwxr-xr-xpkgs/common-updater/scripts/update-source-version21
1 files changed, 19 insertions, 2 deletions
diff --git a/pkgs/common-updater/scripts/update-source-version b/pkgs/common-updater/scripts/update-source-version
index 4c32ae046f3..3e507660a65 100755
--- a/pkgs/common-updater/scripts/update-source-version
+++ b/pkgs/common-updater/scripts/update-source-version
@@ -6,10 +6,11 @@ die() {
     exit 1
 }
 
-# Usage: update-source-hash <attr> <version> [<new-source-hash>]
+# Usage: update-source-hash <attr> <version> [<new-source-hash>] [<new-source-url>]
 attr=$1
 newVersion=$2
 newHash=$3
+newUrl=$4
 
 nixFile=$(nix-instantiate --eval --strict -A "$attr.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/')
 if [ ! -f "$nixFile" ]; then
@@ -27,6 +28,12 @@ if [ $(grep -c "$oldHash" "$nixFile") != 1 ]; then
     die "Couldn't locate old source hash '$oldHash' (or it appeared more than once) in '$nixFile'!"
 fi
 
+oldUrl=$(nix-instantiate --eval -E "with import ./. {}; builtins.elemAt $attr.src.drvAttrs.urls 0" | tr -d '"')
+
+if [ -z "$oldUrl" ]; then
+    die "Couldn't evaluate source url from '$attr.name'!"
+fi
+
 drvName=$(nix-instantiate --eval -E "with import ./. {}; (builtins.parseDrvName $attr.name).name" | tr -d '"')
 oldVersion=$(nix-instantiate --eval -E "with import ./. {}; $attr.version or (builtins.parseDrvName $attr.name).version" | tr -d '"')
 
@@ -41,6 +48,7 @@ fi
 
 # Escape regex metacharacter that are allowed in store path names
 oldVersion=$(echo "$oldVersion" | sed -re 's|[.+]|\\&|g')
+oldUrl=$(echo "$oldUrl" | sed -re 's|[${}.+]|\\&|g')
 
 if [ $(grep -c -E "^\s*(let\b)?\s*version\s*=\s*\"$oldVersion\"" "$nixFile") = 1 ]; then
     pattern="/\bversion\b\s*=/ s|\"$oldVersion\"|\"$newVersion\"|"
@@ -56,6 +64,15 @@ if cmp -s "$nixFile" "$nixFile.bak"; then
     die "Failed to replace version '$oldVersion' to '$newVersion' in '$attr'!"
 fi
 
+# Replace new URL
+if [ -n "$newUrl" ]; then
+    sed -i "$nixFile" -re "s|\"$oldUrl\"|\"$newUrl\"|"
+
+    if cmp -s "$nixFile" "$nixFile.bak"; then
+        die "Failed to replace source URL '$oldUrl' to '$newUrl' in '$attr'!"
+    fi
+fi
+
 case "$oldHashAlgo" in
     sha256) hashLength=64 ;;
     sha512) hashLength=128 ;;
@@ -74,7 +91,7 @@ fi
 if [ -z "$newHash" ]; then
     nix-build --no-out-link -A "$attr.src" 2>"$attr.fetchlog" >/dev/null || true
     # FIXME: use nix-build --hash here once https://github.com/NixOS/nix/issues/1172 is fixed
-    newHash=$(egrep -v "killing process|dependencies couldn't be built" "$attr.fetchlog" | tail -n2 | sed "s~output path .* has .* hash \(.*\) when .* was expected\|fixed-output derivation produced path '.*' with .* hash '\(.*\)' instead of the expected hash '.*'~\1\2~" | head -n1)
+    newHash=$(egrep -v "killing process|dependencies couldn't be built" "$attr.fetchlog" | tail -n2 | sed "s~output path .* has .* hash ‘\(.*\)’ when .* was expected\|fixed-output derivation produced path '.*' with .* hash '\(.*\)' instead of the expected hash '.*'~\1\2~" | head -n1)
 fi
 
 if [ -z "$newHash" ]; then