From patchwork Mon Dec 13 06:00:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip McGrath X-Patchwork-Id: 35165 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id F385A27BBEC; Mon, 13 Dec 2021 06:04:38 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 3E91927BBE9 for ; Mon, 13 Dec 2021 06:04:38 +0000 (GMT) Received: from localhost ([::1]:42450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mweRx-000316-9w for patchwork@mira.cbaines.net; Mon, 13 Dec 2021 01:04:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mweRU-0002V0-W6 for guix-patches@gnu.org; Mon, 13 Dec 2021 01:04:09 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:42220) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mweRU-0007KD-KL for guix-patches@gnu.org; Mon, 13 Dec 2021 01:04:08 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mweRT-0002Y1-GK for guix-patches@gnu.org; Mon, 13 Dec 2021 01:04:07 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51838] [PATCH v4 21/45] guix: node-build-system: Add avoid-node-gyp-rebuild phase. Resent-From: Philip McGrath Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 13 Dec 2021 06:04:07 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51838 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51838@debbugs.gnu.org Cc: Timothy Sample , Pierre Langlois , Jelle Licht , Philip McGrath , Liliana Marie Prikler Received: via spool by 51838-submit@debbugs.gnu.org id=B51838.16393754369677 (code B ref 51838); Mon, 13 Dec 2021 06:04:07 +0000 Received: (at 51838) by debbugs.gnu.org; 13 Dec 2021 06:03:56 +0000 Received: from localhost ([127.0.0.1]:53749 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mweRI-0002W0-GP for submit@debbugs.gnu.org; Mon, 13 Dec 2021 01:03:56 -0500 Received: from mail-ua1-f52.google.com ([209.85.222.52]:40489) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mweRC-0002VF-UN for 51838@debbugs.gnu.org; Mon, 13 Dec 2021 01:03:51 -0500 Received: by mail-ua1-f52.google.com with SMTP id y5so27306279ual.7 for <51838@debbugs.gnu.org>; Sun, 12 Dec 2021 22:03:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philipmcgrath.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=teAJKTWNnkKR3SVaIcZCGsnlAr4obIHoNhyOOMkV1fc=; b=Bg5y8/GRfd8s9qcM1HVavO1W5Ec69q5DIAjzC1p89p1sdXgVsqM598OKEySIKNCxJa VSggd3yKPFVMqqNmLC1UroU4v2BbLFjApApVI5soA469vLEnFekcfRIzYi2iPTCwEDNX kZc/dVv7m421lyUZsE6dsfkRfCYAQchmF1ty7Qgi4gkLL+s2UVHgpfsPzOxutJijRdfJ hfboCZmnhsXMixEJMTcRfLVfkit6ZEJBM++yeXc3nCY1ahpAdwquNLBOVmMJkyDRHvJr F9Amz6XXZtapo2DnmOdPQ6UbgNIy5QrcyhtH9EoD3x9qwok8vOMVWCrcRmEWKEvNeDTe dL2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=teAJKTWNnkKR3SVaIcZCGsnlAr4obIHoNhyOOMkV1fc=; b=4ErhIGRquJ9juilHRY8lZVY7IqIPOKSreIndP0yL74PU9ywUOCD5s2eL4lvsn641Ac aSLZfbtyFXUWyajvgqNJln5y0HJjVqsBII8oYG29Qxe1hHvRFZEbn/qD7+eGdDSX8ITs V9TecsO+ZIgICFSgCVl/XWsfQk8KeeaXuH9PO6MYHoB+GsgfpEhqK3wpXeAkzuOck4l8 BBulz2U9rEsHJ2Kc4TQEOj6MhzmSNaSHYMKuIkE+fSMKusNXxHeNm2qfLU5iDlvd0Iiq yx2qkuWgVOZbOu2fK3acSj28PIOdFoDgmCmTCLd4XRe3Xb8wPDPtxnQ5gnKjm7mZu+VG oQ6w== X-Gm-Message-State: AOAM533P1OUgEaQroVqndS+zhC8QP9EXVJkqw2AVWfsYIaCqs3TkNHai ZUaX5u8Hb6FAWpjpeb22CrfMVfRigQN5KaJ+xlE= X-Google-Smtp-Source: ABdhPJx3yJv2WvlvI3pGHKZTv4Tun13hUuhgCfKaUel0mA9Xql3pmUTCkVVNXP3b6Gjz/CN9dFlacg== X-Received: by 2002:a67:b103:: with SMTP id w3mr26364496vsl.84.1639375425392; Sun, 12 Dec 2021 22:03:45 -0800 (PST) Received: from localhost (c-73-125-89-242.hsd1.fl.comcast.net. [73.125.89.242]) by smtp.gmail.com with ESMTPSA id t11sm3708225vkt.34.2021.12.12.22.03.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Dec 2021 22:03:45 -0800 (PST) From: Philip McGrath Date: Mon, 13 Dec 2021 01:00:43 -0500 Message-Id: <20211213060107.129223-22-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211213060107.129223-1-philip@philipmcgrath.com> References: <46a042bc08eb72a068b1e8c69bfe28cf2d4b2e53.camel@gmail.com> <20211208202838.752542-1-philip@philipmcgrath.com> <20211208202838.752542-5-philip@philipmcgrath.com> <877dc924h7.fsf@gmx.com> <5c62c3ce-dd50-5dcd-00ed-ff1524be4e0b@philipmcgrath.com> <20211213060107.129223-1-philip@philipmcgrath.com> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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 | 59 +++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm index 892104b6d2..f9ca515d58 100644 --- a/guix/build/node-build-system.scm +++ b/guix/build/node-build-system.scm @@ -175,6 +175,62 @@ (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 + (let* ((package.json (string-append + (assoc-ref outputs "out") + "/lib/node_modules/" + (match (call-with-input-file "package.json" read-json) + (('@ . alist) + (assoc-ref alist "name"))) + "/package.json")) + (meta-alist (match (call-with-input-file package.json read-json) + (('@ . alist) + alist))) + (scripts-alist (match (assoc-ref meta-alist "scripts") + (('@ . alist) + alist) + (#f + #f)))) + (when (and scripts-alist + (equal? "node-gyp rebuild" (assoc-ref scripts-alist "install"))) + (call-with-output-file package.json + (lambda (out) + (write-json + (cons '@ (assoc-set! + meta-alist + "scripts" + (cons '@ (assoc-set! + scripts-alist + "install" + "echo Guix: avoiding node-gyp rebuild")))) + out)))) + #t)) + (define %standard-phases (modify-phases gnu:%standard-phases (add-after 'unpack 'set-home set-home) @@ -184,7 +240,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)