From 878153682ecac3fb00bdad50ff8dcc296e30a701 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sun, 12 Feb 2012 23:55:33 -0500 Subject: [PATCH] cmd/fix: warn about exp, old, deleted packages Fixes #2776. There was a previous attempt at CL 5592043 but that seems to have stalled. This one is simpler, and more up to date (correct handling of spdy, for example). R=golang-dev, r CC=golang-dev https://golang.org/cl/5645091 --- doc/go1.html | 8 -------- doc/go1.tmpl | 8 -------- src/cmd/fix/go1pkgrename.go | 25 ++++++++++++++++++++++++- src/cmd/fix/go1pkgrename_test.go | 10 ++++++++++ 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/doc/go1.html b/doc/go1.html index c681eff3b6a..8ba97ad77b8 100644 --- a/doc/go1.html +++ b/doc/go1.html @@ -539,8 +539,6 @@ Running go fix will update all imports and package renames for pack remain inside the standard repository. Programs that import packages that are no longer in the standard repository will need to be edited by hand. -
-TODO: go fix should warn about deletions.

The package tree exp

@@ -581,8 +579,6 @@ If they are installed, they now reside in $GOROOT/bin/tool. Code that uses packages in exp will need to be updated by hand, or else compiled from an installation that has exp available. The go fix tool or the compiler will complain about such uses. -
-TODO: go fix should warn about such uses.

The package tree old

@@ -608,8 +604,6 @@ The packages in their new locations are: Code that uses packages now in old will need to be updated by hand, or else compiled from an installation that has old available. The go fix tool will warn about such uses. -
-TODO: go fix should warn about such uses.

Deleted packages

@@ -636,8 +630,6 @@ slices directly. See the Go Language Community Wiki for some suggestions. Code that uses the other packages (there should be almost zero) will need to be rethought. -
-TODO: go fix should warn such uses.

Packages moving to subrepositories

diff --git a/doc/go1.tmpl b/doc/go1.tmpl index 9cdbf4bad64..bda9ef48dd7 100644 --- a/doc/go1.tmpl +++ b/doc/go1.tmpl @@ -463,8 +463,6 @@ Running go fix will update all imports and package renames for pack remain inside the standard repository. Programs that import packages that are no longer in the standard repository will need to be edited by hand. -
-TODO: go fix should warn about deletions.

The package tree exp

@@ -505,8 +503,6 @@ If they are installed, they now reside in $GOROOT/bin/tool. Code that uses packages in exp will need to be updated by hand, or else compiled from an installation that has exp available. The go fix tool or the compiler will complain about such uses. -
-TODO: go fix should warn about such uses.

The package tree old

@@ -532,8 +528,6 @@ The packages in their new locations are: Code that uses packages now in old will need to be updated by hand, or else compiled from an installation that has old available. The go fix tool will warn about such uses. -
-TODO: go fix should warn about such uses.

Deleted packages

@@ -560,8 +554,6 @@ slices directly. See the Go Language Community Wiki for some suggestions. Code that uses the other packages (there should be almost zero) will need to be rethought. -
-TODO: go fix should warn such uses.

Packages moving to subrepositories

diff --git a/src/cmd/fix/go1pkgrename.go b/src/cmd/fix/go1pkgrename.go index c1a11c83c8a..f701f62f0ae 100644 --- a/src/cmd/fix/go1pkgrename.go +++ b/src/cmd/fix/go1pkgrename.go @@ -6,6 +6,7 @@ package main import ( "go/ast" + "strings" ) func init() { @@ -76,10 +77,24 @@ var go1PackageRenames = []struct{ old, new string }{ {"net/dict", "code.google.com/p/go.net/dict"}, {"net/websocket", "code.google.com/p/go.net/websocket"}, {"exp/spdy", "code.google.com/p/go.net/spdy"}, + {"http/spdy", "code.google.com/p/go.net/spdy"}, // go.codereview sub-repository {"encoding/git85", "code.google.com/p/go.codereview/git85"}, {"patch", "code.google.com/p/go.codereview/patch"}, + + // exp + {"ebnf", "exp/ebnf"}, + {"go/types", "exp/types"}, + + // deleted + {"container/vector", ""}, + {"exp/datafmt", ""}, + {"go/typechecker", ""}, + {"old/netchan", ""}, + {"old/regexp", ""}, + {"old/template", ""}, + {"try", ""}, } var go1PackageNameRenames = []struct{ newPath, old, new string }{ @@ -92,12 +107,20 @@ func go1pkgrename(f *ast.File) bool { // First update the imports. for _, rename := range go1PackageRenames { - if !imports(f, rename.old) { + spec := importSpec(f, rename.old) + if spec == nil { + continue + } + if rename.new == "" { + warn(spec.Pos(), "package %q has been deleted in Go 1", rename.old) continue } if rewriteImport(f, rename.old, rename.new) { fixed = true } + if strings.HasPrefix(rename.new, "exp/") { + warn(spec.Pos(), "package %q is not part of Go 1", rename.new) + } } if !fixed { return false diff --git a/src/cmd/fix/go1pkgrename_test.go b/src/cmd/fix/go1pkgrename_test.go index 736e7ed7fc7..22443f806be 100644 --- a/src/cmd/fix/go1pkgrename_test.go +++ b/src/cmd/fix/go1pkgrename_test.go @@ -87,6 +87,11 @@ import ( import "cmath" import poot "exp/template/html" +import ( + "ebnf" + "old/regexp" +) + var _ = cmath.Sin var _ = poot.Poot `, @@ -95,6 +100,11 @@ var _ = poot.Poot import "math/cmplx" import poot "html/template" +import ( + "exp/ebnf" + "old/regexp" +) + var _ = cmplx.Sin var _ = poot.Poot `,