From patchwork Thu Dec 30 07:44:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip McGrath X-Patchwork-Id: 35807 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 8DAD127BBEB; Thu, 30 Dec 2021 07:48:17 +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=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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 F08A727BBE9 for ; Thu, 30 Dec 2021 07:48:16 +0000 (GMT) Received: from localhost ([::1]:34368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n2qAa-0005pP-5B for patchwork@mira.cbaines.net; Thu, 30 Dec 2021 02:48:16 -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 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 | 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)