From patchwork Tue Sep 28 21:40:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 33409 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 C92E927BBE4; Tue, 28 Sep 2021 22:45:12 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 0D5EE27BBE3 for ; Tue, 28 Sep 2021 22:45:11 +0100 (BST) Received: from localhost ([::1]:57632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVKuU-0005G1-1M for patchwork@mira.cbaines.net; Tue, 28 Sep 2021 17:45:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVKuM-0005Ft-Qy for guix-patches@gnu.org; Tue, 28 Sep 2021 17:45:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:35671) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVKuM-0003Yk-Jx for guix-patches@gnu.org; Tue, 28 Sep 2021 17:45:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mVKuM-00016d-EE for guix-patches@gnu.org; Tue, 28 Sep 2021 17:45:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50878] [PATCH] union: Resolve collisions by stable-sort'ing them. Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 28 Sep 2021 21:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 50878 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50878@debbugs.gnu.org Cc: Attila Lendvai X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16328654664183 (code B ref -1); Tue, 28 Sep 2021 21:45:02 +0000 Received: (at submit) by debbugs.gnu.org; 28 Sep 2021 21:44:26 +0000 Received: from localhost ([127.0.0.1]:47217 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVKtm-00015P-4U for submit@debbugs.gnu.org; Tue, 28 Sep 2021 17:44:26 -0400 Received: from lists.gnu.org ([209.51.188.17]:32802) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVKtj-00015G-IO for submit@debbugs.gnu.org; Tue, 28 Sep 2021 17:44:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVKtj-0005F8-Ar for guix-patches@gnu.org; Tue, 28 Sep 2021 17:44:23 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]:38762) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVKth-00035M-Oh for guix-patches@gnu.org; Tue, 28 Sep 2021 17:44:23 -0400 Received: by mail-ed1-x529.google.com with SMTP id dj4so561465edb.5 for ; Tue, 28 Sep 2021 14:44:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Qr5R52rHMqO4ZCWXfxGqaXGgIsdYxTsy6aODkPEG9fc=; b=aVSdrgDC29acA5/eux1+btEJ5MyCh3UVHTnnpdc9vqpnV8YNeV0s7C6VOh2sb8fXeu TLuZb92vb1Yk5akxeXWhyHpcX5dEGc7JKvHKgaF92ikgi8DkJZTEKS8sXBHe30adDGrz ZWN4O5mygryqP7eNMG3JV/ixxGnaOZsMWvHyGifBnr5HrQ41C+dW028wMbdm+zRk0CYs +RIE/5MPh5LsrX8CZBkrjZR+YYnN3breIOIUgeOgYBJRzzyAx+R11Y97yKzAxMaxCOQ2 dFOr7JpEEMznmNKmheaLm0PSeZHPwpUnrxILH6vOvD19YDxYI1l7+uUCj0vzhkBaajq+ ZujQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=Qr5R52rHMqO4ZCWXfxGqaXGgIsdYxTsy6aODkPEG9fc=; b=C8baJs8p5WC9A/UB6v+3CV3aWLo1T/P4m11CY0axb/6gikj9Nkx6T5qEH/YbzE0YnL Q/Y0MhpEoZm9LHkYon+tYfKW1Bm0dzGXYrS6dZ5nOG5xW6muT6LZWAQDtoWEIFZidC42 MoLUZN4ZSggqUxDPOtCknYh4Ynfq3WKTYQev9i1SSekIp+SvtuChqnUnXwG4BTweTG7s KjGn4F29+uDzrOSmMLaxAAh9YNu76HY4sKTHKyQYRFvTbs4QQYW69Na0mooQfp+OwynT Zz5Mf5ZVsqfz3OPQ/MThAZrJ5qf2MKOCcQ9MP/fLjXQWyF0RMBg3riFSq4Rwyd5qM+DX eQCA== X-Gm-Message-State: AOAM532vC39syKBehrAwVWIdhirSRsAhgccwAw12gop5ewGKDC//2l5P sO4iK+bMoGrSaJcGfveUzAYu+E86Pzo= X-Google-Smtp-Source: ABdhPJxDuE4qnt4HAybDm/dde6TmTyfexO+3SdrRzce06iKM8wois9DODJVrrKsci1siVqINrFR8gg== X-Received: by 2002:a50:d8c2:: with SMTP id y2mr10334092edj.360.1632865459410; Tue, 28 Sep 2021 14:44:19 -0700 (PDT) Received: from lelap.lan (catv-213-222-131-28.catv.broadband.hu. [213.222.131.28]) by smtp.gmail.com with ESMTPSA id c11sm173913edk.68.2021.09.28.14.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 14:44:18 -0700 (PDT) From: Attila Lendvai Date: Tue, 28 Sep 2021 23:40:45 +0200 Message-Id: <20210928214044.437-1-attila@lendvai.name> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=attila.lendvai@gmail.com; helo=mail-ed1-x529.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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/union.scm (resolve-collision/alphanumeric-last): New function. (warn-about-collision): Renamed to default-collision-resolver. --- this should work, but i cannot test it, because srfi-43 seems not to be available on the build side: unpacking bootstrap Guile to '/home/alendvai/workspace/guix/guix/test-tmp/store/qky0jf68rr7pnsvmhj0ay42rzh4qk6r9-guile-bootstrap-2.0'... [...] output without sfri-43.go and then unsurprisingly: "no code for module (srfi srfi-43)" is tis only a peculiarity of the test environment? can you please advise how to proceed? guix/build/union.scm | 26 ++++++++++++++++++++------ guix/gexp.scm | 2 +- tests/union.scm | 9 +++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/guix/build/union.scm b/guix/build/union.scm index 961ac3298b..747902ec6c 100644 --- a/guix/build/union.scm +++ b/guix/build/union.scm @@ -23,11 +23,12 @@ #:use-module (ice-9 format) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-43) #:use-module (rnrs bytevectors) #:use-module (rnrs io ports) #:export (union-build - warn-about-collision + default-collision-resolver relative-file-name symlink-relative)) @@ -102,10 +103,23 @@ identical, #f otherwise." ;; applications via 'glib-or-gtk-build-system'. '("icon-theme.cache" "gschemas.compiled")) -(define (warn-about-collision files) - "Handle the collision among FILES by emitting a warning and choosing the -first one of THEM." - (let ((file (first files))) +(define (resolve-collision/alphanumeric-last files) + ;; Let's do a stable-sort at least, so that multiple foo-1.2.3/bin/foo + ;; variants will predictably resolve to the highest versioned one. + (let* ((original-files (list->vector files)) + (count (vector-length original-files)) + (stripped-files (vector-map (lambda (_ el) + (strip-store-file-name el)) + original-files)) + (indices (vector-unfold values count))) + (stable-sort! indices + (lambda (a b) + (string> (vector-ref stripped-files a) + (vector-ref stripped-files b)))) + (vector-ref original-files (vector-ref indices 0)))) + +(define (default-collision-resolver files) + (let ((file (resolve-collision/alphanumeric-last files))) (unless (member (basename file) %harmless-collisions) (format (current-error-port) "~%warning: collision encountered:~%~{ ~a~%~}" @@ -117,7 +131,7 @@ first one of THEM." #:key (log-port (current-error-port)) (create-all-directories? #f) (symlink symlink) - (resolve-collision warn-about-collision)) + (resolve-collision default-collision-resolver)) "Build in the OUTPUT directory a symlink tree that is the union of all the INPUTS, using SYMLINK to create symlinks. As a special case, if CREATE-ALL-DIRECTORIES?, creates the subdirectories in the output directory to diff --git a/guix/gexp.scm b/guix/gexp.scm index f3d278b3e6..32e8748443 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -1983,7 +1983,7 @@ This yields an 'etc' directory containing these two files." (define* (directory-union name things #:key (copy? #f) (quiet? #f) - (resolve-collision 'warn-about-collision)) + (resolve-collision 'default-collision-resolver)) "Return a directory that is the union of THINGS, where THINGS is a list of file-like objects denoting directories. For example: diff --git a/tests/union.scm b/tests/union.scm index a8387edf42..cbf8840793 100644 --- a/tests/union.scm +++ b/tests/union.scm @@ -204,4 +204,13 @@ ("/a/b" "/a/b/c/d" => "c/d") ("/a/b/c" "/a/d/e/f" => "../../d/e/f"))) +(test-assert "resolve-collision/alphanumeric-last sorts alphanumerically" + (string= + ((@@ (guix build union) resolve-collision/alphanumeric-last) + (list "/gnu/store/c0000000000000000000000000000000-idris-0.0.0/bin/idris" + "/gnu/store/60000000000000000000000000000000-idris-2.0.0/bin/idris" + "/gnu/store/z0000000000000000000000000000000-idris-1.3.5/bin/idris" + "/gnu/store/00000000000000000000000000000000-idris-1.3.3/bin/idris")) + "/gnu/store/60000000000000000000000000000000-idris-2.0.0/bin/idris")) + (test-end)