From ee1795cc87833d7c68b85a5d88e8bbb6228df813 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Thu, 8 Sep 2022 01:23:50 +0200 Subject: common-updater-scripts: Only look for URL when replacing it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This would do a pointless slow `nix-instantiate` call for a feature that is rarely used – initially, it was added for Firefox updates https://github.com/NixOS/nixpkgs/commit/186de9ca9ef5650180f2f0cf0a9efdc7dfb16e2e but now not even that uses it. Additionally, this would break stuff like `cargoDeps`, which lack the url attributes. --- pkgs/common-updater/scripts/update-source-version | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 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 a3a7bde17f8..480fb7b2265 100755 --- a/pkgs/common-updater/scripts/update-source-version +++ b/pkgs/common-updater/scripts/update-source-version @@ -133,12 +133,6 @@ if [[ $(grep --count "$oldHash" "$nixFile") != 1 ]]; then die "Couldn't locate old source hash '$oldHash' (or it appeared more than once) in '$nixFile'!" fi -oldUrl=$(nix-instantiate $systemArg --eval -E "with $importTree; builtins.elemAt ($attr.$sourceKey.drvAttrs.urls or [ $attr.$sourceKey.url ]) 0" | tr -d '"') - -if [[ -z "$oldUrl" ]]; then - die "Couldn't evaluate source url from '$attr.$sourceKey'!" -fi - oldVersion=$(nix-instantiate $systemArg --eval -E "with $importTree; $attr.${versionKey} or (builtins.parseDrvName $attr.name).version" | tr -d '"') if [[ -z "$oldVersion" ]]; then @@ -162,7 +156,6 @@ fi # Escape regex metacharacter that are allowed in store path names oldVersionEscaped=$(echo "$oldVersion" | sed -re 's|[.+]|\\&|g') -oldUrlEscaped=$(echo "$oldUrl" | sed -re 's|[${}.+]|\\&|g') if [[ $(grep --count --extended-regexp "^\s*(let\b)?\s*$versionKey\s*=\s*\"$oldVersionEscaped\"" "$nixFile") = 1 ]]; then pattern="/\b$versionKey\b\s*=/ s|\"$oldVersionEscaped\"|\"$newVersion\"|" @@ -213,6 +206,14 @@ fi # Replace new URL if [[ -n "$newUrl" ]]; then + oldUrl=$(nix-instantiate $systemArg --eval -E "with $importTree; builtins.elemAt ($attr.$sourceKey.drvAttrs.urls or [ $attr.$sourceKey.url ]) 0" | tr -d '"') + if [[ -z "$oldUrl" ]]; then + die "Couldn't evaluate source url from '$attr.$sourceKey'!" + fi + + # Escape regex metacharacter that are allowed in store path names + oldUrlEscaped=$(echo "$oldUrl" | sed -re 's|[${}.+]|\\&|g') + sed -i.cmp "$nixFile" -re "s|\"$oldUrlEscaped\"|\"$newUrl\"|" if cmp -s "$nixFile" "$nixFile.cmp"; then die "Failed to replace source URL '$oldUrl' to '$newUrl' in '$attr'!" -- cgit 1.4.1