From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id QK0LD4ymWWHyigAAgWs5BA (envelope-from ) for ; Sun, 03 Oct 2021 14:48:12 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id UEgXCoymWWGqEgAA1q6Kng (envelope-from ) for ; Sun, 03 Oct 2021 12:48:12 +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 7F49D14DD3 for ; Sun, 3 Oct 2021 14:48:11 +0200 (CEST) Received: from localhost ([::1]:37868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mX0uY-0007qP-Lt for larch@yhetil.org; Sun, 03 Oct 2021 08:48:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mX0uQ-0007pf-KX for guix-patches@gnu.org; Sun, 03 Oct 2021 08:48:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:49795) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mX0uQ-0002ra-Ca for guix-patches@gnu.org; Sun, 03 Oct 2021 08:48:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mX0uQ-0006RB-54 for guix-patches@gnu.org; Sun, 03 Oct 2021 08:48:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50878] [PATCH 4/4] WIP guix: build: Add resolve-collision/alphanumeric-last for union. Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 03 Oct 2021 12:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50878 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50878@debbugs.gnu.org Cc: Attila Lendvai Received: via spool by 50878-submit@debbugs.gnu.org id=B50878.163326524824647 (code B ref 50878); Sun, 03 Oct 2021 12:48:02 +0000 Received: (at 50878) by debbugs.gnu.org; 3 Oct 2021 12:47:28 +0000 Received: from localhost ([127.0.0.1]:33108 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mX0ts-0006PS-EC for submit@debbugs.gnu.org; Sun, 03 Oct 2021 08:47:28 -0400 Received: from mail-wm1-f47.google.com ([209.85.128.47]:46691) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mX0tq-0006OW-0m for 50878@debbugs.gnu.org; Sun, 03 Oct 2021 08:47:26 -0400 Received: by mail-wm1-f47.google.com with SMTP id o4-20020a05600c510400b0030d55d6449fso3932974wms.5 for <50878@debbugs.gnu.org>; Sun, 03 Oct 2021 05:47:25 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=GULd65ZGeXU31ROJ5+3A5vd+eTGKJ4KXxxwFe/EnGGg=; b=j0hX+CrdGUn20LCb+BYmBEGATyHKLo5kHfU66/u4SBt1qlMSsU3I65mLssIMCAfjxi +1294+RUivegwps6G5xURObn5AUpHsvWPJltL2o/87JKSuBtf6zJwMRCp5NGguO1UNsc UgQ+UNZmTMiFM7ewCPbSmjYJGu38EfTMGsJLtShnC+C+ZtB4fAs3awVyPngDsQlOJjVm /clidIip+WAFsyrxnolotOfnlVTl/8NACasmikEjq4F/a+2Fhy5o3j93Y0b9mhf4LXKl 9mnqi7wJYxwQ8d15OZEcKgcjpeO7Xwrdz4hB2X4jPVIYMjZZAT0oGwvyUsABKRe0GTfP TFMg== 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 :in-reply-to:references:mime-version:content-transfer-encoding; bh=GULd65ZGeXU31ROJ5+3A5vd+eTGKJ4KXxxwFe/EnGGg=; b=DV/A8JErtgQw3Bo3GSRa6l78Mwy2TCTmeSh9oyCkTwiZINMRUxYu7qiT6tqP3zyAWu 3MatYpnSxAWyJ7Esv0GrpYnMDZgt7WRtQ0qQwh2btkbg/BiMFUyNknpB3g7wVDhZuCVN 71Yj5L8wd/cRmpF/y/wg1kkgbTamzCC7vPMtNrj5r/5ycVv1eRoWS3uBQsQxnLrvqtod tKCOb2pJut0aa9z2OahIV9btqZistl625KEv0YrgI2mtxUisbt/2rGzD8cgQX7cFMvSM tlKxHA9Fge0VvtyUyQWD+O/2JMPqY9fbcfpQo/msDTe24rzM4t9YNpcYdrYOHVmNvanP hFvw== X-Gm-Message-State: AOAM531226kEqNSqfSwAdla2lFciGWJVcFsFqrqKzJcztuS37xd7oxtd PHJsJSn8mZfZjRIf64rdYh2m/PN4y/4= X-Google-Smtp-Source: ABdhPJw1u9Ld71yE/z01fLWezRth9tOpqDXWQZZB/MogblmXFv/4qkgaJdTp3M8yRuL0hOOXFaYx0w== X-Received: by 2002:a7b:c048:: with SMTP id u8mr13514436wmc.113.1633265240097; Sun, 03 Oct 2021 05:47:20 -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 v10sm11800474wri.29.2021.10.03.05.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 05:47:19 -0700 (PDT) From: Attila Lendvai Date: Sun, 3 Oct 2021 14:43:04 +0200 Message-Id: <20211003124303.8277-4-attila@lendvai.name> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211003124303.8277-1-attila@lendvai.name> References: <20211003124303.8277-1-attila@lendvai.name> 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=1633265291; 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=GULd65ZGeXU31ROJ5+3A5vd+eTGKJ4KXxxwFe/EnGGg=; b=Mgyzv+FTWmXo1ShKwFnCRTK/mA+bpEDy7P52jFHffanJycN32Xt88Xp6Cmiz44420aTAhf DEfQa8/X3MIVst69eh1cdt8jt7fapJYioJUvdfx/IGKMI58fbvgA+JCtKAm32jvvY4onaM IDuN1iwOe44RQVzZzE9jE6WQiv3d74m4dc/D019HPC7y3NH7tWu7D6o+AUQJZinKZxvTM7 lWdcuFGupAeM5/ECCj/ZxPe1a/w26nV7OnZySa0cgcxm5IDsYX2Y4x1xhwLwMGCy9n/Ogh mWUZFUf1fsQCsjBNJQ8wVVojdiM3kjozLqpiaJrjjE2IikCiI8Xc3uY5Uawtyw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1633265291; a=rsa-sha256; cv=none; b=tN0kwMKGnGNMw2SfoH0GB3lUXRAb0vEL3Gp85mq5FfXlSyqWkiFoNXeeC7SV3UCaHNVagH Iv2WiVg0m3oEC4scN/jLYYezY66HXQErddVPkNbqFRZJjJL5kwjy253aBcZeCca25CkdPT 69BPYrZIlQWO3gmidQNz9d+93dIjsrh3iO1tp0MtNsfm94Wq5pZZUj72TRN/ZVYxPqIpvN XdkPpuPHC5Y37AF2tGfrA9XS0ZTTYf5VH/Tea+wd/a97J1y1Qygt6RtqIBzQuxi6Krq6o7 rg6qfT0WMrNkgPU7rNHCPrjIT4NhDln4SnmtdjbfKzRdDzXMHyW6SoRMWBbepg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=j0hX+Crd; 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.59 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=j0hX+Crd; 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: 7F49D14DD3 X-Spam-Score: 3.59 X-Migadu-Scanner: scn0.migadu.com X-TUID: rOydAcH5DZnZ It is currently not used anywhere, only exported. The tests are boken, because guile is too old in the test environment, at least on 'x86_64-linux' (guile 2.0.9 doesn't have srfi-43, aka vectors). Probably it's also broken because testing errors with `no code for module (guix build utils)`. * guix/build/union.scm (resolve-collision/alphanumeric-last): New function. * guix/build/utils.scm (compare-strings-ignoring-store-path-prefix): New function. --- I think the previous 3 patches in this patchset are worthy of inclusion, but this one is more of a good idea than a worked out change, to be picked up later, if at all. The primary issue is that the test framework uses a guile that is too old, but it's also not used anywhere. It would be nice if this was used for resolving conflicts for profiles, i.e. for the user's bin/ directory. guix/build/union.scm | 12 ++++++++++++ guix/build/utils.scm | 27 +++++++++++++++++++++++++++ tests/union.scm | 9 +++++++++ 3 files changed, 48 insertions(+) diff --git a/guix/build/union.scm b/guix/build/union.scm index 9e8c2af4f5..339af7576c 100644 --- a/guix/build/union.scm +++ b/guix/build/union.scm @@ -19,15 +19,18 @@ ;;; along with GNU Guix. If not, see . (define-module (guix build union) + #:use-module (guix build utils) #:use-module (ice-9 match) #: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 default-collision-resolver + resolve-collision/alphanumeric-last relative-file-name symlink-relative)) @@ -102,6 +105,15 @@ identical, #f otherwise." ;; applications via 'glib-or-gtk-build-system'. '("icon-theme.cache" "gschemas.compiled")) +(define (resolve-collision/alphanumeric-last files) + ;; Let's do a stable-sort, so that multiple foo-1.2.3/bin/foo variants will + ;; predictably resolve to the highest versioned one. + (let ((files-vector (list->vector files))) + (stable-sort! files-vector + (lambda (a b) + (> 0 (compare-strings-ignoring-store-path-prefix a b)))) + (vector-ref files-vector 0))) + (define (resolve-collision/pick-first files) (first files)) diff --git a/guix/build/utils.scm b/guix/build/utils.scm index 4009c137b8..1ae0244b04 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -47,6 +47,7 @@ %store-hash-string-length store-file-name? strip-store-file-name + compare-strings-ignoring-store-path-prefix package-name->name+version parallel-job-count @@ -171,6 +172,32 @@ is typically a \"PACKAGE-VERSION\" string." (string-drop file (store-path-prefix-length))) +(define (compare-strings-ignoring-store-path-prefix a b) + (let ((a-length (string-length a)) + (b-length (string-length b))) + (do ((i (store-path-prefix-length) (+ i 1))) + ((not (and (< i a-length) + (< i b-length) + (char=? (string-ref a i) + (string-ref b i)))) + (cond + ((= a-length b-length) + (if (= i a-length) ; we reached the end without any difference + 0 + (- (char->integer (string-ref a i)) + (char->integer (string-ref b i))))) + ((> a-length b-length) + (if (= i b-length) ; we reached the end of B without a difference + 1 + (- (char->integer (string-ref a i)) + (char->integer (string-ref b i))))) + (else ; i.e. (< a-length b-length) + (if (= i a-length) ; we reached the end of A without a difference + -1 + (- (char->integer (string-ref a i)) + (char->integer (string-ref b i))))))) + '()))) + (define (package-name->name+version name) "Given NAME, a package name like \"foo-0.9.1b\", return two values: \"foo\" and \"0.9.1b\". When the version part is unavailable, NAME and 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