From 323b58ac18af8417d5b206288d09d9bb9385d7ae Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 31 Jan 2024 08:29:30 +0100 Subject: channels: ‘latest-channel-instances’ traverses user-provided channels first. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, ‘latest-channel-instances’ would perform a depth-first traversal of channels. Since dependencies specified in ‘.guix-channel’ are usually less specific that those provided by the user, this would lead to the use of instances corresponding to those less specific specs, which in turn might declare dependencies that do not exist for the more specific instances. This commit changes ‘latest-channel-instances’ to perform a breadth-first traversal, thereby giving user-supplied channels higher precedence over dependencies found via ‘.guix-channel’. Fixes . * guix/channels.scm (latest-channel-instances)[ignore?]: Remove. [instance-name, same-named?, more-specific?]: New procedures. Rewrite as a breadth-first traversal using a regular loop. * tests/channels.scm ("latest-channel-instances reads dependencies from most-specific instance"): New test. Change-Id: Iba518145cfd209f04293a56246dbfee3b714650b --- tests/channels.scm | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/channels.scm b/tests/channels.scm index 27e8487fbc..c56e4e6a71 100644 --- a/tests/channels.scm +++ b/tests/channels.scm @@ -1,6 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2018 Ricardo Wurmus -;;; Copyright © 2019, 2020, 2022 Ludovic Courtès +;;; Copyright © 2019-2020, 2022, 2024 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -196,6 +196,55 @@ "abc1234"))) instances))))))) +(test-equal "latest-channel-instances reads dependencies from most-specific instance" + '(chan1 chan2) + ;; Here '.guix-channel' in DIRECTORY2 is less specific than the + ;; user-provided channel spec in ONE: the latter specifies a commit. Since + ;; the most specific one "wins", the bogus '.guix-channel' file added in + ;; DIRECTORY1 as its second commit must not be taken into account. + ;; See . + (with-temporary-git-repository directory1 + `((add "a.scm" "(define-module (a))") + (commit "first commit") + (add ".guix-channel" + ,(object->string + '(channel + (version 0) + (dependencies + ;; Attempting to fetch this dependency would fail. + (channel + (name nonexistent-dependency) + (url "http://guix.example.org/does-not-exist.git")))))) + (commit "second commit")) + (with-temporary-git-repository directory2 + `((add ".guix-channel" + ,(object->string + `(channel (version 0) + (dependencies + (channel + (name chan1) + ;; Note: no 'commit' field here. + (url ,(string-append "file://" directory1))))))) + (commit "initial commit")) + (with-repository directory1 repository + (let* ((commit (find-commit repository "first")) + (one (channel + (url (string-append "file://" directory1)) + (commit (oid->string (commit-id commit))) ;<- specific + (name 'chan1))) + (two (channel + (url (string-append "file://" directory2)) + (name 'chan2)))) + + (with-store store + (map (compose channel-name channel-instance-channel) + (delete-duplicates + (append (latest-channel-instances store (list one two)) + (latest-channel-instances store (list two one))) + (lambda (instance1 instance2) + (string=? (channel-instance-commit instance1) + (channel-instance-commit instance2))))))))))) + (test-equal "latest-channel-instances #:validate-pull" 'descendant -- cgit v1.2.3