cmd/gomobile: remove the logic to clean the given path
This CL fixes an issue that a relative path didn't work with
gomobile. path.Clean removed the prefix './' and this was too
aggressive. path.Clean was needed for go/build.Context.Import
(see golang/go#18876), but they have already been replaced with
packages.Load, so clearning paths is no longer needed.
Updates golang/go#27234
Change-Id: Ife28da6d845baaf94e627a7a44a5e962b8a1d013
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/214497
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/cmd/gomobile/bind.go b/cmd/gomobile/bind.go
index 2676bfe..c203791 100644
--- a/cmd/gomobile/bind.go
+++ b/cmd/gomobile/bind.go
@@ -13,7 +13,6 @@
"io/ioutil"
"os"
"os/exec"
- "path"
"path/filepath"
"strings"
@@ -135,11 +134,7 @@
func importPackages(args []string, targetOS string) ([]*packages.Package, error) {
config := packagesConfig(targetOS)
- var cleaned []string
- for _, a := range args {
- cleaned = append(cleaned, path.Clean(a))
- }
- return packages.Load(config, cleaned...)
+ return packages.Load(config, args...)
}
var (
diff --git a/cmd/gomobile/bind_test.go b/cmd/gomobile/bind_test.go
index d6ca3f6..752d9d7 100644
--- a/cmd/gomobile/bind_test.go
+++ b/cmd/gomobile/bind_test.go
@@ -9,7 +9,6 @@
"io/ioutil"
"os"
"os/exec"
- "path"
"path/filepath"
"runtime"
"strings"
@@ -17,21 +16,6 @@
"text/template"
)
-func TestImportPackagesPathCleaning(t *testing.T) {
- if runtime.GOOS == "android" {
- t.Skip("not available on Android")
- }
- slashPath := "golang.org/x/mobile/example/bind/hello/"
- pkgs, err := importPackages([]string{slashPath}, runtime.GOOS)
- if err != nil {
- t.Fatal(err)
- }
- p := pkgs[0]
- if c := path.Clean(slashPath); p.PkgPath != c {
- t.Errorf("expected %s; got %s", c, p.PkgPath)
- }
-}
-
func TestBindAndroid(t *testing.T) {
androidHome := os.Getenv("ANDROID_HOME")
if androidHome == "" {
@@ -258,12 +242,28 @@
case "ios":
out = filepath.Join(dir, "Cgopkg.framework")
}
- cmd := exec.Command(filepath.Join(dir, "gomobile"), "bind", "-target="+target, "-o="+out, "golang.org/x/mobile/bind/testdata/cgopkg")
- cmd.Env = append(os.Environ(), "PATH="+path, "GO111MODULE=on")
- var b bytes.Buffer
- cmd.Stderr = &b
- if err := cmd.Run(); err != nil {
- t.Errorf("%v: %s", err, string(b.Bytes()))
+
+ // Absolute path
+ {
+ cmd := exec.Command(filepath.Join(dir, "gomobile"), "bind", "-target="+target, "-o="+out, "golang.org/x/mobile/bind/testdata/cgopkg")
+ cmd.Env = append(os.Environ(), "PATH="+path, "GO111MODULE=on")
+ var b bytes.Buffer
+ cmd.Stderr = &b
+ if err := cmd.Run(); err != nil {
+ t.Errorf("%v: %s", err, string(b.Bytes()))
+ }
+ }
+
+ // Relative path
+ {
+ cmd := exec.Command(filepath.Join(dir, "gomobile"), "bind", "-target="+target, "-o="+out, "./bind/testdata/cgopkg")
+ cmd.Env = append(os.Environ(), "PATH="+path, "GO111MODULE=on")
+ cmd.Dir = filepath.Join("..", "..")
+ var b bytes.Buffer
+ cmd.Stderr = &b
+ if err := cmd.Run(); err != nil {
+ t.Errorf("%v: %s", err, string(b.Bytes()))
+ }
}
})
}