update-source-version: Fixes, add --ignore-same-hash

--ignore-same-hash allows ignoring if the same has is used.
This gives the ability to run update-source-version multiple times to
change multiple keys.

Fix version-key, which was not being used to determine the oldVersion
variable.

If $attr.src.drvAttrs.urls is not found, look for
$attr.src.drvAttrs.url since it is being used like that in fetchgit
This commit is contained in:
Tim Steinbach 2019-04-06 19:40:18 -04:00
parent b248553282
commit cce486838b
No known key found for this signature in database
GPG Key ID: 6C654787275A64F1

View File

@ -29,6 +29,9 @@ for arg in "$@"; do
die "Could not find provided file $nixFile"
fi
;;
--ignore-same-hash)
ignoreSameHash="true"
;;
--help)
usage
exit 0
@ -86,11 +89,15 @@ fi
oldUrl=$(nix-instantiate $systemArg --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'!"
oldUrl=$(nix-instantiate $systemArg --eval -E "with import ./. {}; $attr.src.url" | tr -d '"')
if [ -z "$oldUrl" ]; then
die "Couldn't evaluate source url from '$attr.src'!"
fi
fi
drvName=$(nix-instantiate $systemArg --eval -E "with import ./. {}; (builtins.parseDrvName $attr.name).name" | tr -d '"')
oldVersion=$(nix-instantiate $systemArg --eval -E "with import ./. {}; $attr.version or (builtins.parseDrvName $attr.name).version" | tr -d '"')
oldVersion=$(nix-instantiate $systemArg --eval -E "with import ./. {}; $attr.${versionKey} or (builtins.parseDrvName $attr.name).${versionKey}" | tr -d '"')
if [ -z "$drvName" -o -z "$oldVersion" ]; then
die "Couldn't evaluate name and version from '$attr.name'!"
@ -154,7 +161,7 @@ if [ -z "$newHash" ]; then
die "Couldn't figure out new hash of '$attr.src'!"
fi
if [ "$oldVersion" != "$newVersion" ] && [ "$oldHash" = "$newHash" ]; then
if [ -z "${ignoreSameHash}"] && [ "$oldVersion" != "$newVersion" ] && [ "$oldHash" = "$newHash" ]; then
mv "$nixFile.bak" "$nixFile"
die "Both the old and new source hashes of '$attr.src' were equivalent. Please fix the package's source URL to be dependent on '\${version}'!"
fi