cmd/gomote: handle unclean GOROOT

The relative path computation in filepath.Walk later in this function
depends on goroot being a clean path, which it is not guaranteed to be.
Switch to filepath.Rel which is more robust.

Also clean GOROOT before use. This isn't required anymore, but should
help avoid future issues as clean paths are easier to work with.

Fixes golang/go#39104

Change-Id: I223c24e57025a93e1c53d20d9afd282465d264fd
Reviewed-on: https://go-review.googlesource.com/c/build/+/339929
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/cmd/gomote/push.go b/cmd/gomote/push.go
index 3bb75be..c6680b8 100644
--- a/cmd/gomote/push.go
+++ b/cmd/gomote/push.go
@@ -47,6 +47,7 @@
 			return errors.New("Failed to get $GOROOT from environment or go env")
 		}
 	}
+	goroot = filepath.Clean(goroot)
 
 	if fs.NArg() != 1 {
 		fs.Usage()
@@ -153,8 +154,12 @@
 		if err != nil {
 			return err
 		}
-		rel := strings.TrimPrefix(filepath.ToSlash(strings.TrimPrefix(path, goroot)), "/")
-		if rel == "" {
+		rel, err := filepath.Rel(goroot, path)
+		if err != nil {
+			return fmt.Errorf("error calculating relative path from %q to %q", goroot, path)
+		}
+		rel = filepath.ToSlash(rel)
+		if rel == "." {
 			return nil
 		}
 		if fi.IsDir() {