From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id cIkPJBwWsWF7CQAAgWs5BA (envelope-from ) for ; Wed, 08 Dec 2021 21:31:24 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id iHOtHxwWsWGPEwAAbx9fmQ (envelope-from ) for ; Wed, 08 Dec 2021 20:31:24 +0000 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 253BF261EB for ; Wed, 8 Dec 2021 21:31:24 +0100 (CET) Received: from localhost ([::1]:48504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mv3b1-0000j5-9k for larch@yhetil.org; Wed, 08 Dec 2021 15:31:23 -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 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1638995484; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=teAJKTWNnkKR3SVaIcZCGsnlAr4obIHoNhyOOMkV1fc=; b=D/55foAkw74BgN7d5Bzc3IZjwT91iSwuCKKeGoPbnwwYC3l7iiG2ECixtRG7s9VoG1ig5P KGRT9Hf7kzs6TO8neij6nHoPUo7vp5jSpsdfF47+Ui2WxKQ4fIn5vE0ySrPFjQHWI2ATaH 4vvqYNv8C4KCxYv357SrWXi7F3TUlilLE/82AbtxqUeqAl+7hrA2ZckxU9ERahidR/YC4w kh+kpMCa3zHjQN7gbFuq+VTQDxKWPnOzvkbeQaYpbT7FbcOsPaP+B6EPEkYUibOLXAWNqj KPXs0KlOucrlCQUaXEgNzGIf4vseg+0lAoMDbCA7Q+Q3kTBVgGrz3ezvKSmcuQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1638995484; a=rsa-sha256; cv=none; b=Md5/44yBy2kl0ysx44ZMVXBSelWV/ixD0wBf/Ynokz9JIZYdfcqe+a8Cnd6xkE4EN3Yq7J 4vasOCPMZdrncR85YM01iTCo3kHVxz7F6gHwxF5hC0R1iVMaXj6qrAPcZfQ4e3OlkOQDUT KASpwAe/E5WvqVM8Dgd7K/mnl7AZ0w5FLKr1Biy4Xr+dHnQtEj3g1nzKc4jtRCI8A38Yoa Nzjp75s8l3bLScBOJGakyU6Mw5CtoU4VsuKtuRfMjIqH/wdyQi/aH5hXvcBUg6ttklB2d9 E8AtmZBm22A2Of/cfacDM5y/esSzxWjqH4gU9bHDDmUS3KtsKmYRhuAKysyBBg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=JRNz8JRU; 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.45 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=JRNz8JRU; 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: 253BF261EB X-Spam-Score: -0.45 X-Migadu-Scanner: scn1.migadu.com X-TUID: 2lBtwK2o+/uD * 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) -- 2.32.0