maintainers/scripts/update.nix: various fixes (#62478)

maintainers/scripts/update.nix: various fixes
This commit is contained in:
Jan Tojnar 2019-06-04 18:24:16 +02:00 committed by GitHub
commit ea59f09946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 31 deletions

View File

@ -709,19 +709,16 @@ passthru.updateScript = writeScript "update-zoom-us" ''
<programlisting> <programlisting>
passthru.updateScript = [ ../../update.sh pname "--requested-release=unstable" ]; passthru.updateScript = [ ../../update.sh pname "--requested-release=unstable" ];
</programlisting> </programlisting>
Note that the update scripts will be run in parallel by default; you </para>
should avoid running <command>git commit</command> or any other commands <para>
that cannot handle that. The script will be usually run from the root of the Nixpkgs repository
but you should not rely on that. Also note that the update scripts will
be run in parallel by default; you should avoid running <command>git
commit</command> or any other commands that cannot handle that.
</para> </para>
<para> <para>
For information about how to run the updates, execute For information about how to run the updates, execute
<cmdsynopsis> <command>nix-shell maintainers/scripts/update.nix</command>.
<command>nix-shell</command>
<arg>
maintainers/scripts/update.nix
</arg>
</cmdsynopsis>
.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@ -20,7 +20,9 @@ let
in in
[x] ++ nubOn f xs; [x] ++ nubOn f xs;
pkgs = import ./../../default.nix { }; pkgs = import ./../../default.nix {
overlays = [];
};
packagesWith = cond: return: set: packagesWith = cond: return: set:
nubOn (pkg: pkg.updateScript) nubOn (pkg: pkg.updateScript)
@ -67,9 +69,12 @@ let
let let
attrSet = pkgs.lib.attrByPath (pkgs.lib.splitString "." path) null pkgs; attrSet = pkgs.lib.attrByPath (pkgs.lib.splitString "." path) null pkgs;
in in
packagesWith (name: pkg: builtins.hasAttr "updateScript" pkg) if attrSet == null then
(name: pkg: pkg) builtins.throw "Attribute path `${path}` does not exists."
attrSet; else
packagesWith (name: pkg: builtins.hasAttr "updateScript" pkg)
(name: pkg: pkg)
attrSet;
packageByName = name: packageByName = name:
let let
@ -122,9 +127,17 @@ let
packageData = package: { packageData = package: {
name = package.name; name = package.name;
pname = (builtins.parseDrvName package.name).name; pname = (builtins.parseDrvName package.name).name;
updateScript = pkgs.lib.toList package.updateScript; updateScript = map builtins.toString (pkgs.lib.toList package.updateScript);
}; };
packagesJson = pkgs.writeText "packages.json" (builtins.toJSON (map packageData packages));
optionalArgs =
pkgs.lib.optional (max-workers != null) "--max-workers=${max-workers}"
++ pkgs.lib.optional (keep-going == "true") "--keep-going";
args = [ packagesJson ] ++ optionalArgs;
in pkgs.stdenv.mkDerivation { in pkgs.stdenv.mkDerivation {
name = "nixpkgs-update-script"; name = "nixpkgs-update-script";
buildCommand = '' buildCommand = ''
@ -139,6 +152,6 @@ in pkgs.stdenv.mkDerivation {
''; '';
shellHook = '' shellHook = ''
unset shellHook # do not contaminate nested shells unset shellHook # do not contaminate nested shells
exec ${pkgs.python3.interpreter} ${./update.py} ${pkgs.writeText "packages.json" (builtins.toJSON (map packageData packages))}${pkgs.lib.optionalString (max-workers != null) " --max-workers=${max-workers}"}${pkgs.lib.optionalString (keep-going == "true") " --keep-going"} exec ${pkgs.python3.interpreter} ${./update.py} ${builtins.concatStringsSep " " args}
''; '';
} }

View File

@ -86,14 +86,10 @@ if [ $(grep -c "$oldHash" "$nixFile") != 1 ]; then
die "Couldn't locate old source hash '$oldHash' (or it appeared more than once) in '$nixFile'!" die "Couldn't locate old source hash '$oldHash' (or it appeared more than once) in '$nixFile'!"
fi fi
oldUrl=$(nix-instantiate $systemArg --eval -E "with import ./. {}; builtins.elemAt $attr.src.drvAttrs.urls 0" | tr -d '"') oldUrl=$(nix-instantiate $systemArg --eval -E "with import ./. {}; builtins.elemAt ($attr.src.drvAttrs.urls or [ $attr.src.url ]) 0" | tr -d '"')
if [ -z "$oldUrl" ]; then if [ -z "$oldUrl" ]; then
oldUrl=$(nix-instantiate $systemArg --eval -E "with import ./. {}; $attr.src.url" | tr -d '"') die "Couldn't evaluate source url from '$attr.src'!"
if [ -z "$oldUrl" ]; then
die "Couldn't evaluate source url from '$attr.src'!"
fi
fi fi
drvName=$(nix-instantiate $systemArg --eval -E "with import ./. {}; (builtins.parseDrvName $attr.name).name" | tr -d '"') drvName=$(nix-instantiate $systemArg --eval -E "with import ./. {}; (builtins.parseDrvName $attr.name).name" | tr -d '"')
@ -109,13 +105,13 @@ if [ "$oldVersion" = "$newVersion" ]; then
fi fi
# Escape regex metacharacter that are allowed in store path names # Escape regex metacharacter that are allowed in store path names
oldVersion=$(echo "$oldVersion" | sed -re 's|[.+]|\\&|g') oldVersionEscaped=$(echo "$oldVersion" | sed -re 's|[.+]|\\&|g')
oldUrl=$(echo "$oldUrl" | sed -re 's|[${}.+]|\\&|g') oldUrlEscaped=$(echo "$oldUrl" | sed -re 's|[${}.+]|\\&|g')
if [ $(grep -c -E "^\s*(let\b)?\s*$versionKey\s*=\s*\"$oldVersion\"" "$nixFile") = 1 ]; then if [ $(grep -c -E "^\s*(let\b)?\s*$versionKey\s*=\s*\"$oldVersionEscaped\"" "$nixFile") = 1 ]; then
pattern="/\b$versionKey\b\s*=/ s|\"$oldVersion\"|\"$newVersion\"|" pattern="/\b$versionKey\b\s*=/ s|\"$oldVersionEscaped\"|\"$newVersion\"|"
elif [ $(grep -c -E "^\s*(let\b)?\s*name\s*=\s*\"[^\"]+-$oldVersion\"" "$nixFile") = 1 ]; then elif [ $(grep -c -E "^\s*(let\b)?\s*name\s*=\s*\"[^\"]+-$oldVersionEscaped\"" "$nixFile") = 1 ]; then
pattern="/\bname\b\s*=/ s|-$oldVersion\"|-$newVersion\"|" pattern="/\bname\b\s*=/ s|-$oldVersionEscaped\"|-$newVersion\"|"
else else
die "Couldn't figure out where out where to patch in new version in '$attr'!" die "Couldn't figure out where out where to patch in new version in '$attr'!"
fi fi
@ -128,7 +124,7 @@ fi
# Replace new URL # Replace new URL
if [ -n "$newUrl" ]; then if [ -n "$newUrl" ]; then
sed -i "$nixFile" -re "s|\"$oldUrl\"|\"$newUrl\"|" sed -i "$nixFile" -re "s|\"$oldUrlEscaped\"|\"$newUrl\"|"
if cmp -s "$nixFile" "$nixFile.bak"; then if cmp -s "$nixFile" "$nixFile.bak"; then
die "Failed to replace source URL '$oldUrl' to '$newUrl' in '$attr'!" die "Failed to replace source URL '$oldUrl' to '$newUrl' in '$attr'!"

View File

@ -1,4 +1,4 @@
{ stdenv, lib, writeScript, python3, common-updater-scripts, coreutils, gnugrep, gnused }: { stdenv, lib, writeScript, python3, common-updater-scripts }:
{ packageName, attrPath ? packageName, versionPolicy ? "odd-unstable" }: { packageName, attrPath ? packageName, versionPolicy ? "odd-unstable" }:
let let
@ -9,7 +9,7 @@ let
package_name="$1" package_name="$1"
attr_path="$2" attr_path="$2"
version_policy="$3" version_policy="$3"
PATH=${lib.makeBinPath [ common-updater-scripts coreutils gnugrep gnused python ]} PATH=${lib.makeBinPath [ common-updater-scripts python ]}
latest_tag=$(python "${./find-latest-version.py}" "$package_name" "$version_policy" "stable") latest_tag=$(python "${./find-latest-version.py}" "$package_name" "$version_policy" "stable")
update-source-version "$attr_path" "$latest_tag" update-source-version "$attr_path" "$latest_tag"
''; '';