From patchwork Wed Dec 8 20:28:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip McGrath X-Patchwork-Id: 35042 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 299FB27BBE9; Wed, 8 Dec 2021 20:31:28 +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=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,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 3A6E527BBEA for ; Wed, 8 Dec 2021 20:31:27 +0000 (GMT) Received: from localhost ([::1]:48504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mv3b4-0000j5-AZ for patchwork@mira.cbaines.net; Wed, 08 Dec 2021 15:31:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mv3a0-0006lj-3m for guix-patches@gnu.org; Wed, 08 Dec 2021 15:30:21 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:58380) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mv3Zy-0000XK-7d for guix-patches@gnu.org; Wed, 08 Dec 2021 15:30:19 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mv3Zy-00062a-4E for guix-patches@gnu.org; Wed, 08 Dec 2021 15:30:18 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51838] [PATCH v3 21/43] 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: Wed, 08 Dec 2021 20:30:18 +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 Received: via spool by 51838-submit@debbugs.gnu.org id=B51838.163899539522896 (code B ref 51838); Wed, 08 Dec 2021 20:30:18 +0000 Received: (at 51838) by debbugs.gnu.org; 8 Dec 2021 20:29:55 +0000 Received: from localhost ([127.0.0.1]:41647 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mv3Za-0005x7-Sx for submit@debbugs.gnu.org; Wed, 08 Dec 2021 15:29:55 -0500 Received: from mail-ua1-f49.google.com ([209.85.222.49]:45748) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mv3Yq-0005q1-IK for 51838@debbugs.gnu.org; Wed, 08 Dec 2021 15:29:16 -0500 Received: by mail-ua1-f49.google.com with SMTP id ay21so6844427uab.12 for <51838@debbugs.gnu.org>; Wed, 08 Dec 2021 12:29:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philipmcgrath.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=teAJKTWNnkKR3SVaIcZCGsnlAr4obIHoNhyOOMkV1fc=; b=JRNz8JRUOi14sMO95oJoi9m62/eHnO6SEH9WXLD6Rl/GVn3HtSSh8E0aNM6aDjmjlh FhA2jBKsNi2Ku78Ql4HiEDEQinR/UL5yI5XIzWmH3MFoUX7u4Iu1lh20ouHQneKYlRtE 4kntOrmnlYSapOJEfhUlXwTV/Ph9MuapI6ywsvuNgutheXIjqwYGIoPtslmI7+OqUmHu flnmfdKXHgRLZ5twS3u/syir17BSON6t/acTfV67O5PKiTMMZmbcivd8m3s4kFA9LgLy YvWxlN5Gr6CV4CDNBM9bbNKIw2mJn5bgl9FWT/ScnHjO3NpKYmEpWn/ZswPFENmUrk27 Ysuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=teAJKTWNnkKR3SVaIcZCGsnlAr4obIHoNhyOOMkV1fc=; b=5kr474NMHhLzHrdogrp0N5SIgf8bzXOitfBYBCUE+ax4z01PSePzIvbYM/XbbyYQTH 7CKY3H15Khepj6Tjc6zVqE3x/7/X55ku8hvnmbe6z99eA8YFDEo1UdA2u96Czx2ZtJXT Tb16yIGlJ1uZjxwZyqIkDt6hEi621TsocTCJC3arATuaVFamno//G4ra4GebUarRQXUu +m8QhRixddqOfhYs9ggCAzNxFbLh4lEnqfnliUzouNdW/kpsovq9N5r4sIp+7VzUr4+2 9t5dtmv/ueU1ywY1KG3CdrvjWBC1+zgiI0SVIfdkratVY9bA/6+lx4UBefQdsOP9BMZ8 vfmQ== X-Gm-Message-State: AOAM532QbWKcSUlM8eFIhP7gt3KfXfOE+p0CWD/P/s3ATmzGy54JksRH 7YPqObRmpTBBj51MFzMqk/fkT+FGgDgDyc2Jis4= X-Google-Smtp-Source: ABdhPJyTcJamuuiq5m0K+ncKP/868A04FTDNn6jmknnw9d3bYKk9lMTGJg4O2O43OVdhDZ29caSiog== X-Received: by 2002:ab0:719a:: with SMTP id l26mr11370587uao.88.1638995342940; Wed, 08 Dec 2021 12:29:02 -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 m3sm2589008vkf.35.2021.12.08.12.29.02 for <51838@debbugs.gnu.org> (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Dec 2021 12:29:02 -0800 (PST) From: Philip McGrath Date: Wed, 8 Dec 2021 15:28:16 -0500 Message-Id: <20211208202838.752542-22-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211208202838.752542-1-philip@philipmcgrath.com> References: <46a042bc08eb72a068b1e8c69bfe28cf2d4b2e53.camel@gmail.com> <20211208202838.752542-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 | 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)