gnu: node: Avoid duplicating build phases.

* gnu/packages/node.scm (node)[arguments]: Split 'patch-files phase
into 'patch-hardcoded-program-references and
'delete-problematic-tests. Adapt 'patch-hardcoded-program-references
and 'configure to work unmodified on node-lts, but don't try to
share 'delete-problematic-tests, because those details seem to change
too much between node versions.
(node, node-lts)[inputs]: Use bash-minimal rather than bash.
(node-lts)[arguments]: Inherit 'patch-hardcoded-program-references,
and 'configure phases from the bootstrap node.
Remove the 'patch-files phase, keeping its remaining
non-inherited work in a new 'replace-llhttp-sources phase.

Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
This commit is contained in:
Philip McGrath 2021-12-16 21:02:41 -05:00 committed by Liliana Marie Prikler
parent ba744faeb1
commit 2d6d881eb3
No known key found for this signature in database
GPG key ID: 442A84B8C70E2F87

View file

@ -10,6 +10,7 @@
;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
;;; Copyright © 2021 Guillaume Le Vaillant <glv@posteo.net>
;;; Copyright © 2021 Philip McGrath <philip@philipmcgrath.com>
;;;
;;; This file is part of GNU Guix.
;;;
@ -106,14 +107,22 @@ (define-public node
#:test-target "test-ci-js"
#:phases
(modify-phases %standard-phases
(add-before 'configure 'patch-files
(add-before 'configure 'patch-hardcoded-program-references
(lambda* (#:key inputs #:allow-other-keys)
;; Fix hardcoded /bin/sh references.
(substitute* '("lib/child_process.js"
"lib/internal/v8_prof_polyfill.js"
"test/parallel/test-child-process-spawnsync-shell.js"
"test/parallel/test-stdio-closed.js"
"test/sequential/test-child-process-emfile.js")
(substitute*
(let ((common
'("lib/child_process.js"
"lib/internal/v8_prof_polyfill.js"
"test/parallel/test-child-process-spawnsync-shell.js"
"test/parallel/test-stdio-closed.js"
"test/sequential/test-child-process-emfile.js"))
;; not in bootstap node:
(sigxfsz "test/parallel/test-fs-write-sigxfsz.js"))
(if (file-exists? sigxfsz)
(cons sigxfsz common)
common))
(("'/bin/sh'")
(string-append "'" (assoc-ref inputs "bash") "/bin/sh'")))
@ -123,7 +132,10 @@ (define-public node
"test/parallel/test-child-process-exec-env.js")
(("'/usr/bin/env'")
(string-append "'" (assoc-ref inputs "coreutils")
"/bin/env'")))
"/bin/env'")))))
(add-after 'patch-hardcoded-program-references
'delete-problematic-tests
(lambda* (#:key inputs #:allow-other-keys)
;; FIXME: These tests fail in the build container, but they don't
;; seem to be indicative of real problems in practice.
@ -218,9 +230,16 @@ (define-public node
(setenv "CXX" ,(cxx-for-target))
(setenv "PKG_CONFIG" ,(pkg-config-for-target))
(apply invoke
(search-input-file (or native-inputs inputs)
"/bin/python")
"configure" flags))))
(let ((inpts (or native-inputs inputs)))
(with-exception-handler
(lambda (e)
(if (search-error? e)
(search-input-file inpts "/bin/python3")
(raise-exception e)))
(lambda ()
(search-input-file inpts "/bin/python"))))
"configure"
flags))))
(add-after 'patch-shebangs 'patch-npm-shebang
(lambda* (#:key outputs #:allow-other-keys)
(let* ((bindir (string-append (assoc-ref outputs "out")
@ -256,7 +275,7 @@ (define-public node
(variable "NODE_PATH")
(files '("lib/node_modules")))))
(inputs
(list bash
(list bash-minimal
coreutils
c-ares
http-parser
@ -705,65 +724,8 @@ (define-public node-lts
libuv "/lib:"
zlib "/lib"
"'],"))))))
(replace 'configure
;; Node's configure script is actually a python script, so we can't
;; run it with bash.
(lambda* (#:key outputs (configure-flags '()) native-inputs inputs
#:allow-other-keys)
(let* ((prefix (assoc-ref outputs "out"))
(xflags ,(if (%current-target-system)
`'("--cross-compiling"
,(string-append
"--dest-cpu="
(match (%current-target-system)
((? (cut string-prefix? "arm" <>))
"arm")
((? (cut string-prefix? "aarch64" <>))
"arm64")
((? (cut string-prefix? "i686" <>))
"ia32")
((? (cut string-prefix? "x86_64" <>))
"x64")
((? (cut string-prefix? "powerpc64" <>))
"ppc64")
(_ "unsupported"))))
''()))
(flags (cons
(string-append "--prefix=" prefix)
(append xflags configure-flags))))
(format #t "build directory: ~s~%" (getcwd))
(format #t "configure flags: ~s~%" flags)
;; Node's configure script expects the CC environment variable to
;; be set.
(setenv "CC_host" "gcc")
(setenv "CXX_host" "g++")
(setenv "CC" ,(cc-for-target))
(setenv "CXX" ,(cxx-for-target))
(setenv "PKG_CONFIG" ,(pkg-config-for-target))
(apply invoke
(search-input-file (or native-inputs inputs)
"/bin/python3")
"configure" flags))))
(replace 'patch-files
(replace 'delete-problematic-tests
(lambda* (#:key inputs #:allow-other-keys)
;; Fix hardcoded /bin/sh references.
(substitute* '("lib/child_process.js"
"lib/internal/v8_prof_polyfill.js"
"test/parallel/test-child-process-spawnsync-shell.js"
"test/parallel/test-fs-write-sigxfsz.js"
"test/parallel/test-stdio-closed.js"
"test/sequential/test-child-process-emfile.js")
(("'/bin/sh'")
(string-append "'" (assoc-ref inputs "bash") "/bin/sh'")))
;; Fix hardcoded /usr/bin/env references.
(substitute* '("test/parallel/test-child-process-default-options.js"
"test/parallel/test-child-process-env.js"
"test/parallel/test-child-process-exec-env.js")
(("'/usr/bin/env'")
(string-append "'" (assoc-ref inputs "coreutils")
"/bin/env'")))
;; FIXME: These tests fail in the build container, but they don't
;; seem to be indicative of real problems in practice.
(for-each delete-file
@ -802,8 +764,9 @@ (define-public node-lts
;; TODO: Regenerate certs instead.
(for-each delete-file
'("test/parallel/test-tls-passphrase.js"
"test/parallel/test-tls-server-verify.js"))
"test/parallel/test-tls-server-verify.js"))))
(add-after 'delete-problematic-tests 'replace-llhttp-sources
(lambda* (#:key inputs #:allow-other-keys)
;; Replace pre-generated llhttp sources
(let ((llhttp (assoc-ref inputs "llhttp")))
(copy-file (string-append llhttp "/src/llhttp.c")
@ -830,7 +793,7 @@ (define-public node-lts
python
util-linux))
(inputs
(list bash
(list bash-minimal
coreutils
c-ares-for-node
icu4c-67