3
0
Fork 0
forked from mirrors/nixpkgs

maintainers/scripts/update.nix: auto-detect attrPath

This commit is contained in:
Jan Tojnar 2020-09-20 00:20:34 +02:00
parent b351de0971
commit c21a85c6a0
No known key found for this signature in database
GPG key ID: 7FAB2A15F7A607A4
4 changed files with 32 additions and 32 deletions

View file

@ -490,7 +490,7 @@ passthru.updateScript = {
</note>
</para>
<para>
<filename>maintainers/scripts/update.nix</filename> also supports automatically creating commits by running it with <literal>--argstr commit true</literal> but it requires either declaring the <variable>attrPath</variable>, or adding a <literal>commit</literal> to <variable>supportedFeatures</variable> and <link xlink:href="#var-passthru-updateScript-commit">modifying the script accordingly</link>.
<filename>maintainers/scripts/update.nix</filename> also supports automatically creating commits by running it with <literal>--argstr commit true</literal>. Neither declaring the <variable>attrPath</variable> attribute, or adding a <literal>commit</literal> to <variable>supportedFeatures</variable> and <link xlink:href="#var-passthru-updateScript-commit">modifying the script accordingly</link> is required. It might be useful if you want to customize the values to something else than what <filename>update.nix</filename> detects.
</para>
<variablelist>
<title>Supported features</title>

View file

@ -32,27 +32,31 @@ let
in
[x] ++ nubOn f xs;
packagesWithPath = relativePath: cond: return: pathContent:
packagesWithPath = rootPath: cond: pkgs:
let
result = builtins.tryEval pathContent;
dedupResults = lst: nubOn (pkg: pkg.updateScript) (lib.concatLists lst);
in
if result.success then
packagesWithPathInner = relativePath: pathContent:
let
pathContent = result.value;
result = builtins.tryEval pathContent;
dedupResults = lst: nubOn ({ package, attrPath }: package.updateScript) (lib.concatLists lst);
in
if lib.isDerivation pathContent then
lib.optional (cond relativePath pathContent) (return relativePath pathContent)
else if lib.isAttrs pathContent then
# If user explicitly points to an attrSet or it is marked for recursion, we recur.
if relativePath == [] || pathContent.recurseForDerivations or false || pathContent.recurseForRelease or false then
dedupResults (lib.mapAttrsToList (name: elem: packagesWithPath (relativePath ++ [name]) cond return elem) pathContent)
else []
else if lib.isList pathContent then
dedupResults (lib.imap0 (i: elem: packagesWithPath (relativePath ++ [i]) cond return elem) pathContent)
else []
else [];
if result.success then
let
pathContent = result.value;
in
if lib.isDerivation pathContent then
lib.optional (cond relativePath pathContent) { attrPath = lib.concatStringsSep "." relativePath; package = pathContent; }
else if lib.isAttrs pathContent then
# If user explicitly points to an attrSet or it is marked for recursion, we recur.
if relativePath == rootPath || pathContent.recurseForDerivations or false || pathContent.recurseForRelease or false then
dedupResults (lib.mapAttrsToList (name: elem: packagesWithPathInner (relativePath ++ [name]) elem) pathContent)
else []
else if lib.isList pathContent then
dedupResults (lib.imap0 (i: elem: packagesWithPathInner (relativePath ++ [i]) elem) pathContent)
else []
else [];
in
packagesWithPathInner rootPath pkgs;
packagesWith = packagesWithPath [];
@ -73,18 +77,17 @@ let
else false
)
)
(relativePath: pkg: pkg)
pkgs;
packagesWithUpdateScript = path:
let
pathContent = lib.attrByPath (lib.splitString "." path) null pkgs;
prefix = lib.splitString "." path;
pathContent = lib.attrByPath prefix null pkgs;
in
if pathContent == null then
builtins.throw "Attribute path `${path}` does not exists."
else
packagesWith (relativePath: pkg: builtins.hasAttr "updateScript" pkg)
(relativePath: pkg: pkg)
packagesWithPath prefix (relativePath: pkg: builtins.hasAttr "updateScript" pkg)
pathContent;
packageByName = name:
@ -96,7 +99,7 @@ let
else if ! builtins.hasAttr "updateScript" package then
builtins.throw "Package with an attribute name `${name}` does not have a `passthru.updateScript` attribute defined."
else
package;
{ attrPath = name; inherit package; };
packages =
if package != null then
@ -140,13 +143,13 @@ let
--argstr commit true
'';
packageData = package: {
packageData = { package, attrPath }: {
name = package.name;
pname = lib.getName package;
oldVersion = lib.getVersion package;
updateScript = map builtins.toString (lib.toList (package.updateScript.command or package.updateScript));
supportedFeatures = package.updateScript.supportedFeatures or [];
attrPath = package.updateScript.attrPath or null;
attrPath = package.updateScript.attrPath or attrPath;
};
packagesJson = pkgs.writeText "packages.json" (builtins.toJSON (map packageData packages));

View file

@ -91,8 +91,8 @@ async def check_changes(package: Dict, worktree: str, update_info: str):
if len(changes) == 1:
# Dynamic data from updater take precedence over static data from passthru.updateScript.
if 'attrPath' not in changes[0]:
if 'attrPath' in package:
changes[0]['attrPath'] = package['attrPath']
# update.nix is always passing attrPath
changes[0]['attrPath'] = package['attrPath']
if 'oldVersion' not in changes[0]:
# update.nix is always passing oldVersion

View file

@ -23,7 +23,4 @@ let
latest_tag=$(python "${./find-latest-version.py}" "$package_name" "$version_policy" "stable" ${upperBoundFlag})
update-source-version "$attr_path" "$latest_tag"
'';
in {
command = [ updateScript packageName attrPath versionPolicy ];
inherit attrPath;
}
in [ updateScript packageName attrPath versionPolicy ]