From patchwork Mon Dec 13 06:00:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip McGrath X-Patchwork-Id: 35164 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 8719427BBEA; Mon, 13 Dec 2021 06:04:37 +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 5376927BBE9 for ; Mon, 13 Dec 2021 06:04:36 +0000 (GMT) Received: from localhost ([::1]:42252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mweRv-0002rN-CY for patchwork@mira.cbaines.net; Mon, 13 Dec 2021 01:04:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mweQS-0000rk-Mx for guix-patches@gnu.org; Mon, 13 Dec 2021 01:03:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:42161) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mweQS-00075A-CT for guix-patches@gnu.org; Mon, 13 Dec 2021 01:03:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mweQS-0002Ro-9U for guix-patches@gnu.org; Mon, 13 Dec 2021 01:03:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51838] [PATCH v4 06/45] guix: node-build-system: Refactor patch-dependencies phase. Resent-From: Philip McGrath Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 13 Dec 2021 06:03:04 +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.16393753739318 (code B ref 51838); Mon, 13 Dec 2021 06:03:04 +0000 Received: (at 51838) by debbugs.gnu.org; 13 Dec 2021 06:02:53 +0000 Received: from localhost ([127.0.0.1]:53694 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mweQH-0002QE-5Y for submit@debbugs.gnu.org; Mon, 13 Dec 2021 01:02:53 -0500 Received: from mail-vk1-f178.google.com ([209.85.221.178]:41765) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mweQD-0002Pe-JB for 51838@debbugs.gnu.org; Mon, 13 Dec 2021 01:02:49 -0500 Received: by mail-vk1-f178.google.com with SMTP id 188so9696857vku.8 for <51838@debbugs.gnu.org>; Sun, 12 Dec 2021 22:02:49 -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=HgDhxkred0qxyTO/DMBSW0NymNIb0O6DOenE65nfmIE=; b=BMfcTiQwSy8CAjCEbDDIIDu6WYZP/cbh0QB3hHxjJQoDkfBZlNEu5CawAALNvpVV/c R7N750ZKm282Uk3HjfBay/huDLTEV+n8+oGXzzbISGuWvXKFtSZasfVx7SUzfIS2gVpI RTYUTfYYLKdAq0DiM9/4DQS6AuoHgM29/UP+9ELx3kQTszfqow2m+GvCDOTdv/OA/O2g f5ojJ+yeriFvX7esi3R1LR+R+A1DByCP4n0aXLxY734w4ZuOJYbYM/6K6vv7K2b/ISGp 8o7YGxG7Reflf+WWXnuBT7FTCWhitxqRJNwQ/4fD5kEoFlrAD/9Jx3yOtDgW7XrKda5H MWaA== 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=HgDhxkred0qxyTO/DMBSW0NymNIb0O6DOenE65nfmIE=; b=pwLYiOhdTZZhIf099U05C/bt/AhW7JHGoC5+HZ/Fl9JE2ySFCp1Gm/zJnJZQgBxKnY OZPcWYNt0EpIw4pfIE3wcHoWht6CTHXWHnUyQv+CZ52RiixRixoxF9BrWMRbnZG/4ee8 LbARzCoCoFDLHZQMZMjljlKnmpJ/Jb+grmi5MCU+CCSIc7dSIuwdgSKVpKcbyIk+7051 3Bp1tD65RQPQ9CRDVtosiJ248G1BhmTWyA/pofavJxihdNGszidvvgYS6vJCXDYU0rni oC6K1zYJJFymRcqRFeSCkVsC+U60LS0+vZmKHgHk67ZtkabzbxKeYUUuz6EQfg/BhD2g 4lYQ== X-Gm-Message-State: AOAM5317sbDVM4mYBEEiE7x+UZNEhneLPbcEzUW1faUud+A8N8jmC0Wb c9IdpjzVW4GwpLEmYfUxOn1dt5CLyGnLbcWT+/c= X-Google-Smtp-Source: ABdhPJzyrfU43zsbzNMpoz7yiYuZXVX1G2n4WuGhlqUOvlPYpxFcqa+6V8PgWqn5N0P/7QKA5yEf/A== X-Received: by 2002:a1f:3f4f:: with SMTP id m76mr30825007vka.1.1639375364018; Sun, 12 Dec 2021 22:02:44 -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 r13sm3688391vkl.13.2021.12.12.22.02.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Dec 2021 22:02:43 -0800 (PST) From: Philip McGrath Date: Mon, 13 Dec 2021 01:00:28 -0500 Message-Id: <20211213060107.129223-7-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211213060107.129223-1-philip@philipmcgrath.com> References: <46a042bc08eb72a068b1e8c69bfe28cf2d4b2e53.camel@gmail.com> <20211208202838.752542-1-philip@philipmcgrath.com> <20211208202838.752542-5-philip@philipmcgrath.com> <877dc924h7.fsf@gmx.com> <5c62c3ce-dd50-5dcd-00ed-ff1524be4e0b@philipmcgrath.com> <20211213060107.129223-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 (patch-dependencies): Strictly follow the linearity rules for `assoc-set!` and friends. Clarify the types of the arguments to and return value from the internal helper function `resolve-dependencies`. --- guix/build/node-build-system.scm | 53 ++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm index dcaa719f40..b74e593838 100644 --- a/guix/build/node-build-system.scm +++ b/guix/build/node-build-system.scm @@ -73,26 +73,45 @@ (define* (patch-dependencies #:key inputs #:allow-other-keys) (define index (index-modules (map cdr inputs))) - (define (resolve-dependencies package-meta meta-key) - (fold (lambda (key+value acc) - (match key+value - ('@ acc) - ((key . value) (acons key (hash-ref index key value) acc)))) - '() - (or (assoc-ref package-meta meta-key) '()))) + (define (resolve-dependencies meta-alist meta-key) + ;; Given: + ;; - The alist from "package.json", with the '@ unwrapped + ;; - A string key, like "dependencies" + ;; Returns: an alist (without a wrapping '@) like the entry in + ;; meta-alist for meta-key, but with dependencies supplied + ;; by Guix packages mapped to the absolute store paths to use. + (match (assoc-ref meta-alist meta-key) + (#f + '()) + (('@ . orig-deps) + (fold (match-lambda* + (((key . value) acc) + (acons key (hash-ref index key value) acc))) + '() + orig-deps)))) (with-atomic-file-replacement "package.json" (lambda (in out) - (let ((package-meta (read-json in))) - (assoc-set! package-meta "dependencies" - (append - '(@) - (resolve-dependencies package-meta "dependencies") - (resolve-dependencies package-meta "peerDependencies"))) - (assoc-set! package-meta "devDependencies" - (append - '(@) - (resolve-dependencies package-meta "devDependencies"))) + ;; It is unsafe to rely on 'assoc-set!' to update an + ;; existing assosciation list variable: + ;; see 'info "(guile)Adding or Setting Alist Entries"'. + (let* ((package-meta (read-json in)) + (alist (match package-meta + ((@ . alist) alist))) + (alist + (assoc-set! + alist "dependencies" + (append + '(@) + (resolve-dependencies alist "dependencies") + (resolve-dependencies alist "peerDependencies")))) + (alist + (assoc-set! + alist "devDependencies" + (append + '(@) + (resolve-dependencies alist "devDependencies")))) + (package-meta (cons '@ alist))) (write-json package-meta out)))) #t)