1
0
mirror of https://github.com/golang/go synced 2024-11-18 06:54:49 -07:00

refactor/rename: fix two bugs related to MS Windows' path separator

In the package, the added import declarations used backslashes.
In the test, filenames in warning messages used backslashes.
Now both use forward slash.

Fixes golang/go#16384

Change-Id: I43116aab0b3209305f23ed9def7c4adf3259941e
Reviewed-on: https://go-review.googlesource.com/24943
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Alan Donovan 2016-07-15 10:26:15 -04:00
parent e047ae774b
commit 9c3986db53
2 changed files with 17 additions and 9 deletions

View File

@ -61,7 +61,7 @@ func Move(ctxt *build.Context, from, to, moveTmpl string) error {
}
// Build the import graph and figure out which packages to update.
fwd, rev, errors := importgraph.Build(ctxt)
_, rev, errors := importgraph.Build(ctxt)
if len(errors) > 0 {
// With a large GOPATH tree, errors are inevitable.
// Report them but proceed.
@ -74,14 +74,17 @@ func Move(ctxt *build.Context, from, to, moveTmpl string) error {
// Determine the affected packages---the set of packages whose import
// statements need updating.
affectedPackages := map[string]bool{from: true}
destinations := map[string]string{} // maps old dir to new dir
destinations := make(map[string]string) // maps old import path to new import path
for pkg := range subpackages(ctxt, srcDir, from) {
for r := range rev[pkg] {
affectedPackages[r] = true
}
destinations[pkg] = strings.Replace(pkg,
// Ensure directories have a trailing "/".
filepath.Join(from, ""), filepath.Join(to, ""), 1)
// Ensure directories have a trailing separator.
dest := strings.Replace(pkg,
filepath.Join(from, ""),
filepath.Join(to, ""),
1)
destinations[pkg] = filepath.ToSlash(dest)
}
// Load all the affected packages.
@ -100,7 +103,6 @@ func Move(ctxt *build.Context, from, to, moveTmpl string) error {
m := mover{
ctxt: ctxt,
fwd: fwd,
rev: rev,
iprog: iprog,
from: from,
@ -169,8 +171,8 @@ type mover struct {
// with new package names or import paths.
iprog *loader.Program
ctxt *build.Context
// fwd and rev are the forward and reverse import graphs
fwd, rev importgraph.Graph
// rev is the reverse import graph.
rev importgraph.Graph
// from and to are the source and destination import
// paths. fromDir and toDir are the source and destination
// absolute paths that package source files will be moved between.

View File

@ -376,7 +376,13 @@ var _ foo.T
})
var warnings []string
reportError = func(posn token.Position, message string) {
warnings = append(warnings, posn.String()+": "+message)
warning := fmt.Sprintf("%s:%d:%d: %s",
filepath.ToSlash(posn.Filename), // for MS Windows
posn.Line,
posn.Column,
message)
warnings = append(warnings, warning)
}
writeFile = func(filename string, content []byte) error {
got[filename] = string(content)