From 186de9ca9ef5650180f2f0cf0a9efdc7dfb16e2e Mon Sep 17 00:00:00 2001 From: taku0 Date: Wed, 14 Mar 2018 23:24:34 +0900 Subject: common-updater: support updating source URL --- pkgs/common-updater/scripts/update-source-version | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'pkgs/common-updater') 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 [] +# Usage: update-source-hash [] [] 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 -- cgit 1.4.1