Commit 87815368 authored by Russ Cox's avatar Russ Cox

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
parent c58b6ad0
...@@ -539,8 +539,6 @@ Running <code>go fix</code> will update all imports and package renames for pack ...@@ -539,8 +539,6 @@ Running <code>go fix</code> will update all imports and package renames for pack
remain inside the standard repository. Programs that import packages remain inside the standard repository. Programs that import packages
that are no longer in the standard repository will need to be edited that are no longer in the standard repository will need to be edited
by hand. by hand.
<br>
<font color="red">TODO: go fix should warn about deletions.</font>
</p> </p>
<h3 id="exp">The package tree exp</h3> <h3 id="exp">The package tree exp</h3>
...@@ -581,8 +579,6 @@ If they are installed, they now reside in <code>$GOROOT/bin/tool</code>. ...@@ -581,8 +579,6 @@ If they are installed, they now reside in <code>$GOROOT/bin/tool</code>.
Code that uses packages in <code>exp</code> will need to be updated by hand, Code that uses packages in <code>exp</code> will need to be updated by hand,
or else compiled from an installation that has <code>exp</code> available. or else compiled from an installation that has <code>exp</code> available.
The go fix tool or the compiler will complain about such uses. The go fix tool or the compiler will complain about such uses.
<br>
<font color="red">TODO: go fix should warn about such uses.</font>
</p> </p>
<h3 id="old">The package tree old</h3> <h3 id="old">The package tree old</h3>
...@@ -608,8 +604,6 @@ The packages in their new locations are: ...@@ -608,8 +604,6 @@ The packages in their new locations are:
Code that uses packages now in <code>old</code> will need to be updated by hand, Code that uses packages now in <code>old</code> will need to be updated by hand,
or else compiled from an installation that has <code>old</code> available. or else compiled from an installation that has <code>old</code> available.
The go fix tool will warn about such uses. The go fix tool will warn about such uses.
<br>
<font color="red">TODO: go fix should warn about such uses.</font>
</p> </p>
<h3 id="deleted">Deleted packages</h3> <h3 id="deleted">Deleted packages</h3>
...@@ -636,8 +630,6 @@ slices directly. See ...@@ -636,8 +630,6 @@ slices directly. See
<a href="http://code.google.com/p/go-wiki/wiki/SliceTricks">the Go <a href="http://code.google.com/p/go-wiki/wiki/SliceTricks">the Go
Language Community Wiki</a> for some suggestions. Language Community Wiki</a> for some suggestions.
Code that uses the other packages (there should be almost zero) will need to be rethought. Code that uses the other packages (there should be almost zero) will need to be rethought.
<br>
<font color="red">TODO: go fix should warn such uses.</font>
</p> </p>
<h3 id="subrepo">Packages moving to subrepositories</h3> <h3 id="subrepo">Packages moving to subrepositories</h3>
......
...@@ -463,8 +463,6 @@ Running <code>go fix</code> will update all imports and package renames for pack ...@@ -463,8 +463,6 @@ Running <code>go fix</code> will update all imports and package renames for pack
remain inside the standard repository. Programs that import packages remain inside the standard repository. Programs that import packages
that are no longer in the standard repository will need to be edited that are no longer in the standard repository will need to be edited
by hand. by hand.
<br>
<font color="red">TODO: go fix should warn about deletions.</font>
</p> </p>
<h3 id="exp">The package tree exp</h3> <h3 id="exp">The package tree exp</h3>
...@@ -505,8 +503,6 @@ If they are installed, they now reside in <code>$GOROOT/bin/tool</code>. ...@@ -505,8 +503,6 @@ If they are installed, they now reside in <code>$GOROOT/bin/tool</code>.
Code that uses packages in <code>exp</code> will need to be updated by hand, Code that uses packages in <code>exp</code> will need to be updated by hand,
or else compiled from an installation that has <code>exp</code> available. or else compiled from an installation that has <code>exp</code> available.
The go fix tool or the compiler will complain about such uses. The go fix tool or the compiler will complain about such uses.
<br>
<font color="red">TODO: go fix should warn about such uses.</font>
</p> </p>
<h3 id="old">The package tree old</h3> <h3 id="old">The package tree old</h3>
...@@ -532,8 +528,6 @@ The packages in their new locations are: ...@@ -532,8 +528,6 @@ The packages in their new locations are:
Code that uses packages now in <code>old</code> will need to be updated by hand, Code that uses packages now in <code>old</code> will need to be updated by hand,
or else compiled from an installation that has <code>old</code> available. or else compiled from an installation that has <code>old</code> available.
The go fix tool will warn about such uses. The go fix tool will warn about such uses.
<br>
<font color="red">TODO: go fix should warn about such uses.</font>
</p> </p>
<h3 id="deleted">Deleted packages</h3> <h3 id="deleted">Deleted packages</h3>
...@@ -560,8 +554,6 @@ slices directly. See ...@@ -560,8 +554,6 @@ slices directly. See
<a href="http://code.google.com/p/go-wiki/wiki/SliceTricks">the Go <a href="http://code.google.com/p/go-wiki/wiki/SliceTricks">the Go
Language Community Wiki</a> for some suggestions. Language Community Wiki</a> for some suggestions.
Code that uses the other packages (there should be almost zero) will need to be rethought. Code that uses the other packages (there should be almost zero) will need to be rethought.
<br>
<font color="red">TODO: go fix should warn such uses.</font>
</p> </p>
<h3 id="subrepo">Packages moving to subrepositories</h3> <h3 id="subrepo">Packages moving to subrepositories</h3>
......
...@@ -6,6 +6,7 @@ package main ...@@ -6,6 +6,7 @@ package main
import ( import (
"go/ast" "go/ast"
"strings"
) )
func init() { func init() {
...@@ -76,10 +77,24 @@ var go1PackageRenames = []struct{ old, new string }{ ...@@ -76,10 +77,24 @@ var go1PackageRenames = []struct{ old, new string }{
{"net/dict", "code.google.com/p/go.net/dict"}, {"net/dict", "code.google.com/p/go.net/dict"},
{"net/websocket", "code.google.com/p/go.net/websocket"}, {"net/websocket", "code.google.com/p/go.net/websocket"},
{"exp/spdy", "code.google.com/p/go.net/spdy"}, {"exp/spdy", "code.google.com/p/go.net/spdy"},
{"http/spdy", "code.google.com/p/go.net/spdy"},
// go.codereview sub-repository // go.codereview sub-repository
{"encoding/git85", "code.google.com/p/go.codereview/git85"}, {"encoding/git85", "code.google.com/p/go.codereview/git85"},
{"patch", "code.google.com/p/go.codereview/patch"}, {"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 }{ var go1PackageNameRenames = []struct{ newPath, old, new string }{
...@@ -92,12 +107,20 @@ func go1pkgrename(f *ast.File) bool { ...@@ -92,12 +107,20 @@ func go1pkgrename(f *ast.File) bool {
// First update the imports. // First update the imports.
for _, rename := range go1PackageRenames { 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 continue
} }
if rewriteImport(f, rename.old, rename.new) { if rewriteImport(f, rename.old, rename.new) {
fixed = true fixed = true
} }
if strings.HasPrefix(rename.new, "exp/") {
warn(spec.Pos(), "package %q is not part of Go 1", rename.new)
}
} }
if !fixed { if !fixed {
return false return false
......
...@@ -87,6 +87,11 @@ import ( ...@@ -87,6 +87,11 @@ import (
import "cmath" import "cmath"
import poot "exp/template/html" import poot "exp/template/html"
import (
"ebnf"
"old/regexp"
)
var _ = cmath.Sin var _ = cmath.Sin
var _ = poot.Poot var _ = poot.Poot
`, `,
...@@ -95,6 +100,11 @@ var _ = poot.Poot ...@@ -95,6 +100,11 @@ var _ = poot.Poot
import "math/cmplx" import "math/cmplx"
import poot "html/template" import poot "html/template"
import (
"exp/ebnf"
"old/regexp"
)
var _ = cmplx.Sin var _ = cmplx.Sin
var _ = poot.Poot var _ = poot.Poot
`, `,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment