From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id AO+9Bz1kzWFowAAAgWs5BA (envelope-from ) for ; Thu, 30 Dec 2021 08:48:13 +0100 Received: from aspmx2.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id uP0NBT1kzWFLBAEA9RJhRA (envelope-from ) for ; Thu, 30 Dec 2021 08:48:13 +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 aspmx2.migadu.com (Postfix) with ESMTPS id B3D8C1EA7D for ; Thu, 30 Dec 2021 08:48:12 +0100 (CET) Received: from localhost ([::1]:34368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n2qAV-0005pP-K9 for larch@yhetil.org; Thu, 30 Dec 2021 02:48:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n2q9S-0004BE-9v for guix-patches@gnu.org; Thu, 30 Dec 2021 02:47:10 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:39605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n2q9R-0005sV-7f for guix-patches@gnu.org; Thu, 30 Dec 2021 02:47:06 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n2q9R-0006uh-6m for guix-patches@gnu.org; Thu, 30 Dec 2021 02:47:05 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51838] [PATCH v7 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:47: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.164085041826475 (code B ref 51838); Thu, 30 Dec 2021 07:47:05 +0000 Received: (at 51838) by debbugs.gnu.org; 30 Dec 2021 07:46:58 +0000 Received: from localhost ([127.0.0.1]:51137 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n2q9J-0006sp-Ou for submit@debbugs.gnu.org; Thu, 30 Dec 2021 02:46:58 -0500 Received: from mail-qv1-f41.google.com ([209.85.219.41]:39832) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n2q8J-0006oc-59 for 51838@debbugs.gnu.org; Thu, 30 Dec 2021 02:45:55 -0500 Received: by mail-qv1-f41.google.com with SMTP id g15so21416616qvi.6 for <51838@debbugs.gnu.org>; Wed, 29 Dec 2021 23:45:55 -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=PMn+SLxy57HBGaOpqpsoXs/SOLV2bmON9o1ilp51td74tqyl5SUfk4SRE1ffJzwyAr 2T3/WLq3jU+2XugUHNSL4XNVeUMUHoT7hU8wr//TsIEY8Tt3FW9xyY5L0DW3J7fNh47c fGQcpj/cNppQbn7gNrExckG1FOtjGX1QhLFCMHNg0HShSOnuizwjUF2H3hi4uiPyRXd+ Q9Q/hLmt+pi1Yz51CtRIcNhe+6elAYZM0jm3fLA4ZZIRyk8T/UDy7x3n1kdTIJKFTNjc sDcNfFLCPqJmR1VjlZQE7gAsZyBR8Z3l3dr1xK5QGVgPGBZtJv4BRLPWomkUS+lPRIEG DEKw== 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=DKRh50zJUMYkcSS4HbyUZihGIXftzpaIt3cN8rvfUwnp0aUkvFzbIeR+vzL9guXA52 NGX3/uPVwnS4NNPYneF+uva5X7H2zCgp+ZBKSLxbaut5ihDSGxMdURPRz8vn147RShMe QWBTWONWR0yVYfT14OWUQUQUf/tKz1Y6MYFqY3o02q7hvpvtaGWpj1r6gsp/6ejOzgrS 1mXmJONE+Zcts6zcA2cfbFPIwn6qknmh0b0MaWGIJ8Vc4qXqdkJe4yoG0f5mSfHIDYRz Ngmr+3k72hv6VgDhF62tgFxw6JRNsfCrnj4ieovzLWnDdiAyFrcf98d4kWXp57bE6ms6 6sGw== X-Gm-Message-State: AOAM530KiwJsD2/c07BKLnxZzyk1A17ML/vcKO1r3QHhkOBqmhbaVl+J q9ciB/1svp/ZmCvJ+5at3QY8im+ROYu6yk7e X-Google-Smtp-Source: ABdhPJxIFa8WhUVVEZbOrCH1XsGyZ0WtTC4m9Ncnyu9MDAJWRTi7+JqDiNofp9vohcr1s0wDgYemag== X-Received: by 2002:a05:6214:c8f:: with SMTP id r15mr26289570qvr.57.1640850349595; Wed, 29 Dec 2021 23:45:49 -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 k8sm20011096qtx.35.2021.12.29.23.45.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Dec 2021 23:45:49 -0800 (PST) From: Philip McGrath Date: Thu, 30 Dec 2021 02:44:19 -0500 Message-Id: <20211230074456.33433-5-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211230074456.33433-1-philip@philipmcgrath.com> References: <20211230073919.30327-1-philip@philipmcgrath.com> <20211230074456.33433-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=1640850492; 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=bPObfmtn6iBDLU/rpNnbX50qwIwdk/92h3FV/cJsuMXIXqfVPy0tPnzGTNpUiG5K6iLH4r YMyTvqJcLzbw46KteBUq3iXvxHtzLucbT91xe6p6QA7ppw0nm7McLnHZK9DdfdToarxp2N WeIpaYTsHqVtsbmY80GUBz1a7zvKv6FYeTKDEpM6mgjtznxfuEfmaLiQtbKw9lL8g5gu/5 Y7nqdjZuhFJaPWT1Xob1d1kPt+2SU5djA4zv6IoGEfiHInxZMErXe6crUuFB5AOsN0Zwiw MRTb2L6gZ5C81G3glfVH9aRB79v9C2atQVxvTzkI3XWjuEFxqvnoBjXl2WRJ1g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1640850492; a=rsa-sha256; cv=none; b=HUHKGvi60Y352qtTlQuofgsC/IuvlFKOwS/sY1nKkPVDgPdrfSdmDsvTJk4uJZHbrDJkhd WJIuNKN2Qh0QcKEEQt6UUCFEbxjhA1oAxdzQQJ3Qs0kycR73X9dxaTv/FdrqWP3tC2ksna Z+ei0oETIT9jjPRJOhBf/hsTG66b8/dUIvFAalMhWlJ7/js/bK4sc21V8H9YpHU1ftvgh+ peXWDjr7vRCO7RiAGPVju7KMJ1refLKXOfm3CqEgKYs8qKo18LuA2VPqBBv0cuPwVqnolo RuRtZAFgrGI1/3SgV92NPrYfy5b2WpGoTVCXj+MuBnMUBibioAuNOydaLKLN9g== ARC-Authentication-Results: i=1; aspmx2.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=PMn+SLxy; 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.57 Authentication-Results: aspmx2.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=PMn+SLxy; 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: B3D8C1EA7D X-Spam-Score: -0.57 X-Migadu-Scanner: scn0.migadu.com X-TUID: ge4PqKoNTOH2 * 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