cmd/gomvpkg: fix import rewrites for top-level moved package

The top-level moved package was skipped when doing import rewrites.
Don't skip that package.

Fixes #9811

Change-Id: I1c524ed44606586b5231e5adb6168079aa0e0228
Reviewed-on: https://go-review.googlesource.com/4470
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Michael Matloob 2015-02-10 13:18:58 -08:00 committed by Alan Donovan
parent 88df7a741d
commit d29758bc2e
2 changed files with 26 additions and 5 deletions

View File

@ -255,12 +255,8 @@ func (m *mover) move() error {
} }
} }
// For each affected package, rewrite all imports of the package to // Update import paths for all imports by affected packages.
// use the new import path.
for ap := range m.affectedPackages { for ap := range m.affectedPackages {
if ap == m.from {
continue
}
info, ok := m.iprog.Imported[ap] info, ok := m.iprog.Imported[ap]
if !ok { if !ok {
log.Fatalf("unexpected: package %s is not in import map", ap) log.Fatalf("unexpected: package %s is not in import map", ap)

View File

@ -182,6 +182,31 @@ type T int
"/go/src/bar/sub/0.go": `package sub; type T int`, "/go/src/bar/sub/0.go": `package sub; type T int`,
}, },
}, },
// References into subpackages
{
ctxt: fakeContext(map[string][]string{
"foo": {`package foo; import "foo/a"; var _ a.T`},
"foo/a": {`package a; type T int`},
"foo/b": {`package b; import "foo/a"; var _ a.T`},
}),
from: "foo", to: "bar",
want: map[string]string{
"/go/src/bar/0.go": `package bar
import "bar/a"
var _ a.T
`,
"/go/src/bar/a/0.go": `package a; type T int`,
"/go/src/bar/b/0.go": `package b
import "bar/a"
var _ a.T
`,
},
},
} }
for _, test := range tests { for _, test := range tests {