diff mbox series

[bug#54021] Adding rhino package, revised patch

Message ID 87mtiqqd7k.fsf@gmail.com
State Accepted
Headers show
Series [bug#54021] Adding rhino package, revised patch | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

Frank Pursel Feb. 17, 2022, 5:22 a.m. UTC
Hi,

I've incorporated the feedback I've receive so far and worked to get the
check phase to complete successfully but this effort is complicated by
the default use of benchmarking and instrumentation.  I don't think this
additional instrumentation is appropriate to the check phase of this
package.  I can get testing to naively succeed using an alternate target
but because this version of the software has had longterm and widespread
experience I recommend that we simply be honest and set tests? to #f.
That is what I've done here.  Comments in the source describe choices I
made that you might decide are undesirable.

Let me know what you think.

Regards,
Frank

From 84848769a9c40e770d7a29edf200292a04bdcb2e Mon Sep 17 00:00:00 2001
Message-Id: <84848769a9c40e770d7a29edf200292a04bdcb2e.1645075292.git.frank.pursel@gmail.com>
From: Frank Pursel <frank.pursel@gmail.com>
Date: Tue, 15 Feb 2022 14:07:28 -0800
Subject: [PATCH] Adding rhino javascript guix package.

       * guix/gnu/package/javascript.scm (rhino): Added package.
---
 gnu/packages/javascript.scm | 105 +++++++++++++++++++++++++++++++++++-
 1 file changed, 104 insertions(+), 1 deletion(-)

Comments

M Feb. 21, 2022, 4:28 p.m. UTC | #1
Frank Pursel schreef op wo 16-02-2022 om 21:22 [-0800]:
> +                    ;; Identify bundled jars to maintain build purity
> +                    ;; remove bundled jars but those for testing

Jars for testing need to be removed too, they could influence the build
by modifying source files etc. when run.

Also, some licenses (e.g. GPL) require you to to publish the source
code whenever binaries are published.  I don't know if this is the
case for the bundled jars, rhino or dependents of rhino, but it's
simplest to just remove the binaries.

Greetings,
Maxime.
diff mbox series

Patch

diff --git a/gnu/packages/javascript.scm b/gnu/packages/javascript.scm
index c453ac432a..3068ce8197 100644
--- a/gnu/packages/javascript.scm
+++ b/gnu/packages/javascript.scm
@@ -6,6 +6,7 @@ 
 ;;; Copyright © 2018 Nicolas Goaziou <mail@nicolasgoaziou.fr>
 ;;; Copyright © 2021 Pierre Neidhardt <mail@ambrevar.xyz>
 ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2022 Frank Pursel <frank.pursel@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -31,6 +32,9 @@  (define-module (gnu packages javascript)
   #:use-module (gnu packages readline)
   #:use-module (gnu packages uglifyjs)
   #:use-module (gnu packages web)
+  #:use-module (gnu packages java)
+  #:use-module (gnu packages bash)
+  #:use-module (gnu packages perl)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix git-download)
@@ -38,7 +42,9 @@  (define-module (gnu packages javascript)
   #:use-module (guix build-system cmake)
   #:use-module (guix build-system trivial)
   #:use-module (guix build-system minify)
-  #:use-module (guix utils))
+  #:use-module (guix build-system ant)
+  #:use-module (guix utils)
+  #:use-module (guix gexp))
 
 (define-public cjson
   (package
@@ -788,3 +794,100 @@  (define-public duktape
 your build, and use the Duktape API to call ECMAScript functions from C code
 and vice versa.")
     (license license:expat)))
+
+(define-public rhino
+  (let* ((rel-ver "1.7.7.2")
+         (commit "935942527ff434b205e797df4185518e5369466e"))
+    (package
+      (name "rhino")
+      (version rel-ver)
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/mozilla/rhino.git")
+                      (commit commit)))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32 "09i4yr98hs6855fs7fhgmrpiwpr90lhxdv2bvfj97nn4rv1d7wl8"))
+                (modules '((guix build utils)))
+                (snippet
+                 '(begin
+                    ;; Identify bundled jars to maintain build purity
+                    ;; remove bundled jars but those for testing
+                    ;; all appear to be for testing or unused build system
+                    ;;
+                    ;; source/rhino [env]$ find . -name '*.jar'
+                    ;; ./testsrc/org/mozilla/javascript/tests/commonjs/module/modules.jar
+                    ;; ./testsrc/tests/src/jstests.jar
+                    ;; ./gradle/wrapper/gradle-wrapper.jar
+                    (format #t "~%~a~%" "Sourced jars")
+                    (for-each
+                     (lambda (f) (format #t "~/~a~%" f))
+                     (find-files "." ".*\\.jar$"))
+                    #t))))
+      (build-system ant-build-system)
+      (inputs (list bash-minimal))
+      (native-inputs (list java-junit
+                           java-hamcrest-core
+                           java-snakeyaml     ;Required for tests.
+                           perl               ;Required for 'jsdriver' check target.
+                           ))
+      (arguments
+       `(#:tests? #f
+                 ;; tests? currently fail
+                 ;; the 'junit' target defaults to impure instrumentation and benchmarking.
+                 ;; there is another target 'jsdriver' of unknown scope which succeeds
+                 ;; As this pkg+ver has seen longstanding use, tests? are disabled.
+         #:phases (modify-phases %standard-phases
+                    (replace 'check
+                      (lambda* (#:key tests? inputs native-inputs #:allow-other-keys)
+                        (when tests?
+                          (setenv "ANT_OPTS" "-Doffline=true")
+                          (let ((junit-lib (assoc-ref inputs "java-junit"))
+                                (hamcrest-lib (assoc-ref inputs "java-hamcrest-core"))
+                                (snakeyaml-lib (assoc-ref inputs "java-snakeyaml")))
+                            (with-directory-excursion "testsrc"
+                              (substitute* "build.xml"
+                                (("<pathelement location=\"\\$\\{xbean.jar\\}\" */>" all)
+                                 (string-append "<!-- " all " -->"))
+                                (("<pathelement location=\"\\$\\{jsr173.jar\\}\" */>" all)
+                                 (string-append "<!-- " all " -->"))
+                                (("<pathelement path=\"\\$\\{coverage.classes.dir\\}\" */>" all)
+                                 (string-append "<!-- " all " -->"))
+                                (("<pathelement path=\"lib/emma.jar\"/>" all)
+                                 (string-append "<!-- " all " -->"))
+                                (("<pathelement path=\"lib/junit.jar\" ?/>")
+                                 (string-append "<fileset dir=\"" junit-lib
+                                                "\" includes=\"**/*.jar\"/>"))
+                                (("<pathelement path=\"lib/hamcrest.jar\" ?/>")
+                                 (string-append "<fileset dir=\"" hamcrest-lib
+                                                "\" includes=\"**/*.jar\"/>"))
+                                (("<pathelement path=\"lib/snakeyaml.jar\" ?/>")
+                                 (string-append "<fileset dir=\"" snakeyaml-lib
+                                                "\" includes=\"**/*.jar\"/>"))))
+                            ;; Check could alternatively invoke the jsdriver target here.
+                          (invoke "ant" "junit")))))
+                    (replace 'install
+                      (lambda* (#:key inputs outputs #:allow-other-keys)
+                        (let* ((out (assoc-ref outputs "out"))
+                               (pkg+ver (string-append ,name ,version))
+                               (bin (string-append out "/bin"))
+                               (rhino (string-append bin "/rhino")))
+                          (mkdir-p bin)
+                          (install-file (string-append "build/" pkg+ver
+                                                       "/js.jar")
+                                        (string-append out "/share/java"))
+                          (with-output-to-file rhino
+                            (lambda _
+                              (format #t "#!~a~%~a -jar ~a~%"
+                                      (search-input-file inputs "/bin/bash")
+                                      (search-input-file inputs "/bin/java")
+                                      (string-append out "/share/java/js.jar"))))
+                          (chmod rhino #o755)))))))
+      (home-page "https://mozilla.github.io/rhino")
+      (synopsis "Javascript implemented in Java")
+      (description
+       "Rhino implements ECMAScript, also known as JavaScript, in Java as
+specified in the fifth edition of ECMA-262")
+      (license license:mpl2.0))))
+