From f4e390dc8a336cb32bdc9e8bba7cb3b195e9b237 Mon Sep 17 00:00:00 2001 From: nicoo Date: Mon, 4 Dec 2023 16:43:38 +0000 Subject: [PATCH] mpvScripts: Test that dir-packaged scripts contain exactly one `main.*` --- .../video/mpv/scripts/default.nix | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index 67baba53983d..11d9c2e934a9 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -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 }