about summary refs log tree commit diff
path: root/pkgs/tools/text/diffsitter
diff options
context:
space:
mode:
authorBruno Bigras <bigras.bruno@gmail.com>2021-07-20 14:10:15 -0400
committerBruno Bigras <bigras.bruno@gmail.com>2022-10-19 23:00:45 -0400
commit56f6d6337ed5d1227d63558318c4d5da211ba338 (patch)
tree7f746350c96eb3b315b367571084450e47c0220a /pkgs/tools/text/diffsitter
parentd3c2379d149073e53eb5580deafad475c1cabe28 (diff)
diffsitter: init at 0.7.1
Diffstat (limited to 'pkgs/tools/text/diffsitter')
-rw-r--r--pkgs/tools/text/diffsitter/default.nix77
1 files changed, 77 insertions, 0 deletions
diff --git a/pkgs/tools/text/diffsitter/default.nix b/pkgs/tools/text/diffsitter/default.nix
new file mode 100644
index 0000000000000..f649f8d838e44
--- /dev/null
+++ b/pkgs/tools/text/diffsitter/default.nix
@@ -0,0 +1,77 @@
+{ lib
+, fetchFromGitHub
+, linkFarm
+, makeWrapper
+, rustPlatform
+, tree-sitter
+}:
+
+let
+  # based on https://github.com/NixOS/nixpkgs/blob/aa07b78b9606daf1145a37f6299c6066939df075/pkgs/development/tools/parsing/tree-sitter/default.nix#L85-L104
+  withPlugins = grammarFn:
+    let
+      grammars = grammarFn tree-sitter.builtGrammars;
+    in
+    linkFarm "grammars"
+      (map
+        (drv:
+          let
+            name = lib.strings.getName drv;
+          in
+          {
+            name =
+              "lib" +
+              (lib.strings.removeSuffix "-grammar" name)
+              + ".so";
+            path = "${drv}/parser";
+          }
+        )
+        grammars);
+
+  libPath = withPlugins (_: tree-sitter.allGrammars);
+in
+rustPlatform.buildRustPackage rec {
+  pname = "diffsitter";
+  version = "0.7.1";
+
+  src = fetchFromGitHub {
+    owner = "afnanenayet";
+    repo = pname;
+    rev = "v${version}";
+    sha256 = "sha256-fDuJMpMseGVKfgg/ERb7dHUZ9n5McYVJLBvuroLZDqE=";
+    fetchSubmodules = false;
+  };
+
+  cargoSha256 = "sha256-HmL7Xopj0gSokjyQY4Umy+5HKUKdRdBE7glMbrsk00c=";
+
+  buildNoDefaultFeatures = true;
+  buildFeatures = [
+    "dynamic-grammar-libs"
+    # "better-build-info"
+  ];
+
+  nativeBuildInputs = [
+    makeWrapper
+  ];
+
+  postInstall = ''
+    wrapProgram "$out/bin/diffsitter" \
+      --prefix LD_LIBRARY_PATH : "${libPath}"
+  '';
+
+  doCheck = false;
+  # failures:
+  #     tests::diff_hunks_snapshot::_medium_cpp_cpp_false_expects
+  #     tests::diff_hunks_snapshot::_medium_cpp_cpp_true_expects
+  #     tests::diff_hunks_snapshot::_medium_rust_rs_false_expects
+  #     tests::diff_hunks_snapshot::_medium_rust_rs_true_expects
+  #     tests::diff_hunks_snapshot::_short_python_py_true_expects
+  #     tests::diff_hunks_snapshot::_short_rust_rs_true_expects
+
+  meta = with lib; {
+    homepage = "https://github.com/afnanenayet/diffsitter";
+    description = "A tree-sitter based AST difftool to get meaningful semantic diffs";
+    license = licenses.mit;
+    maintainers = with maintainers; [ bbigras ];
+  };
+}