From 523892928dfd692c915c82b98c6f922f7c2720ea Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Tue, 28 May 2024 08:20:16 -0700 Subject: [PATCH] ctagsWrapped: rewrite to use callPackage injection and be a derivation (#299245) --- pkgs/development/tools/misc/ctags/wrapped.nix | 160 ++++++++++-------- 1 file changed, 86 insertions(+), 74 deletions(-) diff --git a/pkgs/development/tools/misc/ctags/wrapped.nix b/pkgs/development/tools/misc/ctags/wrapped.nix index 2bc3aa5ecf4f..b3734bbf06a4 100644 --- a/pkgs/development/tools/misc/ctags/wrapped.nix +++ b/pkgs/development/tools/misc/ctags/wrapped.nix @@ -1,78 +1,90 @@ -{ pkgs, ctags }: - -with pkgs.lib; - -# define some ctags wrappers adding support for some not that common languages -# customization: -# a) add stuff here -# b) override asLang, phpLang, ... using packageOverrides -# c) use ctagsWrapped.override {args = [ your liste ];} - -# install using -iA ctagsWrapped.ctagsWrapped - { + lib, + ctags, + writeTextFile, + runtimeShell, + ctagsWrapped, + name ? "${ctags.name}-wrapped", + args ? lib.concatLists [ + ctagsWrapped.defaultArgs + ctagsWrapped.phpLang + ctagsWrapped.jsLang + ctagsWrapped.nixLang + ctagsWrapped.asLang + ctagsWrapped.rubyLang + ], +}: - # the derivation. use language extensions specified by args - ctagsWrapped = makeOverridable ( {args, name} : pkgs.writeScriptBin name '' - #!${pkgs.runtimeShell} - exec ${pkgs.ctags}/bin/ctags ${concatStringsSep " " (map escapeShellArg args)} "$@" - '') { - args = let x = pkgs.ctagsWrapped; in concatLists [ - x.defaultArgs x.phpLang x.jsLang x.nixLang x.asLang x.rubyLang - ]; - name = "${ctags.name}-wrapped"; +# Define a ctags wrapper derivation adding support for some not-that-common languages customization. +# Override this to provide different args. + +writeTextFile { + inherit name; + executable = true; + destination = "/bin/${name}"; + text = '' + #!${runtimeShell} + exec ${ctags}/bin/ctags ${lib.concatStringsSep " " (map lib.escapeShellArg args)} "$@" + ''; + derivationArgs = { + # Inherit the metadata from the parent `ctags` derivation. + inherit (ctags) meta; + + passthru = { + # `ctagsWrapped` exists for backwards compatibility; ctagsWrapped used to be an attrset and + # now is a derivation, so keep supporting the use of `ctagsWrapped.ctagsWrapped`. + inherit ctagsWrapped; + + ### language arguments + + # don't scan version control directories + defaultArgs = [ + "--exclude=.svn" + "--exclude=.hg" + "--exclude=.git" + "--exclude=_darcs" + "--sort=yes" + ]; + + # actionscript + asLang = [ + "--langdef=ActionScript" + "--langmap=ActionScript:.as" + "--regex-ActionScript=/function[ \\t]+([A-Za-z0-9_]+)[ \\t]*\\(/\\1/f,function,functions/" + "--regex-ActionScript=/function[ \\t]+(set|get)[ \\t]+([A-Za-z0-9_]+)[ \\t]*\\(/\\2/p,property,properties/" + "--regex-ActionScript=/interface[ \\t]+[a-z0-9_.]*([A-Z][A-Za-z0-9_]+)/\\1/i,interface,interfaces/" + "--regex-ActionScript=/package[ \\t]+([^ \\t]*)/\\1/p/" + "--regex-ActionScript=/class[ \\t]+[a-z0-9_.]*([A-Z][A-Za-z0-9_]+)/\\1/c,class,classes/" + ]; + + # PHP + phpLang = [ + "--langmap=PHP:.php" + "--regex-PHP=/abstract class ([^ ]*)/\\1/c/" + "--regex-PHP=/interface ([^ ]*)/\\1/i/" + "--regex-PHP=/function[ \\t]+([^ (]*)/\\1/f/" + ]; + + # Javascript: also find unnamed functions and functions being passed within a dict. + # the dict properties is used to implement duck typing in frameworks + # var foo = function () { ... } + # { + # a : function () {} + # only recognize names up 100 characters. Else you'll be in trouble scanning compressed .js files. + jsLang = [ "--regex-JavaScript=/([^ \\t]{1,100})[ \\t]*:[ \\t]*function[ \\t]*\\(/\\1/f/" ]; + + # find foo in "foo =", don't think we can do a lot better + nixLang = [ + "--langdef=NIX" + "--langmap=NIX:.nix" + "--regex-NIX=/([^ \\t*]*)[ \\t]*=/\\1/f/" + ]; + + rubyLang = [ + "--langmap=RUBY:.rb" + "--regex-RUBY=/class ([^ ]*)/\\1/c/" + "--regex-RUBY=/^[ ]*module[ ]*([^ ]*)/\\1/m/" + ]; + }; }; - - ### language arguments - - # don't scan version control directories - defaultArgs = [ - "--exclude=.svn" - "--exclude=.hg" - "--exclude=.git" - "--exclude=_darcs" - "--sort=yes" - ]; - - # actionscript - asLang = [ - "--langdef=ActionScript" - "--langmap=ActionScript:.as" - "--regex-ActionScript=/function[ \\t]+([A-Za-z0-9_]+)[ \\t]*\\(/\\1/f,function,functions/" - "--regex-ActionScript=/function[ \\t]+(set|get)[ \\t]+([A-Za-z0-9_]+)[ \\t]*\\(/\\2/p,property,properties/" - "--regex-ActionScript=/interface[ \\t]+[a-z0-9_.]*([A-Z][A-Za-z0-9_]+)/\\1/i,interface,interfaces/" - "--regex-ActionScript=/package[ \\t]+([^ \\t]*)/\\1/p/" - "--regex-ActionScript=/class[ \\t]+[a-z0-9_.]*([A-Z][A-Za-z0-9_]+)/\\1/c,class,classes/" - ]; - - # PHP - phpLang = [ - "--langmap=PHP:.php" - "--regex-PHP=/abstract class ([^ ]*)/\\1/c/" - "--regex-PHP=/interface ([^ ]*)/\\1/i/" - "--regex-PHP=/function[ \\t]+([^ (]*)/\\1/f/" - ]; - - # Javascript: also find unnamed functions and functions being passed within a dict. - # the dict properties is used to implement duck typing in frameworks - # var foo = function () { ... } - # { - # a : function () {} - # only recognize names up 100 characters. Else you'll be in trouble scanning compressed .js files. - jsLang = [ - "--regex-JavaScript=/([^ \\t]{1,100})[ \\t]*:[ \\t]*function[ \\t]*\\(/\\1/f/" - ]; - - # find foo in "foo =", don't think we can do a lot better - nixLang = [ - "--langdef=NIX" - "--langmap=NIX:.nix" - "--regex-NIX=/([^ \\t*]*)[ \\t]*=/\\1/f/" - ]; - - rubyLang = [ - "--langmap=RUBY:.rb" - "--regex-RUBY=/class ([^ ]*)/\\1/c/" - "--regex-RUBY=/^[ ]*module[ ]*([^ ]*)/\\1/m/" - ]; }