From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id uIgdEPVizWFPvgAAgWs5BA (envelope-from ) for ; Thu, 30 Dec 2021 08:42:45 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id KFi+DPVizWElSQAAauVa8A (envelope-from ) for ; Thu, 30 Dec 2021 08:42:45 +0100 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 CF40B178CB for ; Thu, 30 Dec 2021 08:42:44 +0100 (CET) Received: from localhost ([::1]:53078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n2q5D-0007N7-Mw for larch@yhetil.org; Thu, 30 Dec 2021 02:42:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n2q4Y-0007J4-S4 for guix-patches@gnu.org; Thu, 30 Dec 2021 02:42:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:39450) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n2q4Y-00080W-I7 for guix-patches@gnu.org; Thu, 30 Dec 2021 02:42:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n2q4Y-0006Yj-GZ for guix-patches@gnu.org; Thu, 30 Dec 2021 02:42:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51838] [PATCH v6 04/41] 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: Thu, 30 Dec 2021 07:42:02 +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.164085007524974 (code B ref 51838); Thu, 30 Dec 2021 07:42:02 +0000 Received: (at 51838) by debbugs.gnu.org; 30 Dec 2021 07:41:15 +0000 Received: from localhost ([127.0.0.1]:50961 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n2q3m-0006Ub-Ao for submit@debbugs.gnu.org; Thu, 30 Dec 2021 02:41:14 -0500 Received: from mail-ua1-f53.google.com ([209.85.222.53]:35764) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n2q3Y-0006Sm-Jt for 51838@debbugs.gnu.org; Thu, 30 Dec 2021 02:41:01 -0500 Received: by mail-ua1-f53.google.com with SMTP id v14so23604777uau.2 for <51838@debbugs.gnu.org>; Wed, 29 Dec 2021 23:41:00 -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=gabsZVpGWF7PrCHsV9bFg142ypKkJ92o164B8EoNLQ0=; b=WdBAPj0d9BXytruu94kh+WwZ8ZOkxeZxnwsvTkDtakBrGZd4/7lI9DVaJuePybxD59 ELy34Ql1AXsWEvhu4cU+l86I+vfVHQAQWLFWhSwD+4Z3k2zH2QDYFirMMK0tj+63m+P0 EeRLO9yMo+QqtHK34q5/cqnziWhvsPPyo1/Le/WylQyibIWFGMgs9ZvDstOuJXI5X5Mq njEWSnhYIGRZszJlcAUVXsxfu+G9Joo4jBKg9w4CjiPCZ6KJa9vG4ZGMt4yT1+1zxcyj f0cw5GepaNIzncvC9oIxvYXDC0tt7x+JrsUJerD/gHhGgzdJVAbLdoPUJ7GXJR7jwJT5 gRDA== 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=gabsZVpGWF7PrCHsV9bFg142ypKkJ92o164B8EoNLQ0=; b=x4jx6aiksWGi6g2JvhnNrIDdzZkPpCxIs3ZItIIiY+AcO97FqMzjcctDcM4mPxllV5 XQd7n0tmdTanKxKNWW6gGZMMsqJcUynN9Ua+VESjff4t4qWsoBrtvYHP6ht1hz1RHH+/ /HQ5nDH10DW7JPkvwaD8eW/5acgylgjjjJUorrJ2h00CtKHTgVu0J+sMxkGtndZm2cpi DKwL2koRAVpbDH6oli3YRi5FFSDkoBR6fgHeZksN7m3jLzBNW58g6yfWoOMBioKcHWAM DOv2VxYP+Q9Q0l0u8YgEOTTJQxygS2jjitCpdm67j1dPrN7v6ZZBjyymgQDIeS342kqh SzQw== X-Gm-Message-State: AOAM533Go3qMFVlJiIJtWtkDeoj06caSO1sIeUUbDkkzk2z6FAq/KyNt 9r00q+FvQWbH3pksH2KgzFTWVf7rHHDNwzNc X-Google-Smtp-Source: ABdhPJwHk73dt6RUgGNC2AC8Bg+XqKxc529GPRSBOzU8XtorRq2CHum/Q5lrrAjKc3Uo6MN1/csrdg== X-Received: by 2002:a9f:3526:: with SMTP id o35mr9637883uao.3.1640850054990; Wed, 29 Dec 2021 23:40:54 -0800 (PST) Received: from localhost (c-73-125-89-242.hsd1.fl.comcast.net. [73.125.89.242]) by smtp.gmail.com with UTF8SMTPSA id k23sm5125495vsm.1.2021.12.29.23.40.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Dec 2021 23:40:54 -0800 (PST) From: Philip McGrath Date: Thu, 30 Dec 2021 02:38:42 -0500 Message-Id: <20211230073919.30327-5-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211230073919.30327-1-philip@philipmcgrath.com> References: <082a81964a43ae5f735ad2ca433d0dfe00859c35.camel@gmail.com> <20211230073919.30327-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=1640850164; 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=gabsZVpGWF7PrCHsV9bFg142ypKkJ92o164B8EoNLQ0=; b=bI5jY6k2v4syZJhsixAkINxjbHWNHJOBd5eK/cblM3YzZmr/Ic+RJHmXEhd1jMqck1zPpf ByYdXqoNw19BSFrAK678bTxrnvuF4eCdm+0yHPmXyMR/jKjQLewC+2ko+yMjFnpJVBZa0u r1PHEM0CQZAMWLgLvEFVmlCsuXjQI0Aiz45sZYV/vmVt4dwdiCrxuoccV6cnHBhzDtXpwd 609vFA/hCfm9XOcxTZLaxN91iRkDkmbSpym6aAH1Rg5DGPUYHkdc13cmL7yPBDyD8tspmS Ofmamh/IoGvF5lcoawSG2ZkXXD+qxsrywFjH5TYRYaT3BmybHKhgHK9IE/idXw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1640850164; a=rsa-sha256; cv=none; b=JxOKMXkcYmOR/u1hb+XGTyPCF0jckUKy6zZYVPx5I0BY9duJtgGQGmHa4PxkXOXhQ3FvPg A+SItjqgatymADR4OfXXHeL07OlT42hPSI2RXHUEcXAGjjKpk+JQwC5fCLfYOa2WahYwzb 5d0YE6bviH7XCAZznG5BdGPYWtB30j41Ere2iBb7S34aRgtRVZaPl7QTiP6YUfdfdTdnMG L+VG1yo2Kne7+RNg22CuFd1p4KJP4xL3idymzqI8mN7A9T/r9qvoOVpHS6E3M6XOfdIboJ oj+XDxOEZRoon/TMWBC7xxV5XOZMLQXVBwFUYdqI8kZgKUJwiNy6Wbe7vEBwcw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=WdBAPj0d; 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: -0.07 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=WdBAPj0d; 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: CF40B178CB X-Spam-Score: -0.07 X-Migadu-Scanner: scn0.migadu.com X-TUID: j0xedNhXS2lN * 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