mpvScripts: Test that dir-packaged scripts contain exactly one main.*

This commit is contained in:
nicoo 2023-12-04 16:43:38 +00:00
parent 1bb85ca0d4
commit f4e390dc8a

View File

@ -7,21 +7,53 @@
let
buildLua = callPackage ./buildLua.nix { };
addTests = name: drv: drv.override { passthru.tests = lib.attrsets.unionOfDisjoint (drv.passthru.tests or {}) {
scriptName-is-valid = let
inherit (drv) scriptName;
scriptPath = "${drv}/share/mpv/scripts/${scriptName}";
in runCommand "mpvScripts.${name}.passthru.tests.scriptName-is-valid" {
inherit (lib.attrsets) filterAttrs optionalAttrs recursiveUpdate unionOfDisjoint;
addTests = name: drv: let
inherit (drv) scriptName;
scriptPath = "share/mpv/scripts/${scriptName}";
fullScriptPath = "${drv}/${scriptPath}";
in drv.override { passthru.tests = unionOfDisjoint (drv.passthru.tests or {}) {
scriptName-is-valid = runCommand "mpvScripts.${name}.passthru.tests.scriptName-is-valid" {
meta.maintainers = with lib.maintainers; [ nicoo ];
preferLocalBuild = true;
} ''
if [ -e "${scriptPath}" ]; then
if [ -e "${fullScriptPath}" ]; then
touch $out
else
echo "mpvScripts.\"${name}\" does not contain a script named \"${scriptName}\"" >&2
exit 1
fi
'';
# TODO(nicoo): Avoid emitting the test for scripts that aren't dir-packaged
single-main-in-script-dir = runCommand "mpvScripts.${name}.passthru.tests.single-main-in-script-dir" {
meta.maintainers = with lib.maintainers; [ nicoo ];
preferLocalBuild = true;
} ''
die() {
echo "$@" >&2
exit 1
}
if ! [ -d "${fullScriptPath}" ]; then
echo "This script isn't dir-packaged" >&2
touch $out
exit 0
fi
cd "${drv}/${scriptPath}" # so the glob expands to filenames only
mains=( main.* )
if [ "''${#mains[*]}" -eq 1 ]; then
touch $out
elif [ "''${#mains[*]}" -eq 0 ]; then
die "'${scriptPath}' contains no 'main.*' file"
else
die "'${scriptPath}' contains multiple 'main.*' files:" "''${mains[*]}"
fi
'';
}; };
in
@ -50,6 +82,6 @@ lib.recurseIntoAttrs
cutter = callPackage ./cutter.nix { };
}
// (callPackage ./occivink.nix { inherit buildLua; })))
// lib.optionalAttrs config.allowAliases {
// optionalAttrs config.allowAliases {
youtube-quality = throw "'youtube-quality' is no longer maintained, use 'quality-menu' instead"; # added 2023-07-14
}