Subject: [PATCH 13/15] gnu: Add java-tunnelvisionlabs-antlr4-runtime.

From: Julien Lepiller <[email-masked]>
Date: Sun, 27 Sep 2020 00:18:22 +0200

* gnu/packages/java.scm (java-tunnelvisionlabs-antlr4-runtime): New
variable.
---
 gnu/packages/java.scm | 73 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/gnu/packages/java.scm b/gnu/packages/java.scm
index 73a5fbd693..83d26c4ab4 100644
--- a/gnu/packages/java.scm
+++ b/gnu/packages/java.scm
@@ -8558,6 +8558,79 @@ parse trees.")))
     (description "This package contains annotations used during the build of
 the runtime library of ANTLR.")))
 
+(define java-tunnelvisionlabs-antlr4-runtime-bootstrap
+  (package
+    (inherit java-antlr4-runtime)
+    (name "java-tunnelvisionlabs-antlr4-runtime")
+    (version (package-version java-tunnelvisionlabs-antlr4-runtime-annotations))
+    (source (package-source java-tunnelvisionlabs-antlr4-runtime-annotations))
+    (arguments
+     `(#:jar-name "java-antlr4-runtime.jar"
+       #:source-dir "runtime/Java/src"
+       #:tests? #f; tests require antlr4, but antlr4 depends on this package
+       #:phases
+       (modify-phases %standard-phases
+         (add-before 'build 'generate-xpath-lexer
+           (lambda _
+             (invoke "antlr4" "-lib" "runtime/Java/src/org/antlr/v4/runtime/tree/xpath"
+                     "-visitor" "-no-listener"
+                     "-package" "org.antlr.v4.runtime.tree.xpath"
+                     "runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPathLexer.g4")
+             ;; Generated code is for an incompatible version of the runtime
+             (substitute* "runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPathLexer.java"
+               (("LexerATNSimulator\\(this,_ATN,_decisionToDFA,_sharedContextCache\\)")
+                "LexerATNSimulator(this,_ATN)"))
+             #t))
+         (add-before 'build 'copy-resources
+           (lambda _
+             (copy-recursively "runtime/Java/src/main/dot"
+                               "build/classes")
+             #t)))))
+    (native-inputs
+     `(("antlr4" ,antlr4-4.1)
+       ("java-tunnelvisionlabs-antlr4-runtime-annotations"
+        ,java-tunnelvisionlabs-antlr4-runtime-annotations)))))
+
+(define java-tunnelvisionlabs-antlr4-bootstrap
+  (package
+    (inherit antlr4)
+    (name "java-tunnelvisionlabs-antlr4")
+    (version (package-version java-tunnelvisionlabs-antlr4-runtime-annotations))
+    (source (package-source java-tunnelvisionlabs-antlr4-runtime-annotations))
+    (arguments
+     (substitute-keyword-arguments (package-arguments antlr4)
+       ((#:test-dir _)
+        "tool/test:runtime-testsuite/src")
+       ((#:phases phases)
+        `(modify-phases ,phases
+           (delete 'remove-unrelated-languages)
+           (delete 'remove-graphemes)
+           (delete 'generate-test-parsers)
+           (delete 'check)))))
+    (native-inputs '())
+    (inputs
+     `(("antlr3" ,antlr3)
+       ("java-antlr4-runtime" ,java-tunnelvisionlabs-antlr4-runtime-bootstrap)
+       ("java-tunnelvisionlabs-antlr4-runtime-annotations"
+        ,java-tunnelvisionlabs-antlr4-runtime-annotations)
+       ("java-icu4j" ,java-icu4j)
+       ("java-jsonp-api" ,java-jsonp-api)
+       ("java-stringtemplate" ,java-stringtemplate)
+       ("java-treelayout" ,java-treelayout)))))
+
+(define-public java-tunnelvisionlabs-antlr4-runtime
+  (package
+    (inherit java-tunnelvisionlabs-antlr4-runtime-bootstrap)
+    (native-inputs
+      (map
+        (match-lambda
+          ((name package)
+           (if (equal? name "antlr4")
+               (list name java-tunnelvisionlabs-antlr4-bootstrap)
+               (list name package))))
+        (package-native-inputs java-tunnelvisionlabs-antlr4-runtime-bootstrap)))))
+
+
 (define-public java-commons-cli-1.2
   ;; This is a bootstrap dependency for Maven2.
   (package
-- 
2.28.0