cmd/gomobile: clean package paths

Clean the package paths so gomobile use the same directory for the
export data (*.a) files as the go tool.

Fixes golang/go#18876.

Change-Id: I40285f9203f04dbb80b21bd74d9b24212b677533
Reviewed-on: https://go-review.googlesource.com/37323
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/cmd/gomobile/bind.go b/cmd/gomobile/bind.go
index 40259f8..4b34f97 100644
--- a/cmd/gomobile/bind.go
+++ b/cmd/gomobile/bind.go
@@ -139,10 +139,11 @@
 
 func importPackages(args []string) ([]*build.Package, error) {
 	pkgs := make([]*build.Package, len(args))
-	for i, path := range args {
+	for i, a := range args {
+		a = path.Clean(a)
 		var err error
-		if pkgs[i], err = ctx.Import(path, cwd, build.ImportComment); err != nil {
-			return nil, fmt.Errorf("package %q: %v", path, err)
+		if pkgs[i], err = ctx.Import(a, cwd, build.ImportComment); err != nil {
+			return nil, fmt.Errorf("package %q: %v", a, err)
 		}
 	}
 	return pkgs, nil
diff --git a/cmd/gomobile/bind_test.go b/cmd/gomobile/bind_test.go
index 0e3abae..415c1d9 100644
--- a/cmd/gomobile/bind_test.go
+++ b/cmd/gomobile/bind_test.go
@@ -7,6 +7,7 @@
 import (
 	"bytes"
 	"os"
+	"path"
 	"path/filepath"
 	"strings"
 	"testing"
@@ -15,6 +16,18 @@
 
 // TODO(crawshaw): TestBindIOS
 
+func TestImportPackagesPathCleaning(t *testing.T) {
+	slashPath := "golang.org/x/mobile/example/bind/hello/"
+	pkgs, err := importPackages([]string{slashPath})
+	if err != nil {
+		t.Fatal(err)
+	}
+	p := pkgs[0]
+	if c := path.Clean(slashPath); p.ImportPath != c {
+		t.Errorf("expected %s; got %s", c, p.ImportPath)
+	}
+}
+
 func TestBindAndroid(t *testing.T) {
 	androidHome := os.Getenv("ANDROID_HOME")
 	if androidHome == "" {