summary refs log tree commit diff
path: root/pkgs/development/tools/parsing
diff options
context:
space:
mode:
authorBryan Tan <bryantan@technius.net>2022-10-21 22:39:37 -0700
committerBryan Tan <bryantan@technius.net>2022-10-21 22:45:25 -0700
commit98b114eee2bd625d3172724ca68ae988774b1360 (patch)
tree1164fc85dd34d4d30fe47b3bcdf5592f96b6634f /pkgs/development/tools/parsing
parenta195a65efe8fd561c256eaea2c9c2076f8ce4220 (diff)
antlr4: simplify package definitions
This does not require a rebuild.
Diffstat (limited to 'pkgs/development/tools/parsing')
-rw-r--r--pkgs/development/tools/parsing/antlr/4.nix139
1 files changed, 67 insertions, 72 deletions
diff --git a/pkgs/development/tools/parsing/antlr/4.nix b/pkgs/development/tools/parsing/antlr/4.nix
index cae89e63c3b04..3dbcda7e18ec4 100644
--- a/pkgs/development/tools/parsing/antlr/4.nix
+++ b/pkgs/development/tools/parsing/antlr/4.nix
@@ -1,5 +1,8 @@
 { lib, stdenv, fetchurl, jre
-, fetchFromGitHub, cmake, ninja, pkg-config, darwin
+, fetchFromGitHub, cmake, ninja, pkg-config
+
+# darwin only
+, CoreFoundation ? null
 
 # ANTLR 4.8 & 4.9
 , libuuid
@@ -9,7 +12,12 @@
 
 let
 
-  mkAntlr = { version, sourceSha256, jarSha256 }: lib.fixedPoints.makeExtensible (self: {
+  mkAntlr = {
+    version, sourceSha256, jarSha256,
+    extraCppPatchFlags ? [],
+    extraCppBuildInputs ? [],
+    extraCppCmakeFlags ? []
+  }: rec {
     source = fetchFromGitHub {
       owner = "antlr";
       repo = "antlr4";
@@ -45,8 +53,8 @@ let
       inherit jre;
 
       passthru = {
-        inherit (self) runtime;
-        jarLocation = "${self.antlr}/share/java/antlr-${version}-complete.jar";
+        inherit runtime;
+        jarLocation = "${antlr}/share/java/antlr-${version}-complete.jar";
       };
 
       meta = with lib; {
@@ -69,18 +77,26 @@ let
       cpp = stdenv.mkDerivation {
         pname = "antlr-runtime-cpp";
         inherit version;
-        src = self.source;
+        src = source;
 
         outputs = [ "out" "dev" "doc" ];
 
-        nativeBuildInputs = [ cmake ninja pkg-config ];
-        buildInputs =
-          lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.CoreFoundation;
-
         postUnpack = ''
           export sourceRoot=$sourceRoot/runtime/Cpp
         '';
 
+        patchFlags =
+          if extraCppPatchFlags == []
+          then null
+          else extraCppPatchFlags;
+
+        nativeBuildInputs = [ cmake ninja pkg-config ];
+        buildInputs =
+          lib.optional stdenv.isDarwin CoreFoundation ++
+          extraCppBuildInputs;
+
+        cmakeFlags = extraCppCmakeFlags;
+
         meta = with lib; {
           description = "C++ target for ANTLR 4";
           homepage = "https://www.antlr.org/";
@@ -89,69 +105,48 @@ let
         };
       };
     };
-  });
+  };
 
 in {
-  antlr4_11 = (
-    (mkAntlr {
-      version = "4.11.1";
-      sourceSha256 = "sha256-SUeDgfqLjYQorC8r/CKlwbYooTThMOILkizwQV8pocc=";
-      jarSha256 = "sha256-YpdeGStK8mIrcrXwExVT7jy86X923CpBYy3MVeJUc+E=";
-    }).extend (self: super: {
-      runtime.cpp = super.runtime.cpp.overrideAttrs {
-        cmakeFlags = [
-          # Generate CMake config files, which are not installed by default.
-          "-DANTLR4_INSTALL=ON"
-
-          # Disable tests, since they require downloading googletest, which is
-          # not available in a sandboxed build.
-          "-DANTLR_BUILD_CPP_TESTS=OFF"
-        ];
-      };
-    })
-  ).antlr;
-
-  antlr4_10 = (
-    (mkAntlr {
-      version = "4.10.1";
-      sourceSha256 = "sha256-Z1P81L0aPbimitzrHH/9rxsMCA6Qn3i42jFbUmVqu1E=";
-      jarSha256 = "sha256-QZSdQfINMdW4J3GHc13XVRCN9Ss422yGUQjTOCBA+Rg=";
-    }).extend (self: super: {
-      runtime.cpp = super.runtime.cpp.overrideAttrs (attrs: {
-        buildInputs = lib.optional stdenv.isLinux libuuid ++ attrs.buildInputs;
-        cmakeFlags = [
-          "-DANTLR4_INSTALL=ON"
-          "-DANTLR_BUILD_CPP_TESTS=OFF"
-        ];
-      });
-    })
-  ).antlr;
-
-  antlr4_9 = (
-    (mkAntlr {
-      version = "4.9.3";
-      sourceSha256 = "1af3cfqwk7lq1b5qsh1am0922fyhy7wmlpnrqdnvch3zzza9n1qm";
-      jarSha256 = "0dnz2x54kigc58bxnynjhmr5iq49f938vj6p50gdir1xdna41kdg";
-    }).extend (self: super: {
-      runtime.cpp = super.runtime.cpp.overrideAttrs (attrs: {
-        patchFlags = [ "-p3" ];
-        buildInputs = [ utf8cpp ]
-          ++ lib.optional stdenv.isLinux libuuid
-          ++ attrs.buildInputs;
-      });
-    })
-  ).antlr;
-
-  antlr4_8 = (
-    (mkAntlr {
-      version = "4.8";
-      sourceSha256 = "1qal3add26qxskm85nk7r758arladn5rcyjinmhlhznmpbbv9j8m";
-      jarSha256 = "0nms976cnqyr1ndng3haxkmknpdq6xli4cpf4x4al0yr21l9v93k";
-    }).extend (self: super: {
-      runtime.cpp = super.runtime.cpp.overrideAttrs (attrs: {
-        cmakeFlags = ["-DANTLR4_INSTALL=ON"];
-        buildInputs = lib.optional stdenv.isLinux libuuid ++ attrs.buildInputs;
-      });
-    })
-  ).antlr;
+  antlr4_11 = (mkAntlr {
+    version = "4.11.1";
+    sourceSha256 = "sha256-SUeDgfqLjYQorC8r/CKlwbYooTThMOILkizwQV8pocc=";
+    jarSha256 = "sha256-YpdeGStK8mIrcrXwExVT7jy86X923CpBYy3MVeJUc+E=";
+    extraCppCmakeFlags = [
+      # Generate CMake config files, which are not installed by default.
+      "-DANTLR4_INSTALL=ON"
+
+      # Disable tests, since they require downloading googletest, which is
+      # not available in a sandboxed build.
+      "-DANTLR_BUILD_CPP_TESTS=OFF"
+    ];
+  }).antlr;
+
+  antlr4_10 = (mkAntlr {
+    version = "4.10.1";
+    sourceSha256 = "sha256-Z1P81L0aPbimitzrHH/9rxsMCA6Qn3i42jFbUmVqu1E=";
+    jarSha256 = "sha256-QZSdQfINMdW4J3GHc13XVRCN9Ss422yGUQjTOCBA+Rg=";
+    extraCppBuildInputs = lib.optional stdenv.isLinux libuuid;
+    extraCppCmakeFlags = [
+      "-DANTLR4_INSTALL=ON"
+      "-DANTLR_BUILD_CPP_TESTS=OFF"
+    ];
+  }).antlr;
+
+  antlr4_9 = (mkAntlr {
+    version = "4.9.3";
+    sourceSha256 = "1af3cfqwk7lq1b5qsh1am0922fyhy7wmlpnrqdnvch3zzza9n1qm";
+    jarSha256 = "0dnz2x54kigc58bxnynjhmr5iq49f938vj6p50gdir1xdna41kdg";
+    extraCppPatchFlags = [ "-p3" ];
+    extraCppBuildInputs = [ utf8cpp ]
+      ++ lib.optional stdenv.isLinux libuuid;
+  }).antlr;
+
+  antlr4_8 = (mkAntlr {
+    version = "4.8";
+    sourceSha256 = "1qal3add26qxskm85nk7r758arladn5rcyjinmhlhznmpbbv9j8m";
+    jarSha256 = "0nms976cnqyr1ndng3haxkmknpdq6xli4cpf4x4al0yr21l9v93k";
+    extraCppBuildInputs = lib.optional stdenv.isLinux libuuid;
+    extraCppCmakeFlags = [ "-DANTLR4_INSTALL=ON" ];
+  }).antlr;
 }