From: Attila Lendvai <attila@lendvai.name>
To: 55242@debbugs.gnu.org
Cc: Attila Lendvai <attila@lendvai.name>
Subject: [bug#55242] [PATCH 04/10] guix: import: go: Fix the interpretation of the replace directive.
Date: Tue, 3 May 2022 13:42:55 +0200 [thread overview]
Message-ID: <20220503114301.9524-4-attila@lendvai.name> (raw)
In-Reply-To: <20220503114301.9524-2-attila@lendvai.name>
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
next prev parent reply other threads:[~2022-05-03 11:44 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-03 11:16 [bug#55242] [PATCH 01/10] guix: import: Print the number of packages at the end Attila Lendvai
2022-05-03 11:42 ` [bug#55242] [PATCH 02/10] guix: import: go: Rename go.pkg.dev-info to pkg.go.dev-info Attila Lendvai
2022-05-03 11:42 ` [bug#55242] [PATCH 03/10] guix: import: go: Add mockup logging facility Attila Lendvai
2022-05-03 16:23 ` Maxime Devos
2022-06-14 19:46 ` [bug#55242] [PATCH 01/10] guix: import: Print the number of packages at the end Maxim Cournoyer
2022-05-03 11:42 ` Attila Lendvai [this message]
2022-05-03 16:25 ` [bug#55242] [PATCH 04/10] guix: import: go: Fix the interpretation of the replace directive Maxime Devos
2022-05-03 16:26 ` Maxime Devos
2022-05-03 16:27 ` Maxime Devos
2022-05-03 16:28 ` Maxime Devos
2022-05-03 11:42 ` [bug#55242] [PATCH 05/10] guix: import: go: Harden sxml->texi conversion Attila Lendvai
2022-05-03 16:32 ` Maxime Devos
2022-05-03 11:42 ` [bug#55242] [PATCH 06/10] guix: import: go: Add a local duplicate of http-fetch Attila Lendvai
2022-05-03 11:42 ` [bug#55242] [PATCH 07/10] guix: import: go: More resilience wrt network errors; add logging Attila Lendvai
2022-05-03 16:12 ` Maxime Devos
2022-05-03 17:00 ` Attila Lendvai
2022-05-03 17:38 ` Maxime Devos
2022-05-09 12:34 ` Attila Lendvai
2022-05-09 17:45 ` Maxime Devos
2022-05-09 20:02 ` Attila Lendvai
2022-05-09 20:08 ` Maxime Devos
2022-05-03 16:17 ` Maxime Devos
2022-05-03 16:36 ` Maxime Devos
2022-05-03 16:37 ` Maxime Devos
2022-05-03 11:42 ` [bug#55242] [PATCH 08/10] guix: import: go: Modules in a subdir and prefixed tags Attila Lendvai
2022-05-03 16:42 ` Maxime Devos
2022-05-03 16:48 ` Maxime Devos
2022-05-03 16:50 ` Maxime Devos
2022-05-09 12:50 ` Attila Lendvai
2022-05-03 16:51 ` Maxime Devos
2022-05-03 16:53 ` Maxime Devos
2022-05-03 16:55 ` Maxime Devos
2022-05-03 16:56 ` Maxime Devos
2022-05-03 16:59 ` Maxime Devos
2022-05-03 17:00 ` Maxime Devos
2022-05-03 17:01 ` Maxime Devos
2022-05-03 11:43 ` [bug#55242] [PATCH 09/10] guix: import: go: module-name -> module-path to be consistent Attila Lendvai
2022-05-03 11:43 ` [bug#55242] [PATCH 10/10] guix: import: go: Better handling of /v2 in the module path Attila Lendvai
2022-05-09 20:39 ` Maxime Devos
2022-05-03 16:22 ` [bug#55242] [PATCH 02/10] guix: import: go: Rename go.pkg.dev-info to pkg.go.dev-info Maxime Devos
2022-05-03 16:21 ` [bug#55242] [PATCH 01/10] guix: import: Print the number of packages at the end Maxime Devos
2022-05-03 17:29 ` Maxime Devos
2022-05-09 12:37 ` Attila Lendvai
2022-05-14 7:09 ` Maxime Devos
2022-05-14 7:15 ` Maxime Devos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220503114301.9524-4-attila@lendvai.name \
--to=attila@lendvai.name \
--cc=55242@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).