maintainers/scripts/update.nix: auto-detect attrPath
This commit is contained in:
parent
b351de0971
commit
c21a85c6a0
|
@ -490,7 +490,7 @@ passthru.updateScript = {
|
||||||
</note>
|
</note>
|
||||||
</para>
|
</para>
|
||||||
<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>
|
</para>
|
||||||
<variablelist>
|
<variablelist>
|
||||||
<title>Supported features</title>
|
<title>Supported features</title>
|
||||||
|
|
|
@ -32,27 +32,31 @@ let
|
||||||
in
|
in
|
||||||
[x] ++ nubOn f xs;
|
[x] ++ nubOn f xs;
|
||||||
|
|
||||||
packagesWithPath = relativePath: cond: return: pathContent:
|
packagesWithPath = rootPath: cond: pkgs:
|
||||||
|
let
|
||||||
|
packagesWithPathInner = relativePath: pathContent:
|
||||||
let
|
let
|
||||||
result = builtins.tryEval pathContent;
|
result = builtins.tryEval pathContent;
|
||||||
|
|
||||||
dedupResults = lst: nubOn (pkg: pkg.updateScript) (lib.concatLists lst);
|
dedupResults = lst: nubOn ({ package, attrPath }: package.updateScript) (lib.concatLists lst);
|
||||||
in
|
in
|
||||||
if result.success then
|
if result.success then
|
||||||
let
|
let
|
||||||
pathContent = result.value;
|
pathContent = result.value;
|
||||||
in
|
in
|
||||||
if lib.isDerivation pathContent then
|
if lib.isDerivation pathContent then
|
||||||
lib.optional (cond relativePath pathContent) (return relativePath pathContent)
|
lib.optional (cond relativePath pathContent) { attrPath = lib.concatStringsSep "." relativePath; package = pathContent; }
|
||||||
else if lib.isAttrs pathContent then
|
else if lib.isAttrs pathContent then
|
||||||
# If user explicitly points to an attrSet or it is marked for recursion, we recur.
|
# 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
|
if relativePath == rootPath || pathContent.recurseForDerivations or false || pathContent.recurseForRelease or false then
|
||||||
dedupResults (lib.mapAttrsToList (name: elem: packagesWithPath (relativePath ++ [name]) cond return elem) pathContent)
|
dedupResults (lib.mapAttrsToList (name: elem: packagesWithPathInner (relativePath ++ [name]) elem) pathContent)
|
||||||
else []
|
else []
|
||||||
else if lib.isList pathContent then
|
else if lib.isList pathContent then
|
||||||
dedupResults (lib.imap0 (i: elem: packagesWithPath (relativePath ++ [i]) cond return elem) pathContent)
|
dedupResults (lib.imap0 (i: elem: packagesWithPathInner (relativePath ++ [i]) elem) pathContent)
|
||||||
else []
|
else []
|
||||||
else [];
|
else [];
|
||||||
|
in
|
||||||
|
packagesWithPathInner rootPath pkgs;
|
||||||
|
|
||||||
packagesWith = packagesWithPath [];
|
packagesWith = packagesWithPath [];
|
||||||
|
|
||||||
|
@ -73,18 +77,17 @@ let
|
||||||
else false
|
else false
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(relativePath: pkg: pkg)
|
|
||||||
pkgs;
|
pkgs;
|
||||||
|
|
||||||
packagesWithUpdateScript = path:
|
packagesWithUpdateScript = path:
|
||||||
let
|
let
|
||||||
pathContent = lib.attrByPath (lib.splitString "." path) null pkgs;
|
prefix = lib.splitString "." path;
|
||||||
|
pathContent = lib.attrByPath prefix null pkgs;
|
||||||
in
|
in
|
||||||
if pathContent == null then
|
if pathContent == null then
|
||||||
builtins.throw "Attribute path `${path}` does not exists."
|
builtins.throw "Attribute path `${path}` does not exists."
|
||||||
else
|
else
|
||||||
packagesWith (relativePath: pkg: builtins.hasAttr "updateScript" pkg)
|
packagesWithPath prefix (relativePath: pkg: builtins.hasAttr "updateScript" pkg)
|
||||||
(relativePath: pkg: pkg)
|
|
||||||
pathContent;
|
pathContent;
|
||||||
|
|
||||||
packageByName = name:
|
packageByName = name:
|
||||||
|
@ -96,7 +99,7 @@ let
|
||||||
else if ! builtins.hasAttr "updateScript" package then
|
else if ! builtins.hasAttr "updateScript" package then
|
||||||
builtins.throw "Package with an attribute name `${name}` does not have a `passthru.updateScript` attribute defined."
|
builtins.throw "Package with an attribute name `${name}` does not have a `passthru.updateScript` attribute defined."
|
||||||
else
|
else
|
||||||
package;
|
{ attrPath = name; inherit package; };
|
||||||
|
|
||||||
packages =
|
packages =
|
||||||
if package != null then
|
if package != null then
|
||||||
|
@ -140,13 +143,13 @@ let
|
||||||
--argstr commit true
|
--argstr commit true
|
||||||
'';
|
'';
|
||||||
|
|
||||||
packageData = package: {
|
packageData = { package, attrPath }: {
|
||||||
name = package.name;
|
name = package.name;
|
||||||
pname = lib.getName package;
|
pname = lib.getName package;
|
||||||
oldVersion = lib.getVersion package;
|
oldVersion = lib.getVersion package;
|
||||||
updateScript = map builtins.toString (lib.toList (package.updateScript.command or package.updateScript));
|
updateScript = map builtins.toString (lib.toList (package.updateScript.command or package.updateScript));
|
||||||
supportedFeatures = package.updateScript.supportedFeatures or [];
|
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));
|
packagesJson = pkgs.writeText "packages.json" (builtins.toJSON (map packageData packages));
|
||||||
|
|
|
@ -91,7 +91,7 @@ async def check_changes(package: Dict, worktree: str, update_info: str):
|
||||||
if len(changes) == 1:
|
if len(changes) == 1:
|
||||||
# Dynamic data from updater take precedence over static data from passthru.updateScript.
|
# Dynamic data from updater take precedence over static data from passthru.updateScript.
|
||||||
if 'attrPath' not in changes[0]:
|
if 'attrPath' not in changes[0]:
|
||||||
if 'attrPath' in package:
|
# update.nix is always passing attrPath
|
||||||
changes[0]['attrPath'] = package['attrPath']
|
changes[0]['attrPath'] = package['attrPath']
|
||||||
|
|
||||||
if 'oldVersion' not in changes[0]:
|
if 'oldVersion' not in changes[0]:
|
||||||
|
|
|
@ -23,7 +23,4 @@ let
|
||||||
latest_tag=$(python "${./find-latest-version.py}" "$package_name" "$version_policy" "stable" ${upperBoundFlag})
|
latest_tag=$(python "${./find-latest-version.py}" "$package_name" "$version_policy" "stable" ${upperBoundFlag})
|
||||||
update-source-version "$attr_path" "$latest_tag"
|
update-source-version "$attr_path" "$latest_tag"
|
||||||
'';
|
'';
|
||||||
in {
|
in [ updateScript packageName attrPath versionPolicy ]
|
||||||
command = [ updateScript packageName attrPath versionPolicy ];
|
|
||||||
inherit attrPath;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue