Unverified Commit d914dcf6 authored by Peder Bergebakken Sundt's avatar Peder Bergebakken Sundt Committed by GitHub
Browse files

Merge pull request #272088 from nbraud/mpvScripts/validate

mpvScripts: Add generic tests to all drvs
parents b1417122 764f5463
Loading
Loading
Loading
Loading
+56 −4
Original line number Diff line number Diff line
{ lib
, callPackage
, config
, runCommand
}:

let buildLua = callPackage ./buildLua.nix { };
in lib.recurseIntoAttrs
  ({
let
  buildLua = callPackage ./buildLua.nix { };

  unionOfDisjoints = lib.fold lib.attrsets.unionOfDisjoint {};

  addTests = name: drv: let
    inherit (drv) scriptName;
    scriptPath = "share/mpv/scripts/${scriptName}";
    fullScriptPath = "${drv}/${scriptPath}";

  in drv.overrideAttrs (old: { passthru = (old.passthru or {}) // { tests = unionOfDisjoints [
    (old.passthru.tests or {})

    {
      scriptName-is-valid = runCommand "mpvScripts.${name}.passthru.tests.scriptName-is-valid" {
        meta.maintainers = with lib.maintainers; [ nicoo ];
        preferLocalBuild = true;
      } ''
        if [ -e "${fullScriptPath}" ]; then
          touch $out
        else
          echo "mpvScripts.\"${name}\" does not contain a script named \"${scriptName}\"" >&2
          exit 1
        fi
      '';
    }

    # can't check whether `fullScriptPath` is a directory, in pure-evaluation mode
    (with lib; optionalAttrs (! any (s: hasSuffix s drv.passthru.scriptName) [ ".js" ".lua" ".so" ]) {
      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
        }

        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

lib.recurseIntoAttrs
  (lib.mapAttrs addTests ({
    acompressor = callPackage ./acompressor.nix { inherit buildLua; };
    autocrop = callPackage ./autocrop.nix { };
    autodeint = callPackage ./autodeint.nix { };
@@ -29,7 +81,7 @@ in lib.recurseIntoAttrs
    vr-reversal = callPackage ./vr-reversal.nix { };
    webtorrent-mpv-hook = callPackage ./webtorrent-mpv-hook.nix { };
  }
  // (callPackage ./occivink.nix { inherit buildLua; }))
  // (callPackage ./occivink.nix { inherit buildLua; })))
  // lib.optionalAttrs config.allowAliases {
  youtube-quality = throw "'youtube-quality' is no longer maintained, use 'quality-menu' instead"; # added 2023-07-14
}
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ buildLua rec {
    runHook postInstall
  '';

  passthru.scriptName = "mpvacious";

  meta = with lib; {
    description = "Adds mpv keybindings to create Anki cards from movies and TV shows";
    homepage = "https://github.com/Ajatt-Tools/mpvacious";
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ buildLua rec {
  };

  scriptPath = ".";
  passthru.scriptName = "webui.lua";
  passthru.scriptName = "webui";

  meta = with lib; {
    description = "A web based user interface with controls for the mpv mediaplayer";