From ac292a1aa102c8ccb687574da467534dd4c43919 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Sat, 26 Sep 2020 21:51:18 +0200 Subject: [PATCH] gnu: Add java-tunnelvisionlabs-antlr4-runtime. * gnu/packages/java.scm (java-tunnelvisionlabs-antlr4-runtime): New variable. --- gnu/packages/java.scm | 76 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/gnu/packages/java.scm b/gnu/packages/java.scm index 0da7e59f4e..7af0dfb521 100644 --- a/gnu/packages/java.scm +++ b/gnu/packages/java.scm @@ -8555,6 +8555,82 @@ parse trees."))) (description "This package contains annotations used during the build of the runtime library of ANTLR."))) +;; the runtime of this library requires a lexer that is generated by antlr4. +;; However, antlr4 itself requires this library at build and run-time. We +;; use antlr4@4.1, the closest version of antlr that doesn't need this +;; bootstrap process, to generate the lexer. The generated lexer is built +;; for the 4.1 runtime, which is slightly different from this runtime. +;; So, we build the runtime with antlr 4.1, with a broken xml lexer, that we +;; use to build antlr4. We then re-use this antlr4 to build the runtime, and +;; the proper, working, runtime to build antlr4 again. +(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 + (alist-replace + "antlr4" (list java-tunnelvisionlabs-antlr4-bootstrap) + (package-native-inputs java-tunnelvisionlabs-antlr4-runtime-bootstrap))))) + (define-public java-commons-cli-1.2 ;; This is a bootstrap dependency for Maven2. (package