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>
This commit is contained in:
Hajime Hoshi 2020-01-14 01:12:27 +09:00
parent 1d13e329d2
commit b9f03b3fa3
2 changed files with 23 additions and 28 deletions

View File

@ -13,7 +13,6 @@ import (
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
@ -135,11 +134,7 @@ func runBind(cmd *command) error {
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 (

View File

@ -9,7 +9,6 @@ import (
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
@ -17,21 +16,6 @@ import (
"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 @@ func TestBindWithGoModules(t *testing.T) {
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()))
}
}
})
}