vimPlugins.nvim-treesitter: move grammar generation from fetch to grammar.nix

This commit is contained in:
figsoda
2022-11-14 23:22:24 -05:00
parent 73982c5181
commit af810aa232
3 changed files with 39 additions and 51 deletions
@@ -1,6 +1,6 @@
# generated by pkgs/applications/editors/vim/plugins/nvim-treesitter/update.py
{ buildGrammar, fetchFromGitHub, fetchFromGitLab, fetchgit, nodejs, tree-sitter }:
{ buildGrammar, fetchFromGitHub, fetchFromGitLab, fetchgit }:
{
agda = buildGrammar {
@@ -169,11 +169,10 @@
source = fetchFromGitHub {
owner = "CyberShadow";
repo = "tree-sitter-d";
nativeBuildInputs = [ nodejs tree-sitter ];
postFetch = "pushd $out && tree-sitter generate && popd";
rev = "c2fbf21bd3aa45495fe13247e040ad5815250032";
hash = "sha256-JOCS72Ux1FMzf6kBVO7aqHNwJ0s3xkhzIFFV9GjJVOs=";
hash = "sha256-1aW3nLZ5MbsOEiJ9PH6N/bBUlRihosWa4OWRcAmT3kc=";
};
generate = true;
};
dart = buildGrammar {
language = "dart";
@@ -191,11 +190,10 @@
source = fetchFromGitHub {
owner = "joelspadin";
repo = "tree-sitter-devicetree";
nativeBuildInputs = [ nodejs tree-sitter ];
postFetch = "pushd $out && tree-sitter generate && popd";
rev = "ea30a05d0f0446a96d8b096ad11828ad4f8ad849";
hash = "sha256-AZ0MAGVfeVhRHEbiqQrDpKzZsb9AMHBXC9uOJVla2fk=";
hash = "sha256-ZiUMIsjVMxpchxmJQ3g2yXIn+/kAWPwTzMzx3IlW93o=";
};
generate = true;
};
diff = buildGrammar {
language = "diff";
@@ -373,11 +371,10 @@
source = fetchFromGitHub {
owner = "shunsambongi";
repo = "tree-sitter-gitignore";
nativeBuildInputs = [ nodejs tree-sitter ];
postFetch = "pushd $out && tree-sitter generate && popd";
rev = "f4685bf11ac466dd278449bcfe5fd014e94aa504";
hash = "sha256-Jv/DMHq5wE9avZgaVg8dSgoDgzl50u0TEj8pITQ3iBc=";
hash = "sha256-MjoY1tlVZgN6JqoTjhhg0zSdHzc8yplMr8824sfIKp8=";
};
generate = true;
};
gleam = buildGrammar {
language = "gleam";
@@ -425,11 +422,10 @@
source = fetchFromGitHub {
owner = "PrestonKnopp";
repo = "tree-sitter-godot-resource";
nativeBuildInputs = [ nodejs tree-sitter ];
postFetch = "pushd $out && tree-sitter generate && popd";
rev = "b6ef0768711086a86b3297056f9ffb5cc1d77b4a";
hash = "sha256-u3YcGCtFV0Kz6+604XJQOXiqncgU8LBVKROOiVMZrC0=";
hash = "sha256-ws/8nL+HOoPb6Hcdh4pihjPoRw90R1fy7MB0V9Lb9ik=";
};
generate = true;
};
gomod = buildGrammar {
language = "gomod";
@@ -831,11 +827,10 @@
source = fetchFromGitHub {
owner = "atom-ocaml";
repo = "tree-sitter-ocamllex";
nativeBuildInputs = [ nodejs tree-sitter ];
postFetch = "pushd $out && tree-sitter generate && popd";
rev = "ac1d5957e719d49bd6acd27439b79843e4daf8ed";
hash = "sha256-KxQiNJyS1Rbtc4Rl+ROktuVazdtjDduWdkrQ+NzT9NQ=";
hash = "sha256-XRxAnl+9F6AYPyd6BGNQOo+KjRs2el78ziyo7NeD1IE=";
};
generate = true;
};
org = buildGrammar {
language = "org";
@@ -1163,11 +1158,10 @@
source = fetchFromGitHub {
owner = "alex-pinkus";
repo = "tree-sitter-swift";
nativeBuildInputs = [ nodejs tree-sitter ];
postFetch = "pushd $out && tree-sitter generate && popd";
rev = "25f8de356e3c33099ed691bd3b8b5c0fe3a11e15";
hash = "sha256-KCmEE5O7EAA0uUcYkM/FpeEIn9tOqrJosSpYsBvivOk=";
hash = "sha256-x9m5QFQY33NWdkq0lkWiskfKxqRPz5ePSbVUDY7IBLU=";
};
generate = true;
};
sxhkdrc = buildGrammar {
language = "sxhkdrc";
@@ -1185,11 +1179,10 @@
source = fetchFromGitHub {
owner = "euclidianAce";
repo = "tree-sitter-teal";
nativeBuildInputs = [ nodejs tree-sitter ];
postFetch = "pushd $out && tree-sitter generate && popd";
rev = "1ae8c68e90523b26b93af56feb7868fe4214e2b2";
hash = "sha256-8FqXrsgOI/cVezgVsQqPLlTa4Qnzmbuelo0XsI48fV0=";
hash = "sha256-IGSZurROJLOp1pRPLowHGO1Pu/ehieLKWgI+RCE7wLc=";
};
generate = true;
};
tiger = buildGrammar {
language = "tiger";
@@ -75,19 +75,6 @@ def generate_grammar(item):
generated += f"""fetchgit {{
url = "{url}";"""
if info.get("requires_generate_from_grammar"):
cmd += [
"--arg",
"nativeBuildInputs",
"[ nodejs tree-sitter ]",
"--postFetch",
"pushd $out && tree-sitter generate && popd",
]
generated += """
nativeBuildInputs = [ nodejs tree-sitter ];
postFetch = "pushd $out && tree-sitter generate && popd";"""
hash = subprocess.check_output(cmd, text=True).strip()
generated += f"""
@@ -100,6 +87,10 @@ def generate_grammar(item):
generated += f"""
location = "{location}";"""
if info.get("requires_generate_from_grammar"):
generated += """
generate = true;"""
generated += """
};
"""
@@ -109,7 +100,7 @@ def generate_grammar(item):
generated_file = """# generated by pkgs/applications/editors/vim/plugins/nvim-treesitter/update.py
{ buildGrammar, fetchFromGitHub, fetchFromGitLab, fetchgit, nodejs, tree-sitter }:
{ buildGrammar, fetchFromGitHub, fetchFromGitLab, fetchgit }:
{
"""
@@ -1,4 +1,5 @@
{ stdenv
, nodejs
, tree-sitter
, lib
}:
@@ -13,35 +14,38 @@
# source for the language grammar
, source
, location ? null
, generate ? false,
}:
stdenv.mkDerivation rec {
pname = "${language}-grammar";
inherit version;
src = if location == null then source else "${source}/${location}";
src = source;
buildInputs = [ tree-sitter ];
nativeBuildInputs = lib.optionals generate [ nodejs tree-sitter ];
dontUnpack = true;
dontConfigure = true;
CFLAGS = [ "-I${src}/src" "-O2" ];
CXXFLAGS = [ "-I${src}/src" "-O2" ];
CFLAGS = [ "-Isrc" "-O2" ];
CXXFLAGS = [ "-Isrc" "-O2" ];
stripDebugList = [ "parser" ];
configurePhase = lib.optionalString generate ''
tree-sitter generate
'' + lib.optionalString (location != null) ''
cd ${location}
'';
# When both scanner.{c,cc} exist, we should not link both since they may be the same but in
# different languages. Just randomly prefer C++ if that happens.
buildPhase = ''
runHook preBuild
if [[ -e "$src/src/scanner.cc" ]]; then
$CXX -fPIC -c "$src/src/scanner.cc" -o scanner.o $CXXFLAGS
elif [[ -e "$src/src/scanner.c" ]]; then
$CC -fPIC -c "$src/src/scanner.c" -o scanner.o $CFLAGS
if [[ -e src/scanner.cc ]]; then
$CXX -fPIC -c src/scanner.cc -o scanner.o $CXXFLAGS
elif [[ -e src/scanner.c ]]; then
$CC -fPIC -c src/scanner.c -o scanner.o $CFLAGS
fi
$CC -fPIC -c "$src/src/parser.c" -o parser.o $CFLAGS
$CC -fPIC -c src/parser.c -o parser.o $CFLAGS
$CXX -shared -o parser *.o
runHook postBuild
'';
@@ -50,8 +54,8 @@ stdenv.mkDerivation rec {
runHook preInstall
mkdir $out
mv parser $out/
if [[ -d "$src/queries" ]]; then
cp -r $src/queries $out/
if [[ -d queries ]]; then
cp -r queries $out
fi
runHook postInstall
'';