common-updater: support updating source URL

This commit is contained in:
taku0 2018-03-14 23:24:34 +09:00
parent cb51341d12
commit 186de9ca9e
2 changed files with 22 additions and 3 deletions

View File

@ -28,7 +28,9 @@ writeScript "update-${attrPath}" ''
sort --version-sort | \
tail -n 1`
source_url=`curl --silent $url$version/SOURCE | grep -o 'https://.*\.tar\.bz2'`
shasum=`curl --silent $url$version/SHA512SUMS | grep 'source\.tar\.xz' | cut -d ' ' -f 1`
update-source-version ${attrPath} "$version" "$shasum"
update-source-version ${attrPath} "$version" "$shasum" "$source_url"
''

View File

@ -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