From patchwork Thu Dec 30 07:38:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip McGrath X-Patchwork-Id: 35764 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 7319127BBEA; Thu, 30 Dec 2021 07:42:35 +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 DF2DA27BBE9 for ; Thu, 30 Dec 2021 07:42:34 +0000 (GMT) Received: from localhost ([::1]:53078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n2q53-0007N7-UH for patchwork@mira.cbaines.net; Thu, 30 Dec 2021 02:42:33 -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 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)