From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id GFwLOv7wu2H8NgEAgWs5BA (envelope-from ) for ; Fri, 17 Dec 2021 03:07:58 +0100 Received: from aspmx2.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 6PbMNf7wu2GYVAAA1q6Kng (envelope-from ) for ; Fri, 17 Dec 2021 02:07:58 +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 aspmx2.migadu.com (Postfix) with ESMTPS id EEB1B358C2 for ; Fri, 17 Dec 2021 03:07:57 +0100 (CET) Received: from localhost ([::1]:55116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1my2f6-0006PU-HK for larch@yhetil.org; Thu, 16 Dec 2021 21:07:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1my2dJ-0004B8-Qh for guix-patches@gnu.org; Thu, 16 Dec 2021 21:06:05 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:54053) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1my2dJ-0007zD-Gq for guix-patches@gnu.org; Thu, 16 Dec 2021 21:06:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1my2dJ-0005CG-Ay for guix-patches@gnu.org; Thu, 16 Dec 2021 21:06:05 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51838] [PATCH v5 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: Fri, 17 Dec 2021 02:06:05 +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.163970672919761 (code B ref 51838); Fri, 17 Dec 2021 02:06:05 +0000 Received: (at 51838) by debbugs.gnu.org; 17 Dec 2021 02:05:29 +0000 Received: from localhost ([127.0.0.1]:37330 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1my2ci-00058Y-Vq for submit@debbugs.gnu.org; Thu, 16 Dec 2021 21:05:29 -0500 Received: from mail-qv1-f53.google.com ([209.85.219.53]:40800) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1my2cY-00057c-Jy for 51838@debbugs.gnu.org; Thu, 16 Dec 2021 21:05:19 -0500 Received: by mail-qv1-f53.google.com with SMTP id eq6so1036345qvb.7 for <51838@debbugs.gnu.org>; Thu, 16 Dec 2021 18:05:18 -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=E5bMjI/DdRLMg3CPgVJv0hK6CYkzmi9vFxHDgLgshAySH2tmVlrHIWVdar+tbbCuay zkg99ACEpIgWZNvVK7Z95px2Z+I4GDOBSBkxs1QqoAwq8Dr7MDtvJ0kA5s4M53IK7pkH yDp/2ikHYl5uTB0wl+e+ELzr384SaFX98mdnu5zOeNmM+Gnkap0sAJCzTOomVbUE9M6n PnEqQCrfhn0A5pcIWjzlcwpP0hZd44nPlOzurO+Fp26eTqi3qeHaNTtLaFKTwY5p5Onu /BhRjuVi1Rt8qpLfysrgapPeuUPHBXbEcYNy3G15vIgX59yna4sw7zFU0f6GiQ5lDNIQ cZGw== 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=FmEnQIevGz7g8Gpwuecq8+SC1QSfxmwFxqjPbMZKaRZy433XBXUTKPWWPRekDOxLRV eHzpGbF5lmCagyxDJ10Za4D2G8wcX/wezfljkWdXjnTkLUD54kUxfY4PDOLTsnyJ7YYM pfMcaUaOePld01ULGkMR+O4nYNOFdCb9FLxKFB0EfJ9mDChPXg0BFhmvblC81aokRlmc TTSTrc7r5CPQfqPAIJPEOX3cpEI/4KFgRO8AVTMFXk3+rAGFFWGkNHdONcOqiAOL9tEI mqLmJWcpw4G8NOX5Z4nNA0iAD4k+Oi/HdQJAXMGhrdl8a9FK0uMMJY5pN85IsgjNSeLW 8Ltw== X-Gm-Message-State: AOAM532H51D+uQOhyYvn6Fy1WoFWPvd47dSoArk8IK5FIqYrJhUeKiIx XaqVjmSXb2LwLuAb5HEzpiTeqDSe9XvNQlD99tg= X-Google-Smtp-Source: ABdhPJyH989kZUc4QwB6QYpJQP7l6SyRsevv00lOmORcBTufauYrv+UKqeeMvSISsC9b0iU39dwdgg== X-Received: by 2002:ad4:5365:: with SMTP id e5mr552742qvv.127.1639706713220; Thu, 16 Dec 2021 18:05:13 -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 s4sm3990486qko.47.2021.12.16.18.05.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Dec 2021 18:05:12 -0800 (PST) From: Philip McGrath Date: Thu, 16 Dec 2021 21:03:01 -0500 Message-Id: <20211217020325.520821-22-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211217020325.520821-1-philip@philipmcgrath.com> References: <20211213060107.129223-1-philip@philipmcgrath.com> <20211217020325.520821-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 X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1639706878; 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=qJjtHCbQH8EPXkjmg5W6v/QxdHm0mntaz+/iTC8P5A3rzpeo0B7w0fgBdWKGQry+5FFDW8 7LNbax519T4UNS7uYXMuUmoFtmEexG50OkEtgsl1+ElEngHzwy/SrI1Dh3JhzknDqMhgaM fd1KeXmmSbxMBMrzZSijdnow6h9Z+300kprSDZgxPFmynDSG6XzfXgNwA7hs5GYvmjz/Cm UIxBhz2uMvUjFiKKz62D11bwwLlVm1HbFwb4mXSI4M6HTKzwVYOcQnQZttkkfDjcBu/h6Q jbtU5M9yLdsfygomZkmFcj2EsSUKC2vgtBI8VZenh8rRd8coOeed8tAnjP6BCQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1639706878; a=rsa-sha256; cv=none; b=hCT5T3pPnhSRBhAazjNG3Y3SLNyI7RLc+ikbbFDy3b4iSWEH3Rzelup60tV3n9v1ChG1aU cwXzP+0XByu0IxUn9kGPBw9pX4J9oQQ73Te5FWetWw4C/X+WiACUUmjSC0knb6UZhDSnFB /k6PwFDQVPx9G02Wcqm0N1jyDKI4PtGEqlXjECzWepzEMmHE2AmcL1dKiaZvdYTBqhywvZ d1S5S7bantcp+4M++xFo0Bljvnri+rhVi02PNkB19kP6tLJr4rXAFp0ozL1mzlOnls3Rvf 5URj3RkquWCPth29wjh4Q3noLm4NX3wOKqqOlQXmGt1MZSTSwzcBqMqDg2Q8OA== ARC-Authentication-Results: i=1; aspmx2.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b="E5bMjI/D"; dmarc=none; spf=pass (aspmx2.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: 0.30 Authentication-Results: aspmx2.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b="E5bMjI/D"; dmarc=none; spf=pass (aspmx2.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: EEB1B358C2 X-Spam-Score: 0.30 X-Migadu-Scanner: scn1.migadu.com X-TUID: +aeDljIlXS+G * 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