[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#51838] [PATCH v7 04/41] guix: node-build-system: Add avoid-node-gyp
From: |
Philip McGrath |
Subject: |
[bug#51838] [PATCH v7 04/41] guix: node-build-system: Add avoid-node-gyp-rebuild phase. |
Date: |
Thu, 30 Dec 2021 02:44:19 -0500 |
* guix/build/node-build-system.scm (avoid-node-gyp-rebuild): New
function. Override the default install script for packages with
native addons to prevent it from attempting to write to the store
when such packages are used.
(%standard-phases): Add 'avoid-node-gyp-rebuild' after 'install'.
---
guix/build/node-build-system.scm | 50 +++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm
index e5c4da5091..dc8b6a41c2 100644
--- a/guix/build/node-build-system.scm
+++ b/guix/build/node-build-system.scm
@@ -380,6 +380,53 @@ (define* (install #:key outputs inputs #:allow-other-keys)
"install" "../package.tgz")
#t))
+(define* (avoid-node-gyp-rebuild #:key outputs #:allow-other-keys)
+ "Adjust the installed 'package.json' to remove an 'install' script that
+would try to run 'node-gyp rebuild'."
+ ;; We want to take advantage of `npm install`'s automatic support for
+ ;; building native addons with node-gyp: in particular, it helps us avoid
+ ;; hard-coding the specifics of how npm's internal copy of node-gyp is
+ ;; currently packaged. However, the mechanism by which the automatic support
+ ;; is implemented causes problems for us.
+ ;;
+ ;; If a package contains a 'binding.gyp' file and does not define an
+ ;; 'install' or 'preinstall' script, 'npm install' runs a default install
+ ;; script consisting of 'node-gyp rebuild'. In our 'install' phase, this
+ ;; implicit 'install' script, if it is applicable, is explicitly added to
+ ;; the "package.json" file. However, if another Guix package were to use a
+ ;; Node.js package with such an 'install' script, the dependent package's
+ ;; build process would fail, because 'node-gyp rebuild' would try to write
+ ;; to the store.
+ ;;
+ ;; Here, if the installed "package.json" defines scripts.install as
+ ;; "node-gyp rebuild", we replace it with a no-op. Importantly, deleting the
+ ;; install script definition would not be enough, because the default
+ ;; install script would cause the same problem.
+ ;;
+ ;; For further details, see:
+ ;; -
https://docs.npmjs.com/cli/v8/configuring-npm/package-json#default-values
+ ;; - https://docs.npmjs.com/cli/v8/using-npm/scripts#best-practices
+ (define installed-package.json
+ (search-input-file outputs (string-append "/lib/node_modules/"
+ (module-name ".")
+ "/package.json")))
+ ;; not with-atomic-json-file-replacement, because we usually don't
+ ;; want or need to overwrite it
+ (define pkg-meta
+ (call-with-input-file installed-package.json read-json))
+ (define scripts
+ (jsobject-ref pkg-meta "scripts" '(@)))
+ (when (equal? "node-gyp rebuild" (jsobject-ref scripts "install" #f))
+ (call-with-output-file installed-package.json
+ (lambda (out)
+ (write-json
+ (jsobject-set pkg-meta
+ "scripts"
+ (jsobject-set scripts
+ "install"
+ "echo Guix: avoiding node-gyp rebuild"))
+ out)))))
+
(define %standard-phases
(modify-phases gnu:%standard-phases
(add-after 'unpack 'set-home set-home)
@@ -389,7 +436,8 @@ (define %standard-phases
(replace 'build build)
(replace 'check check)
(add-before 'install 'repack repack)
- (replace 'install install)))
+ (replace 'install install)
+ (add-after 'install 'avoid-node-gyp-rebuild avoid-node-gyp-rebuild)))
(define* (node-build #:key inputs (phases %standard-phases)
#:allow-other-keys #:rest args)
--
2.32.0
- [bug#51838] [PATCH v6 29/41] gnu: Add node-ms., (continued)
- [bug#51838] [PATCH v6 29/41] gnu: Add node-ms., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v6 30/41] gnu: Add node-debug., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v6 35/41] gnu: Add node-serialport-parser-regex., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v6 33/41] gnu: Add node-serialport-parser-readline., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v6 34/41] gnu: Add node-serialport-bindings., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v6 36/41] gnu: Add node-serialport-parser-ready., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v6 37/41] gnu: Add node-serialport-parser-inter-byte-timeout., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v6 39/41] gnu: Add node-serialport-parser-byte-length., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v6 41/41] gnu: Add node-serialport., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v7 00/41] guix: node-build-system: Support compiling add-ons with node-gyp., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v7 04/41] guix: node-build-system: Add avoid-node-gyp-rebuild phase.,
Philip McGrath <=
- [bug#51838] [PATCH v7 01/41] guix: node-build-system: Add delete-lockfiles phase., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v7 02/41] guix: node-build-system: Add implicit libuv input., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v7 06/41] gnu: node-semver-bootstrap: Use #:absent-dependencies., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v7 03/41] guix: node-build-system: Add JSON utilities., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v7 05/41] guix: node-build-system: Add #:absent-dependencies argument., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v7 07/41] gnu: node-ms-bootstrap: Use #:absent-dependencies., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v7 12/41] gnu: node-llparse-bootstrap: Use #:absent-dependencies., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v7 14/41] gnu: node-wrappy: Use #:absent-dependencies., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v7 13/41] gnu: node-semver: Use #:absent-dependencies., Philip McGrath, 2021/12/30
- [bug#51838] [PATCH v7 19/41] gnu: Add node-safe-buffer., Philip McGrath, 2021/12/30