diff --git a/refactor/rename/mvpkg.go b/refactor/rename/mvpkg.go index 927195c11c..cd416c56f9 100644 --- a/refactor/rename/mvpkg.go +++ b/refactor/rename/mvpkg.go @@ -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. diff --git a/refactor/rename/mvpkg_test.go b/refactor/rename/mvpkg_test.go index 1800f6b1de..674fe6cc97 100644 --- a/refactor/rename/mvpkg_test.go +++ b/refactor/rename/mvpkg_test.go @@ -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)