Skip to content

Commit 9c3986d

Browse files
committed
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 <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent e047ae7 commit 9c3986d

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

refactor/rename/mvpkg.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func Move(ctxt *build.Context, from, to, moveTmpl string) error {
6161
}
6262

6363
// Build the import graph and figure out which packages to update.
64-
fwd, rev, errors := importgraph.Build(ctxt)
64+
_, rev, errors := importgraph.Build(ctxt)
6565
if len(errors) > 0 {
6666
// With a large GOPATH tree, errors are inevitable.
6767
// Report them but proceed.
@@ -74,14 +74,17 @@ func Move(ctxt *build.Context, from, to, moveTmpl string) error {
7474
// Determine the affected packages---the set of packages whose import
7575
// statements need updating.
7676
affectedPackages := map[string]bool{from: true}
77-
destinations := map[string]string{} // maps old dir to new dir
77+
destinations := make(map[string]string) // maps old import path to new import path
7878
for pkg := range subpackages(ctxt, srcDir, from) {
7979
for r := range rev[pkg] {
8080
affectedPackages[r] = true
8181
}
82-
destinations[pkg] = strings.Replace(pkg,
83-
// Ensure directories have a trailing "/".
84-
filepath.Join(from, ""), filepath.Join(to, ""), 1)
82+
// Ensure directories have a trailing separator.
83+
dest := strings.Replace(pkg,
84+
filepath.Join(from, ""),
85+
filepath.Join(to, ""),
86+
1)
87+
destinations[pkg] = filepath.ToSlash(dest)
8588
}
8689

8790
// Load all the affected packages.
@@ -100,7 +103,6 @@ func Move(ctxt *build.Context, from, to, moveTmpl string) error {
100103

101104
m := mover{
102105
ctxt: ctxt,
103-
fwd: fwd,
104106
rev: rev,
105107
iprog: iprog,
106108
from: from,
@@ -169,8 +171,8 @@ type mover struct {
169171
// with new package names or import paths.
170172
iprog *loader.Program
171173
ctxt *build.Context
172-
// fwd and rev are the forward and reverse import graphs
173-
fwd, rev importgraph.Graph
174+
// rev is the reverse import graph.
175+
rev importgraph.Graph
174176
// from and to are the source and destination import
175177
// paths. fromDir and toDir are the source and destination
176178
// absolute paths that package source files will be moved between.

refactor/rename/mvpkg_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,13 @@ var _ foo.T
376376
})
377377
var warnings []string
378378
reportError = func(posn token.Position, message string) {
379-
warnings = append(warnings, posn.String()+": "+message)
379+
warning := fmt.Sprintf("%s:%d:%d: %s",
380+
filepath.ToSlash(posn.Filename), // for MS Windows
381+
posn.Line,
382+
posn.Column,
383+
message)
384+
warnings = append(warnings, warning)
385+
380386
}
381387
writeFile = func(filename string, content []byte) error {
382388
got[filename] = string(content)

0 commit comments

Comments
 (0)