Skip to content

Commit d6a9af8

Browse files
committed
godoc/analysis: remove deprecated analysis package
Change-Id: I862cae902ea2ff7ed36722d536039cc617200de6 Reviewed-on: https://go-review.googlesource.com/c/tools/+/358954 Trust: Zvonimir Pavlinovic <[email protected]> Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Zvonimir Pavlinovic <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Russ Cox <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent e7eb6f6 commit d6a9af8

File tree

10 files changed

+2
-1658
lines changed

10 files changed

+2
-1658
lines changed

cmd/godoc/doc.go

-7
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ The flags are:
5252
Go root directory
5353
-http=addr
5454
HTTP service address (e.g., '127.0.0.1:6060' or just ':6060')
55-
-analysis=type,pointer
56-
comma-separated list of analyses to perform
57-
"type": display identifier resolution, type info, method sets,
58-
'implements', and static callees
59-
"pointer": display channel peers, callers and dynamic callees
60-
(significantly slower)
61-
See https://golang.org/lib/godoc/analysis/help.html for details.
6255
-templates=""
6356
directory containing alternate template files; if set,
6457
the directory may provide alternative template files

cmd/godoc/godoc_test.go

-134
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
package main_test
66

77
import (
8-
"bufio"
98
"bytes"
109
"fmt"
1110
"go/build"
12-
"io"
1311
"io/ioutil"
1412
"net"
1513
"net/http"
@@ -479,135 +477,3 @@ func TestNoMainModule(t *testing.T) {
479477
t.Errorf("stderr contains 'go mod download', is that intentional?\nstderr=%q", stderr.String())
480478
}
481479
}
482-
483-
// Basic integration test for godoc -analysis=type (via HTTP interface).
484-
func TestTypeAnalysis(t *testing.T) {
485-
bin, cleanup := buildGodoc(t)
486-
defer cleanup()
487-
testTypeAnalysis(t, packagestest.GOPATH, bin)
488-
// TODO(golang.org/issue/34473): Add support for type, pointer
489-
// analysis in module mode, then enable its test coverage here.
490-
}
491-
func testTypeAnalysis(t *testing.T, x packagestest.Exporter, bin string) {
492-
if runtime.GOOS == "plan9" {
493-
t.Skip("skipping test on plan9 (issue #11974)") // see comment re: Plan 9 below
494-
}
495-
496-
// Write a fake GOROOT/GOPATH.
497-
// TODO(golang.org/issue/34473): This test uses import paths without a dot in first
498-
// path element. This is not viable in module mode; import paths will need to change.
499-
e := packagestest.Export(t, x, []packagestest.Module{
500-
{
501-
Name: "app",
502-
Files: map[string]interface{}{
503-
"main.go": `
504-
package main
505-
import "lib"
506-
func main() { print(lib.V) }
507-
`,
508-
},
509-
},
510-
{
511-
Name: "lib",
512-
Files: map[string]interface{}{
513-
"lib.go": `
514-
package lib
515-
type T struct{}
516-
const C = 3
517-
var V T
518-
func (T) F() int { return C }
519-
`,
520-
},
521-
},
522-
})
523-
goroot := filepath.Join(e.Temp(), "goroot")
524-
if err := os.Mkdir(goroot, 0755); err != nil {
525-
t.Fatalf("os.Mkdir(%q) failed: %v", goroot, err)
526-
}
527-
defer e.Cleanup()
528-
529-
// Start the server.
530-
addr := serverAddress(t)
531-
cmd := exec.Command(bin, fmt.Sprintf("-http=%s", addr), "-analysis=type")
532-
cmd.Dir = e.Config.Dir
533-
// Point to an empty GOROOT directory to speed things up
534-
// by not doing type analysis for the entire real GOROOT.
535-
// TODO(golang.org/issue/34473): This test optimization may not be viable in module mode.
536-
cmd.Env = append(e.Config.Env, fmt.Sprintf("GOROOT=%s", goroot))
537-
cmd.Stdout = os.Stderr
538-
stderr, err := cmd.StderrPipe()
539-
if err != nil {
540-
t.Fatal(err)
541-
}
542-
cmd.Args[0] = "godoc"
543-
if err := cmd.Start(); err != nil {
544-
t.Fatalf("failed to start godoc: %s", err)
545-
}
546-
defer killAndWait(cmd)
547-
waitForServerReady(t, cmd, addr)
548-
549-
// Wait for type analysis to complete.
550-
reader := bufio.NewReader(stderr)
551-
for {
552-
s, err := reader.ReadString('\n') // on Plan 9 this fails
553-
if err != nil {
554-
t.Fatal(err)
555-
}
556-
fmt.Fprint(os.Stderr, s)
557-
if strings.Contains(s, "Type analysis complete.") {
558-
break
559-
}
560-
}
561-
go io.Copy(os.Stderr, reader)
562-
563-
t0 := time.Now()
564-
565-
// Make an HTTP request and check for a regular expression match.
566-
// The patterns are very crude checks that basic type information
567-
// has been annotated onto the source view.
568-
tryagain:
569-
for _, test := range []struct{ url, pattern string }{
570-
{"/src/lib/lib.go", "L2.*package .*Package docs for lib.*/lib"},
571-
{"/src/lib/lib.go", "L3.*type .*type info for T.*struct"},
572-
{"/src/lib/lib.go", "L5.*var V .*type T struct"},
573-
{"/src/lib/lib.go", "L6.*func .*type T struct.*T.*return .*const C untyped int.*C"},
574-
575-
{"/src/app/main.go", "L2.*package .*Package docs for app"},
576-
{"/src/app/main.go", "L3.*import .*Package docs for lib.*lib"},
577-
{"/src/app/main.go", "L4.*func main.*package lib.*lib.*var lib.V lib.T.*V"},
578-
} {
579-
url := fmt.Sprintf("http://%s%s", addr, test.url)
580-
resp, err := http.Get(url)
581-
if err != nil {
582-
t.Errorf("GET %s failed: %s", url, err)
583-
continue
584-
}
585-
body, err := ioutil.ReadAll(resp.Body)
586-
resp.Body.Close()
587-
if err != nil {
588-
t.Errorf("GET %s: failed to read body: %s (response: %v)", url, err, resp)
589-
continue
590-
}
591-
592-
if !bytes.Contains(body, []byte("Static analysis features")) {
593-
// Type analysis results usually become available within
594-
// ~4ms after godoc startup (for this input on my machine).
595-
if elapsed := time.Since(t0); elapsed > 500*time.Millisecond {
596-
t.Fatalf("type analysis results still unavailable after %s", elapsed)
597-
}
598-
time.Sleep(10 * time.Millisecond)
599-
goto tryagain
600-
}
601-
602-
match, err := regexp.Match(test.pattern, body)
603-
if err != nil {
604-
t.Errorf("regexp.Match(%q) failed: %s", test.pattern, err)
605-
continue
606-
}
607-
if !match {
608-
// This is a really ugly failure message.
609-
t.Errorf("GET %s: body doesn't match %q, got:\n%s",
610-
url, test.pattern, string(body))
611-
}
612-
}
613-
}

cmd/godoc/main.go

+2-29
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"flag"
2626
"fmt"
2727
"go/build"
28-
exec "golang.org/x/sys/execabs"
2928
"io"
3029
"log"
3130
"net/http"
@@ -38,8 +37,9 @@ import (
3837
"runtime"
3938
"strings"
4039

40+
exec "golang.org/x/sys/execabs"
41+
4142
"golang.org/x/tools/godoc"
42-
"golang.org/x/tools/godoc/analysis"
4343
"golang.org/x/tools/godoc/static"
4444
"golang.org/x/tools/godoc/vfs"
4545
"golang.org/x/tools/godoc/vfs/gatefs"
@@ -59,8 +59,6 @@ var (
5959
// file-based index
6060
writeIndex = flag.Bool("write_index", false, "write index to a file; the file name must be specified with -index_files")
6161

62-
analysisFlag = flag.String("analysis", "", `comma-separated list of analyses to perform when in GOPATH mode (supported: type, pointer). See https://golang.org/lib/godoc/analysis/help.html`)
63-
6462
// network
6563
httpAddr = flag.String("http", defaultAddr, "HTTP service address")
6664

@@ -208,12 +206,6 @@ func main() {
208206
if goModFile != "" {
209207
fmt.Printf("using module mode; GOMOD=%s\n", goModFile)
210208

211-
if *analysisFlag != "" {
212-
fmt.Fprintln(os.Stderr, "The -analysis flag is supported only in GOPATH mode at this time.")
213-
fmt.Fprintln(os.Stderr, "See https://golang.org/issue/34473.")
214-
usage()
215-
}
216-
217209
// Detect whether to use vendor mode or not.
218210
mainMod, vendorEnabled, err := gocommand.VendorEnabled(context.Background(), gocommand.Invocation{}, &gocommand.Runner{})
219211
if err != nil {
@@ -266,20 +258,6 @@ func main() {
266258
}
267259
}
268260

269-
var typeAnalysis, pointerAnalysis bool
270-
if *analysisFlag != "" {
271-
for _, a := range strings.Split(*analysisFlag, ",") {
272-
switch a {
273-
case "type":
274-
typeAnalysis = true
275-
case "pointer":
276-
pointerAnalysis = true
277-
default:
278-
log.Fatalf("unknown analysis: %s", a)
279-
}
280-
}
281-
}
282-
283261
var corpus *godoc.Corpus
284262
if goModFile != "" {
285263
corpus = godoc.NewCorpus(moduleFS{fs})
@@ -376,11 +354,6 @@ func main() {
376354
go corpus.RunIndexer()
377355
}
378356

379-
// Start type/pointer analysis.
380-
if typeAnalysis || pointerAnalysis {
381-
go analysis.Run(pointerAnalysis, &corpus.Analysis)
382-
}
383-
384357
// Start http server.
385358
if *verbose {
386359
log.Println("starting HTTP server")

godoc/analysis/README

-111
This file was deleted.

0 commit comments

Comments
 (0)