]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/distpack: rename go.mod to _go.mod in toolchain modules
authorRuss Cox <rsc@golang.org>
Fri, 16 Jun 2023 17:04:50 +0000 (13:04 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 20 Jun 2023 15:03:07 +0000 (15:03 +0000)
Modules cannot contain go.mod files except at the root
(and we don't keep one at the root). Rename the other go.mod
files to _go.mod.

dl2mod, which we used to convert all the old releases,
did this renaming, but it was missed when porting that
code to distpack.

For #57001.
Fixes #60847.

Change-Id: I4d646b96b5be15df3b79193e254ddc9b11cc8734
Reviewed-on: https://go-review.googlesource.com/c/go/+/503979
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/distpack/archive.go
src/cmd/distpack/pack.go
src/cmd/distpack/test.go

index 730233765c22d13986140c3f9af1e439940bf0c0..f731b3792f8c9fc2c6ee1c9ac73b1986f69f7484 100644 (file)
@@ -92,7 +92,7 @@ func (a *Archive) Add(name, src string, info fs.FileInfo) {
 }
 
 // Sort sorts the files in the archive.
-// It is only necessary to call Sort after calling Add.
+// It is only necessary to call Sort after calling Add or RenameGoMod.
 // ArchiveDir returns a sorted archive, and the other methods
 // preserve the sorting of the archive.
 func (a *Archive) Sort() {
@@ -164,6 +164,16 @@ func (a *Archive) SetTime(t time.Time) {
        }
 }
 
+// RenameGoMod renames the go.mod files in the archive to _go.mod,
+// for use with the module form, which cannot contain other go.mod files.
+func (a *Archive) RenameGoMod() {
+       for i, f := range a.Files {
+               if strings.HasSuffix(f.Name, "/go.mod") {
+                       a.Files[i].Name = strings.TrimSuffix(f.Name, "go.mod") + "_go.mod"
+               }
+       }
+}
+
 func amatch(pattern, name string) (bool, error) {
        // firstN returns the prefix of name corresponding to the first n path elements.
        // If n <= 0, firstN returns the entire name.
index fb549f967d2d8db7fff539d6f17d688cee3278e6..6867ac17c2abe998391fcb391ca6fdb47ca6475c 100644 (file)
 // A cross-compiled distribution for goos/goarch can be built using:
 //
 //     GOOS=goos GOARCH=goarch ./make.bash -distpack
+//
+// To test that the module downloads are usable with the go command:
+//
+//     ./make.bash -distpack
+//     mkdir -p /tmp/goproxy/golang.org/toolchain/
+//     ln -sf $(pwd)/../pkg/distpack /tmp/goproxy/golang.org/toolchain/@v
+//     GOPROXY=file:///tmp/goproxy GOTOOLCHAIN=$(sed 1q ../VERSION) gotip version
+//
+// gotip can be replaced with an older released Go version once there is one.
+// It just can't be the one make.bash built, because it knows it is already that
+// version and will skip the download.
 package main
 
 import (
@@ -199,6 +210,8 @@ func main() {
        )
        modVers := modVersionPrefix + "-" + version + "." + goosDashGoarch
        modArch.AddPrefix(modPath + "@" + modVers)
+       modArch.RenameGoMod()
+       modArch.Sort()
        testMod(modArch)
 
        // distpack returns the full path to name in the distpack directory.
index 93c65645949b9b80e48f645d2e5f127ce748573c..4544d72d1f386f3a2d43d90a3695015c6fff303b 100644 (file)
@@ -95,6 +95,10 @@ var modRules = []testRule{
        {name: "golang.org/toolchain@*/pkg/tool/*/compile", goos: "darwin"},
        {name: "golang.org/toolchain@*/pkg/tool/*/compile", goos: "windows", exclude: true},
        {name: "golang.org/toolchain@*/pkg/tool/*/compile.exe", goos: "windows"},
+
+       // go.mod are renamed to _go.mod.
+       {name: "**/go.mod", exclude: true},
+       {name: "**/_go.mod"},
 }
 
 func testSrc(a *Archive) {