From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id aDY8ILoVcWL2bgEAbAwnHQ (envelope-from ) for ; Tue, 03 May 2022 13:44:58 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id YJE0ILoVcWJlawAAauVa8A (envelope-from ) for ; Tue, 03 May 2022 13:44:58 +0200 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 1EF433F193 for ; Tue, 3 May 2022 13:44:58 +0200 (CEST) Received: from localhost ([::1]:46710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlqxc-0004TU-7U for larch@yhetil.org; Tue, 03 May 2022 07:44:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlqwm-0003e8-BD for guix-patches@gnu.org; Tue, 03 May 2022 07:44:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44944) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlqwm-0002Rl-39 for guix-patches@gnu.org; Tue, 03 May 2022 07:44:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nlqwm-0005QK-0z for guix-patches@gnu.org; Tue, 03 May 2022 07:44:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55242] [PATCH 04/10] guix: import: go: Fix the interpretation of the replace directive. Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 03 May 2022 11:44:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55242 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55242@debbugs.gnu.org Cc: Attila Lendvai Received: via spool by 55242-submit@debbugs.gnu.org id=B55242.165157821420744 (code B ref 55242); Tue, 03 May 2022 11:44:03 +0000 Received: (at 55242) by debbugs.gnu.org; 3 May 2022 11:43:34 +0000 Received: from localhost ([127.0.0.1]:38828 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nlqwH-0005OQ-Rn for submit@debbugs.gnu.org; Tue, 03 May 2022 07:43:34 -0400 Received: from mail-ed1-f52.google.com ([209.85.208.52]:45618) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nlqwF-0005NC-BF for 55242@debbugs.gnu.org; Tue, 03 May 2022 07:43:31 -0400 Received: by mail-ed1-f52.google.com with SMTP id be20so19512279edb.12 for <55242@debbugs.gnu.org>; Tue, 03 May 2022 04:43:31 -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=8AS+bwnBiW5h+Jn9QhXNURpZsGBqogHAd3TY/Q7wtEY=; b=C19XHXcA/cNVDwDQvPxJJpiWHtY6GonPU7F7BeeyFBWvM37XC5AClRL67+5wCfPyW9 R5h/sjmrfFZcMbCfq3SremekjAKZOHTG23TJgXKjboWP4f3JFyq2oXT1SDLGgNPJjvpB FkmN8AhgnxiOxRPSMks5A5tph1Bi/Ziw+OBUEGE/Y6LOfAB9Pb3scSOXgRnmtbQ0tKRT aU+dQBgZxoNOn5k5iUAQnHs9ge1wcng5h37CErZ19IJcCTU1GydYRGficAXecb/U0y0k JHF43HVCx8zJE66zN/HVMIXPnPKchqYrSerJIfjyPUW0V28f7F0mQupVg6pztYxXgJm3 c/Rg== 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=8AS+bwnBiW5h+Jn9QhXNURpZsGBqogHAd3TY/Q7wtEY=; b=miQ1w/q7gH5hwJCahplA7jV/7F1un/7zvkVIhyhmYVUcfykwwmK1TQ+qXx8tM2nblU HsiFJ54/0OHb78P5ktjFkerbE7VgoJsXssPMRIAWDk7/hLHETLwMJ9P9mB8+Ua5j/nWW 0wyTcLFsTSII+K6oxgWi+qkS7heFn2fiX44PX0oB64ko+yTikxHRgMQ2nUKH+A2Yzj0W QuNiwKRGSaTtlruE2On47sOfzTVvWGVRPTCrmLK/SXVKShtCtg+LiLOS4dUpjd8Ezzim 1U0haHGeYNgsvxOOnqD9mlxeqTI6G31LhhOcxUWyzNfyhs/DxvRRgqwZMGarbm8YpBwo ZrLg== X-Gm-Message-State: AOAM533y5RhXnDvc6wUePh/AGtHY7o0PhdgBRgHY7J+xDORQoKKAlO97 27ueZLhqSLZ+bK/kY8W6AbLkP2+rfXk= X-Google-Smtp-Source: ABdhPJxiuCX6iWHRvhew9WfO5GSHkg2C7tORKzfWdFVbha2m52btbQeb4RjmN/AMXn6/nKAxHx4PGg== X-Received: by 2002:a05:6402:84a:b0:426:262d:967e with SMTP id b10-20020a056402084a00b00426262d967emr17646593edz.286.1651578203253; Tue, 03 May 2022 04:43:23 -0700 (PDT) Received: from lelap.local (catv-89-132-245-188.catv.fixed.vodafone.hu. [89.132.245.188]) by smtp.gmail.com with ESMTPSA id k13-20020a05640212cd00b0042617ba63d6sm7766964edx.96.2022.05.03.04.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 04:43:22 -0700 (PDT) From: Attila Lendvai Date: Tue, 3 May 2022 13:42:55 +0200 Message-Id: <20220503114301.9524-4-attila@lendvai.name> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220503114301.9524-2-attila@lendvai.name> References: <20220503114301.9524-2-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 X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1651578298; 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=8AS+bwnBiW5h+Jn9QhXNURpZsGBqogHAd3TY/Q7wtEY=; b=NUWfboMykM01fojx6qagME1c7Ct05Euei0tqSkm3DbSLw+GxDTomyfrV4ymf0rKWzS394w /ARGT9NXoHegN/RUgxhm8/9wRrjybWOgwVymvrsAUV2g5JkyLIN32b14ufMGgJJ8JxP4Wz XfU7cPv+Id6oQ/n0DLE+5T3nSabXiSpPatQs3OKKpuojFG2S3kW6oiTKTQFErwLR7UugyP DSr970eAqiB9pqhasqhaWrl28j1fCv6xunHPIgQx4OPXSLRc18FhKr/QS8XEc8AGffwRa7 A9k78K+qNUgIpcKLOYwe0tK6s0b3KALtFYNFjPRUFIBO135aiuWrZQRv4eboxQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1651578298; a=rsa-sha256; cv=none; b=IYZlBJ8fNEqnid/cQowRktVj3VJVUIOtEDKuwzUUdmCwsHRodHH8Yx6MccUFPLAVOnqOQg r47BAHpG5jaB2h+LYLICU/W3FDjJnQ+xr4IyxG9M/FkJpYlAdUrWgoi2cRVy5id4+awvqO LEfJSpy56nmKg5IvYi75xYwRbynoATrfwuTBOKSZ5415+Z95NXI5s+wpNh+O4ubeAfrmUc xCrVtW4kL1bsRTKgDfBuqTFUAcfzIEY+A7xc6212tgss3sYN/9OE27zM7N1O+7sBQTZfg0 QOA4MbMuST4HdaFaqD5KeP3ituAjEwjFUBGOXKj9+5hT4T+CrOudiAE1osh3+w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=C19XHXcA; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 2.52 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=C19XHXcA; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 1EF433F193 X-Spam-Score: 2.52 X-Migadu-Scanner: scn1.migadu.com X-TUID: uoPnc4WDVsBG When a version is specified in a replace directive, then we must also match the version against any potential replacements. * guix/import/go.scm (go.mod-requirements): Fix by also matching the version. --- guix/import/go.scm | 53 +++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/guix/import/go.scm b/guix/import/go.scm index 0af5e4b5e2..a115c61adc 100644 --- a/guix/import/go.scm +++ b/guix/import/go.scm @@ -331,7 +331,7 @@ (define-peg-pattern original all (or (and module-path version) module-path)) (define-peg-pattern with all (or (and module-path version) file-path)) (define-peg-pattern replace all (and original => with EOL)) (define-peg-pattern replace-top body - (and (ignore "replace") + (and (ignore "replace") (or (and block-start (* (or replace block-line)) block-end) replace))) ;; RetractSpec = ( Version | "[" Version "," Version "]" ) newline . @@ -365,22 +365,39 @@ (define (go.mod-directives go.mod directive) (define (go.mod-requirements go.mod) "Compute and return the list of requirements specified by GO.MOD." (define (replace directive requirements) - (define (maybe-replace module-path new-requirement) - ;; Do not allow version updates for indirect dependencies (see: - ;; https://golang.org/ref/mod#go-mod-file-replace). - (if (and (equal? module-path (first new-requirement)) - (not (assoc-ref requirements module-path))) - requirements - (cons new-requirement (alist-delete module-path requirements)))) - + ;; Specification: https://golang.org/ref/mod#go-mod-file-replace + ;; Interesting test cases: + ;; github.com/influxdata/influxdb-client-go/v2@v2.4.0 + (log.debug "inside replace, directive ~S, requirements ~S" directive requirements) + (define (maybe-replace old-module-path old-version new-module-path new-version) + (let ((matched-entry (assoc-ref requirements old-module-path))) + (log.debug "inside maybe-replace, ~S ~S => ~S ~S, matched-entry ~S" + old-module-path old-version new-module-path new-version matched-entry) + (cond ((and (equal? old-module-path new-module-path) + (not matched-entry)) + ;; "A replace directive has no effect if the module version on the left + ;; side is not required." + ;; Do not allow version updates for indirect dependencies. + requirements) + ((and matched-entry + (or (not old-version) + (equal? old-version new-version))) + (cons (list new-module-path new-version) + (alist-delete old-module-path requirements))) + (else + requirements)))) + (log.debug "toplevel directive is ~S" directive) (match directive - ((('original ('module-path module-path) . _) with . _) + ((('original ('module-path old-module-path) ('version old-version) ...) with) + (unless (null? old-version) + (set! old-version (first old-version))) (match with - (('with ('file-path _) . _) - (alist-delete module-path requirements)) - (('with ('module-path new-module-path) ('version new-version) . _) - (maybe-replace module-path - (list new-module-path new-version))))))) + (('with ('file-path _)) + ;; Superseded by a module in a local path, so let's delete it. + (alist-delete old-module-path requirements)) + (('with ('module-path new-module-path) ('version new-version)) + (maybe-replace old-module-path old-version + new-module-path new-version)))))) (define (require directive requirements) (match directive @@ -389,8 +406,10 @@ (define (require directive requirements) (let* ((requires (go.mod-directives go.mod 'require)) (replaces (go.mod-directives go.mod 'replace)) - (requirements (fold require '() requires))) - (fold replace requirements replaces))) + (requirements (fold require '() requires)) + (result (fold replace requirements replaces))) + (log.debug "requires:~% ~S~%replaces:~% ~S~%result:~% ~S" requires replaces result) + result)) ;; Prevent inlining of this procedure, which is accessed by unit tests. (set! go.mod-requirements go.mod-requirements) -- 2.35.1