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 IIsbIOWMU2FqUwAAgWs5BA (envelope-from ) for ; Tue, 28 Sep 2021 23:45:09 +0200 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 OO6QG+WMU2GJFgAAbx9fmQ (envelope-from ) for ; Tue, 28 Sep 2021 21:45:09 +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 9EAD619250 for ; Tue, 28 Sep 2021 23:45:08 +0200 (CEST) Received: from localhost ([::1]:57632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVKuR-0005G1-Q7 for larch@yhetil.org; Tue, 28 Sep 2021 17:45:07 -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 Content-Transfer-Encoding: 8bit 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+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=1632865508; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=Qr5R52rHMqO4ZCWXfxGqaXGgIsdYxTsy6aODkPEG9fc=; b=bgAIdTqwwbje+kH0H11V3VVNkTQOMyy2Il33AnyC2Qj4auVHRq0ckXWwrb3SkbcNARCO4i 4CTWIKjoBm+m11R2G8I6lFEd0beFDiEvxtqAmkEi67pDeBR2i7BKl8njuhQ4/wTIFJLex9 wKLzKYfldUIswGFkrlOVJb8XVWbQbB9zprNmk0NRKk29vg47Xzrk2PqB39EQa02R9p7XoW Qmq4p3/RLc74ZvQTqrHy+qDlMjjhRoraxM44RoN2+z83LpOxn8S4PntZI+fIRsw/9IL6r5 XiSRTNTAS/1gNqtEbqai51ZczdynZ9azbXjoRdXPJpD5gkQR7g5SWpuMsSkavg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1632865508; a=rsa-sha256; cv=none; b=Lw/xkusYFKXp7/mgCGmfkh9Z67cFunqnpM9TOWZL1T6CeRL04cKIvhSMUH41wNelKmLIBn hF8WQ0jbn04xxAjJZ9ghD0QcySaQRSBSjd++LEYmbtii09NYw8ODQ9oDwXPZvPXxw3u6mU ex1wsJjjJgd45wtgEXB0RjDSjZhUWmvt705FSBjjIpZvShaN8rzvNrDQ3VZUjDyxRBPQG/ hAnfnc49OraFEfOU30rNddSIQ14remwf3OQN7u4n6GV3nLR6f5HD2Xvp+O8Ur/Dup99qlP q3Fkkd4boQMjsS1lSEVXBfDuxYqnQBavcx0JR6N8jAJ8qikB9z8VycSUiJ//cQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=aVSdrgDC; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 3.60 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=aVSdrgDC; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 9EAD619250 X-Spam-Score: 3.60 X-Migadu-Scanner: scn0.migadu.com X-TUID: kdfavE3roNBU * 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) -- 2.33.0