From patchwork Tue May 3 11:42:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 2162 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 84CEE27BBEA; Tue, 3 May 2022 12:45:03 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id BA05C27BBE9 for ; Tue, 3 May 2022 12:45:02 +0100 (BST) Received: from localhost ([::1]:46710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlqxh-0004TU-To for patchwork@mira.cbaines.net; Tue, 03 May 2022 07:45:01 -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 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 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)