From 5f3a7aa2172c4b78de6bae19f740024c4088b5e3 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Fri, 11 Oct 2013 10:37:32 +0900 Subject: [PATCH] go.tools/misc/dist: copy doc.go from go.tools to go root This will allow "godoc godoc", "godoc vet", "godoc cover" to work. Fixes #6527. R=r, dsymonds CC=golang-dev https://golang.org/cl/14566049 --- misc/dist/bindist.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/misc/dist/bindist.go b/misc/dist/bindist.go index 82898a59ba..7f70bc265b 100644 --- a/misc/dist/bindist.go +++ b/misc/dist/bindist.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // This is a tool for packaging binary releases. -// It supports FreeBSD, Linux, NetBSD, OS X, and Windows. +// It supports FreeBSD, Linux, NetBSD, OpenBSD, OS X, and Windows. package main import ( @@ -22,6 +22,7 @@ import ( "net/http" "os" "os/exec" + "path" "path/filepath" "regexp" "runtime" @@ -480,7 +481,31 @@ func (b *Build) tools() error { // Install tools. args = append([]string{"install"}, toolPaths...) _, err = b.run(b.gopath, filepath.Join(b.root, "bin", "go"), args...) - return err + if err != nil { + return err + } + + // Copy doc.go from go.tools/cmd/$CMD to $GOROOT/src/cmd/$CMD + // while rewriting "package main" to "package documentation". + for _, p := range toolPaths { + d, err := ioutil.ReadFile(filepath.Join(b.gopath, "src", + filepath.FromSlash(p), "doc.go")) + if err != nil { + return err + } + d = bytes.Replace(d, []byte("\npackage main\n"), + []byte("\npackage documentation\n"), 1) + cmdDir := filepath.Join(b.root, "src", "cmd", path.Base(p)) + if err := os.MkdirAll(cmdDir, 0755); err != nil { + return err + } + docGo := filepath.Join(cmdDir, "doc.go") + if err := ioutil.WriteFile(docGo, d, 0644); err != nil { + return err + } + } + + return nil } func (b *Build) blog() error { -- 2.50.0