]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "cmd/go/internal/modload: record the replacement for the module containing...
authorAndrew Bonventre <andybons@google.com>
Mon, 24 Feb 2020 22:47:00 +0000 (22:47 +0000)
committerAndrew Bonventre <andybons@golang.org>
Mon, 24 Feb 2020 23:29:37 +0000 (23:29 +0000)
This reverts CL 220645 (commit e092fc352ad393a4d2f1f7fa641df2d23572ccff).

Reason for revert: Seems to have broken windows/amd64 longtest

Change-Id: Iffa8c882524250e5845514bc827fcd8927645a44
Reviewed-on: https://go-review.googlesource.com/c/go/+/220722
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/internal/modload/build.go
src/cmd/go/testdata/mod/example.com_printversion_v0.1.0.txt
src/cmd/go/testdata/mod/example.com_printversion_v1.0.0.txt
src/cmd/go/testdata/script/version_replace.txt [deleted file]
src/runtime/debug/mod.go

index 454dbf28cfca3493458b43a1d493f93491d8d584..6fa47d7400e60015b720251782e8e9b2286f8a9a 100644 (file)
@@ -207,7 +207,6 @@ func PackageBuildInfo(path string, deps []string) string {
        if isStandardImportPath(path) || !Enabled() {
                return ""
        }
-
        target := mustFindModule(path, path)
        mdeps := make(map[module.Version]bool)
        for _, dep := range deps {
@@ -224,25 +223,26 @@ func PackageBuildInfo(path string, deps []string) string {
 
        var buf bytes.Buffer
        fmt.Fprintf(&buf, "path\t%s\n", path)
-
-       writeEntry := func(token string, m module.Version) {
-               mv := m.Version
+       tv := target.Version
+       if tv == "" {
+               tv = "(devel)"
+       }
+       fmt.Fprintf(&buf, "mod\t%s\t%s\t%s\n", target.Path, tv, modfetch.Sum(target))
+       for _, mod := range mods {
+               mv := mod.Version
                if mv == "" {
                        mv = "(devel)"
                }
-               fmt.Fprintf(&buf, "%s\t%s\t%s", token, m.Path, mv)
-               if r := Replacement(m); r.Path == "" {
-                       fmt.Fprintf(&buf, "\t%s\n", modfetch.Sum(m))
-               } else {
-                       fmt.Fprintf(&buf, "\n=>\t%s\t%s\t%s\n", r.Path, r.Version, modfetch.Sum(r))
+               r := Replacement(mod)
+               h := ""
+               if r.Path == "" {
+                       h = "\t" + modfetch.Sum(mod)
+               }
+               fmt.Fprintf(&buf, "dep\t%s\t%s%s\n", mod.Path, mv, h)
+               if r.Path != "" {
+                       fmt.Fprintf(&buf, "=>\t%s\t%s\t%s\n", r.Path, r.Version, modfetch.Sum(r))
                }
        }
-
-       writeEntry("mod", target)
-       for _, mod := range mods {
-               writeEntry("dep", mod)
-       }
-
        return buf.String()
 }
 
index 606322ac862fe5c15672a61e71847e3f0d8dd2fc..bae8b13d470e24ae28b88f93dd3b489f2a287f13 100644 (file)
@@ -21,13 +21,7 @@ func main() {
        info, _ := debug.ReadBuildInfo()
        fmt.Fprintf(os.Stdout, "path is %s\n", info.Path)
        fmt.Fprintf(os.Stdout, "main is %s %s\n", info.Main.Path, info.Main.Version)
-       if r := info.Main.Replace; r != nil {
-               fmt.Fprintf(os.Stdout, "\t(replaced by %s %s)\n", r.Path, r.Version)
-       }
        for _, m := range info.Deps {
                fmt.Fprintf(os.Stdout, "using %s %s\n", m.Path, m.Version)
-               if r := m.Replace; r != nil {
-                       fmt.Fprintf(os.Stdout, "\t(replaced by %s %s)\n", r.Path, r.Version)
-               }
        }
 }
index b9b71e953825aef26891a3d9c9d8d51276371189..246741821aff1be4ecc82d789a0f61c5f0947cfb 100644 (file)
@@ -29,13 +29,7 @@ func main() {
        info, _ := debug.ReadBuildInfo()
        fmt.Fprintf(os.Stdout, "path is %s\n", info.Path)
        fmt.Fprintf(os.Stdout, "main is %s %s\n", info.Main.Path, info.Main.Version)
-       if r := info.Main.Replace; r != nil {
-               fmt.Fprintf(os.Stdout, "\t(replaced by %s %s)\n", r.Path, r.Version)
-       }
        for _, m := range info.Deps {
                fmt.Fprintf(os.Stdout, "using %s %s\n", m.Path, m.Version)
-               if r := m.Replace; r != nil {
-                       fmt.Fprintf(os.Stdout, "\t(replaced by %s %s)\n", r.Path, r.Version)
-               }
        }
 }
diff --git a/src/cmd/go/testdata/script/version_replace.txt b/src/cmd/go/testdata/script/version_replace.txt
deleted file mode 100644 (file)
index e832b2e..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-[short] skip
-
-go mod download example.com/printversion@v0.1.0 example.com/printversion@v1.0.0
-
-go install example.com/printversion
-
-go run example.com/printversion
-cmp stdout out.txt
-
-go version -m $GOPATH/bin/printversion
-stdout '^.*[/\\]bin[/\\]printversion: .*$'
-stdout '^      path    example.com/printversion$'
-stdout '^      mod     example.com/printversion        v0.1.0$'
-stdout '^      =>      example.com/printversion        v1.0.0  h1:.*$'
-stdout '^      dep     example.com/version     v1.0.0$'
-stdout '^      =>      example.com/version     v1.0.1  h1:.*$'
-
--- go.mod --
-module golang.org/issue/37392
-go 1.14
-require (
-       example.com/printversion v0.1.0
-)
-replace (
-       example.com/printversion => example.com/printversion v1.0.0
-       example.com/version v1.0.0 => example.com/version v1.0.1
-)
--- out.txt --
-path is example.com/printversion
-main is example.com/printversion v0.1.0
-       (replaced by example.com/printversion v1.0.0)
-using example.com/version v1.0.0
-       (replaced by example.com/version v1.0.1)
index 0381bdcc53951c64b6277277467ca896c8863941..837cd689a079af3175926f9b14bf8ff86c62867f 100644 (file)
@@ -47,27 +47,9 @@ func readBuildInfo(data string) (*BuildInfo, bool) {
                repLine  = "=>\t"
        )
 
-       readEntryFirstLine := func(elem []string) (Module, bool) {
-               if len(elem) != 2 && len(elem) != 3 {
-                       return Module{}, false
-               }
-               sum := ""
-               if len(elem) == 3 {
-                       sum = elem[2]
-               }
-               return Module{
-                       Path:    elem[0],
-                       Version: elem[1],
-                       Sum:     sum,
-               }, true
-       }
+       info := &BuildInfo{}
 
-       var (
-               info = &BuildInfo{}
-               last *Module
-               line string
-               ok   bool
-       )
+       var line string
        // Reverse of cmd/go/internal/modload.PackageBuildInfo
        for len(data) > 0 {
                i := strings.IndexByte(data, '\n')
@@ -81,33 +63,42 @@ func readBuildInfo(data string) (*BuildInfo, bool) {
                        info.Path = elem
                case strings.HasPrefix(line, modLine):
                        elem := strings.Split(line[len(modLine):], "\t")
-                       last = &info.Main
-                       *last, ok = readEntryFirstLine(elem)
-                       if !ok {
+                       if len(elem) != 3 {
                                return nil, false
                        }
+                       info.Main = Module{
+                               Path:    elem[0],
+                               Version: elem[1],
+                               Sum:     elem[2],
+                       }
                case strings.HasPrefix(line, depLine):
                        elem := strings.Split(line[len(depLine):], "\t")
-                       last = new(Module)
-                       info.Deps = append(info.Deps, last)
-                       *last, ok = readEntryFirstLine(elem)
-                       if !ok {
+                       if len(elem) != 2 && len(elem) != 3 {
                                return nil, false
                        }
+                       sum := ""
+                       if len(elem) == 3 {
+                               sum = elem[2]
+                       }
+                       info.Deps = append(info.Deps, &Module{
+                               Path:    elem[0],
+                               Version: elem[1],
+                               Sum:     sum,
+                       })
                case strings.HasPrefix(line, repLine):
                        elem := strings.Split(line[len(repLine):], "\t")
                        if len(elem) != 3 {
                                return nil, false
                        }
-                       if last == nil {
+                       last := len(info.Deps) - 1
+                       if last < 0 {
                                return nil, false
                        }
-                       last.Replace = &Module{
+                       info.Deps[last].Replace = &Module{
                                Path:    elem[0],
                                Version: elem[1],
                                Sum:     elem[2],
                        }
-                       last = nil
                }
        }
        return info, true