From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id QO12M3vitmEhUgEAgWs5BA (envelope-from ) for ; Mon, 13 Dec 2021 07:04:43 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id eI5CL3vitmEFYwAAB5/wlQ (envelope-from ) for ; Mon, 13 Dec 2021 06:04:43 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 774C82C500 for ; Mon, 13 Dec 2021 07:04:43 +0100 (CET) Received: from localhost ([::1]:42450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mweS1-000316-Em for larch@yhetil.org; Mon, 13 Dec 2021 01:04:42 -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 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1639375483; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=teAJKTWNnkKR3SVaIcZCGsnlAr4obIHoNhyOOMkV1fc=; b=qej3fHejUIwHegfetZXHP5P2TYUK9R/HYhZudX4lomu5WU8Fp3hS+acp/vA7KRjWcM+wJC qn5sgmRZgfOx6iDV0mR9FYbF2oOokCDl0VmtK54e1dx+m33FWg8ABO6RjcMzZmo3LfUleS mu7q3vR/JiqUeFFsidqeh8nBmnpF8MOYTRUWD58D25Q+wjQxyvJGAG1+Ey1p3XS58L2uge vlZZgNZTD4ilKe9O2w6jKaYhcgRuY/WKXhNpjTE1R/hrPbmzDEY7lNg0YTF76GTAqVd7m9 tI3+TA1sz/sA2q2rBCkZpR6kfvPrNhWC0xLEeyWJ9bdgq/Vu+d7LM3ZubAEFAQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1639375483; a=rsa-sha256; cv=none; b=PQ5je5+jWOz1OTpa1btT+ZFxD8ncjGoduAQrX7oc1h7rPntvIB46kEzoozurVf/44wgVt+ YgX+3k7Y1gkKi9fTBy6mdqW9pPC5sGGXPXH8Xt6AkPSPjd+sKqPWW5qQrIAH8Aua+O3j99 Ib/r6vgoafNkYRo2+OFeVqhhrk2EQlsaYdn+MwBVr3N6WDLZnTG17TjvUWSuPY4RADw4IS t5g23ktWFRkmPaF+eGkFG1Lg3HGaVIEV3fIbA2MCUP8A33lWLTsLtshqXqrKLwvWRtOQcR 5lURf7HhggZBYOdpTJNRvlP3aKcIhdC3RbiL7jP6spYijFdcUFE7z5iXIomyrA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b="Bg5y8/GR"; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 1.03 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b="Bg5y8/GR"; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 774C82C500 X-Spam-Score: 1.03 X-Migadu-Scanner: scn1.migadu.com X-TUID: Y0aMn6wDLvyf * 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) -- 2.32.0