From patchwork Sun Oct 3 12:43:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 33590 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 5DF7727BBE3; Sun, 3 Oct 2021 13:48:14 +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, URIBL_BLOCKED autolearn=unavailable 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 E035127BBE1 for ; Sun, 3 Oct 2021 13:48:13 +0100 (BST) Received: from localhost ([::1]:37868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mX0ub-0007qP-2C for patchwork@mira.cbaines.net; Sun, 03 Oct 2021 08:48:13 -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 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 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)