From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id gPbJCphR2WFRXAAAgWs5BA (envelope-from ) for ; Sat, 08 Jan 2022 09:55:52 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id +HoWCJhR2WH1ggEA9RJhRA (envelope-from ) for ; Sat, 08 Jan 2022 09:55:52 +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 aspmx1.migadu.com (Postfix) with ESMTPS id 1C2663A8E5 for ; Sat, 8 Jan 2022 09:55:51 +0100 (CET) Received: from localhost ([::1]:33402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n67Vt-0002gI-NR for larch@yhetil.org; Sat, 08 Jan 2022 03:55:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n67LS-0002pl-KR for guix-patches@gnu.org; Sat, 08 Jan 2022 03:45:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:53434) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n67LS-0004Bi-9s for guix-patches@gnu.org; Sat, 08 Jan 2022 03:45:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n67LS-0000o2-78 for guix-patches@gnu.org; Sat, 08 Jan 2022 03:45:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51838] [PATCH v9 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: Sat, 08 Jan 2022 08:45: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 , Philip McGrath , Pierre Langlois , Liliana Marie Prikler , Leo Famulari , Jelle Licht Received: via spool by 51838-submit@debbugs.gnu.org id=B51838.16416314492838 (code B ref 51838); Sat, 08 Jan 2022 08:45:02 +0000 Received: (at 51838) by debbugs.gnu.org; 8 Jan 2022 08:44:09 +0000 Received: from localhost ([127.0.0.1]:46297 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n67Kb-0000ji-AC for submit@debbugs.gnu.org; Sat, 08 Jan 2022 03:44:09 -0500 Received: from mail-qt1-f177.google.com ([209.85.160.177]:45694) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n67KZ-0000ir-MX for 51838@debbugs.gnu.org; Sat, 08 Jan 2022 03:44:08 -0500 Received: by mail-qt1-f177.google.com with SMTP id b11so1169180qtk.12 for <51838@debbugs.gnu.org>; Sat, 08 Jan 2022 00:44:07 -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=dGsGuPn2gq4WA19XVo5t3fUrd/z6WCQYTzjpyoqHAtg=; b=bBcockcQECqxdasOlenzy0LO2gJ1cu/0WYUHDq8wPZE9HBresqcNSO7wWVymxS++Mz cyNZ7Ved5HcxJaBTUEiqiUJ8XHosbppueeqL0KrcJ1VzQt031Ts8W3t2ETDR+dRUV8H4 Ia4fAq3aSAZe2sL4crbkhNgHHte14xGgap39tmebwESsaen8SsIS8oOONM4MvxrqxfKm O26f+91xJoJqOfz5EcpfPOAWyHbdnDSJOjmFqLqC39jfagKIiddI6buxFIARiU0RgGpQ KxVMamKdxuhb+E0zqJZTJ4gUXfO8o9MMDeAd7p/NfzfjG9+wNX3H8TUzkexvr7/bm6Ur qbUA== 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=dGsGuPn2gq4WA19XVo5t3fUrd/z6WCQYTzjpyoqHAtg=; b=e+VkO7zkSexqkEZ9R9mEjJnLmyqpJwU9oB29TfiqPz6NodYV6GKNgrNWNL+/piBF2S kYze5RTXq2S8KciI+SxqA0WTPzzCbn6mUZSM67VqK41iit0o3UlsioPLkJuBQ5cPGCy6 D3EeVVzwjPz95sEURVTyFGmoZcjFAhvT01/fBDHMT3UYVk7LJF4Fl0Wrqv/y5TS14Nmi /vy4zZ+Vy1/2UKl8w0gbly/2NmqI8RsMG55SlT2g87/7cbhISwTEwzmBCfMhDF8qA0yS 770nS8TFpF5CgLFkVjHW1SG95mLCUwhAzMWEKSEuo3ifp8kYuoetnV2ZQRYiOq1HCfQ/ goOA== X-Gm-Message-State: AOAM53275NVrGXuMB3juCmnuN3EnhgtD3aki2J8U5AqX/vRWo82/dSdo Mi8QyYJZZ5NPKs/g6HxQMAwRV98T8ZMuJPXX X-Google-Smtp-Source: ABdhPJzPMToJvVlA593NLr1mpTPrrNXVEz5bOutsoH6zjnjFuGJw0RBaSJoy9WO2cdPS9I+0EdT38Q== X-Received: by 2002:a05:622a:586:: with SMTP id c6mr3079368qtb.46.1641631442141; Sat, 08 Jan 2022 00:44:02 -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 v1sm684409qtw.65.2022.01.08.00.44.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 08 Jan 2022 00:44:01 -0800 (PST) From: Philip McGrath Date: Sat, 8 Jan 2022 03:41:52 -0500 Message-Id: <20220108084229.362642-5-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220108084229.362642-1-philip@philipmcgrath.com> References: <64e08d3a1838ed8507f33fae895545372960522f.camel@gmail.com> <7b04af28bbd57c67093ce8f33a648efec89693bd.camel@gmail.com> <441bfeb0-eb6e-81f6-488b-cdf1b09a78ef@philipmcgrath.com> <20220108084229.362642-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=1641632151; 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=dGsGuPn2gq4WA19XVo5t3fUrd/z6WCQYTzjpyoqHAtg=; b=ayvQhbW4Vs28edq8Oo2gfD82n5ULYN8N1PKOOsisaolcJ6sGQQcy6MBoOJ7MqbAaIVTKO2 gNmhLEjlrr2aTyZ9SYeg/PxpN4JRwaJC4BDL3AL5CFeiOR/A7Tn/HYLlL5sE6pix1sD7c3 DlfVYJKPAvwYnrQmBkac5ndn0u7ScEDcZUP00XyqEOChI4Y0eZ1ZTeSp3f5ufmcOxgUr5J mncLwKpgWWIhT4Ipdd5RffuU7aBksL9spCucfsKeqbKAzhq8sxDfQZKAqdNsC4+9uX/H7U 84Mpt5ipnKc2ZMXb428s3/kBuD3Cgf5SpcBERWixZyPTPwAOTFpiIBPBVa04lQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641632151; a=rsa-sha256; cv=none; b=NgW+bLDis8V6ZmIFD4s45qRneOSo3fD1KQ1/c4Pg98CLfMoJKDGElo4mWzLnA3UxYSE+br hgHNoPxMPqiUWrG12RTy2cLvR9N3IJSf6zMl6U25Ab6TgnQ3hC47ERvMcXTkvN6ypUE8mV rslSuzZV0pntJDWcFaMH3SWhxJaiE0GAXoNeDVcCyRQ5WHsiFrcksPCJA9u4bF43UaHpfX 7BWKBJrDPHZoo9s4IlSASNbo3nCG3ALdKAYMZT1/bMsHFYmoUkBuADhZcdKUSAiJcZrYSD ArEvqyYow7GrNDJkPa/kfglzopWLmtvdPCOyg9Q/Sz7byUDKsEK1f5/xMjXouw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=bBcockcQ; 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.90 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=bBcockcQ; 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: 1C2663A8E5 X-Spam-Score: 0.90 X-Migadu-Scanner: scn1.migadu.com X-TUID: ax6G+XH4qClt Packages with native addons currently try to write to store paths when used as dependecies. This patch adds a phase to replace that behaviour with a no-op. * guix/build/node-build-system.scm (avoid-node-gyp-rebuild): New variable. (%standard-phases): Add 'avoid-node-gyp-rebuild' after 'install'. --- guix/build/node-build-system.scm | 54 +++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm index 60c75dc85d..ee3442e9e4 100644 --- a/guix/build/node-build-system.scm +++ b/guix/build/node-build-system.scm @@ -242,6 +242,57 @@ (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"))) + ;; We don't want to use an atomic replacement here, because we often don't + ;; even need to overwrite this file. Therefore, let's use some helpers + ;; that we'd otherwise not need. + (define pkg-meta + (call-with-input-file installed-package.json read-json)) + (define scripts + (jsobject-ref pkg-meta "scripts" '(@))) + (define (jsobject-set js key val) + (jsobject-update* js (list key (const val)))) + + (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) @@ -251,7 +302,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