golang/go

cmd/go: go list complains about "missing dot" with unknown imports

hajimehoshi opened this issue · 12 comments

What version of Go are you using (go version)?

$ go1.13rc1 version
go version go1.13rc1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hajimehoshi/Library/Caches/go-build"
GOENV="/Users/hajimehoshi/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/hajimehoshi/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/hajimehoshi/sdk/go1.13rc1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/hajimehoshi/sdk/go1.13rc1/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ht/ky_bwgzs4bd5z1hh02k34x_h0000gn/T/go-build377164815=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go1.13rc1 test -v -run=TestClasses -count=1 golang.org/x/mobile/bind/java/

In order to reproduce the problem, the change https://go-review.googlesource.com/c/mobile/+/190479 is required on my local machine to force to use the patched gomobile/gobind. This CL changes $PATH order to use the guilt gomobile/gobind.

What did you expect to see?

The test passes

What did you see instead?

$ go1.13rc1 test -v -run=TestClasses -count=1 ./bind/java/
=== RUN   TestClasses
--- FAIL: TestClasses (5.07s)
    seq_test.go:124: tmpdir = /var/folders/ht/ky_bwgzs4bd5z1hh02k34x_h0000gn/T/bind-java-seq-test-724090206
    seq_test.go:145: /var/folders/ht/ky_bwgzs4bd5z1hh02k34x_h0000gn/T/bind-java-test-401428283/gomobile: /var/folders/ht/ky_bwgzs4bd5z1hh02k34x_h0000gn/T/bind-java-test-401428283/gobind -lang=go,java -outdir=/var/folders/ht/ky_bwgzs4bd5z1hh02k34x_h0000gn/T/gomobile-work-069256369 -tags=aaa,bbb golang.org/x/mobile/bind/testdata/testpkg/javapkg failed: exit status 1                                                                                                             
        type-checking package "golang.org/x/mobile/bind/testdata/testpkg/javapkg" failed (/Users/hajimehoshi/go/src/golang.org/x/mobile/bind/testdata/testpkg/javapkg/classes.go:8:2: could not import Java/java/beans (go/build: importGo Java/java/beans: exit status 1
        can't load package: package Java/java/beans: malformed module path "Java/java/beans": missing dot in first path element                                                                                                              

        ))


    seq_test.go:146: failed to run gomobile bind: exit status 1
FAIL
FAIL    golang.org/x/mobile/bind/java   6.361s
FAIL

This is actually what the try bots are complaining. (Apparently the try bots use Go 1.13 or later).

CC @hyangah

Change https://golang.org/cl/191657 mentions this issue: all: use GOROOT/bin/go instead of go

Inserted a panic at the Go compiler like:

--- a/src/cmd/go/internal/module/module.go
+++ b/src/cmd/go/internal/module/module.go
@@ -184,6 +184,7 @@ func CheckPath(path string) error {
                return fmt.Errorf("malformed module path %q: leading slash", path)
        }
        if !strings.Contains(path[:i], ".") {
+               panic("!?")
                return fmt.Errorf("malformed module path %q: missing dot in first path element", path)
        }
        if path[0] == '-' {

then get the result:

=== RUN   TestClasses
--- FAIL: TestClasses (9.05s)
    seq_test.go:124: tmpdir = /var/folders/ht/ky_bwgzs4bd5z1hh02k34x_h0000gn/T/bind-java-seq-test-129829619
    seq_test.go:145: /var/folders/ht/ky_bwgzs4bd5z1hh02k34x_h0000gn/T/bind-java-test-554361572/gomobile: /var/folders/ht/ky_bwgzs4bd5z1hh02k34x_h0000gn/T/bind-java-test-554361572/gobind -lang=go,java -outdir=/var/folders/ht/ky_bwgzs4bd5z1hh02k34x_h0000gn/T/gomobile-work-831800625 -tags=aaa,bbb golang.org/x/mobile/bind/testdata/testpkg/javapkg failed: exit status 1                                                                                                             
        2019/08/24 04:27:30 go [list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags aaa bbb -- golang.org/x/mobile/bind/testdata/testpkg/javapkg]: exit status 2: go: finding golang.org/x/mobile latest     
        panic: !?

        goroutine 251 [running]:
        cmd/go/internal/module.CheckPath(0xc000686521, 0x17, 0x24ceff1eea4b52ca, 0x164987f)
                /Users/hajimehoshi/go-code/src/cmd/go/internal/module/module.go:187 +0x567
        cmd/go/internal/module.EncodePath(0xc000686521, 0x17, 0xc000234180, 0x0, 0x0, 0xc000432700)
                /Users/hajimehoshi/go-code/src/cmd/go/internal/module/module.go:528 +0x39
        cmd/go/internal/modfetch.newProxyRepo(0x164987f, 0x18, 0xc000686521, 0x17, 0xc0001e4300, 0xc0004328b0, 0x1077040, 0x1ab1b20)                                                                                                         
                /Users/hajimehoshi/go-code/src/cmd/go/internal/modfetch/proxy.go:185 +0x1f2
        cmd/go/internal/modfetch.lookup(0x164987f, 0x18, 0xc000686521, 0x17, 0x15589a0, 0xc0000d0060, 0x3201b28, 0xc0005981c0)                                                                                                               
                /Users/hajimehoshi/go-code/src/cmd/go/internal/modfetch/repo.go:237 +0x1c5
        cmd/go/internal/modfetch.Lookup.func1(0x1ab1b20, 0x15c0fa0)
                /Users/hajimehoshi/go-code/src/cmd/go/internal/modfetch/repo.go:201 +0x57
        cmd/go/internal/par.(*Cache).Do(0x1ab1b20, 0x15c0fa0, 0xc0005981a0, 0xc000432970, 0x4db0ddc2f17fd781, 0x5c6e9f7c6e2ac3fe)                                                                                                            
                /Users/hajimehoshi/go-code/src/cmd/go/internal/par/work.go:128 +0xec
        cmd/go/internal/modfetch.Lookup(0x164987f, 0x18, 0xc000686521, 0x17, 0x4080401000f0000, 0x8d5738e79f2c0001, 0x66f997546da3a0cd, 0x909b8221453f3f14)                                                                                  
                /Users/hajimehoshi/go-code/src/cmd/go/internal/modfetch/repo.go:200 +0xea
        cmd/go/internal/modload.queryProxy(0x164987f, 0x18, 0xc000686521, 0x17, 0x163a23a, 0x6, 0x0, 0x0, 0x1681610, 0xc00019a360, ...)                                                                                                      
                /Users/hajimehoshi/go-code/src/cmd/go/internal/modload/query.go:196 +0x148
        cmd/go/internal/modload.QueryPattern.func3.1(0xc000686521, 0x17, 0xc000686521, 0x17, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)                                                                                                              
                /Users/hajimehoshi/go-code/src/cmd/go/internal/modload/query.go:372 +0xda
        cmd/go/internal/modload.queryPrefixModules.func1(0xc000246190, 0xc000644140, 0xc000686521, 0x17, 0xc000594dc0)
                /Users/hajimehoshi/go-code/src/cmd/go/internal/modload/query.go:442 +0x55
        created by cmd/go/internal/modload.queryPrefixModules
                /Users/hajimehoshi/go-code/src/cmd/go/internal/modload/query.go:441 +0x12b

    seq_test.go:146: failed to run gomobile bind: exit status 1
go1.13rc1 list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags "aaa bbb" -- golang.org/x/mobile/bind/testdata/testpkg/javapkg

outputs a JSON with Err columns:

{
        "ImportPath": "Java/java/beans",
        "DepOnly": true,
        "Incomplete": true,
        "Stale": true,
        "StaleReason": "build ID mismatch",
        "Error": {
                "ImportStack": [
                        "golang.org/x/mobile/bind/testdata/testpkg/javapkg",
                        "Java/java/beans"
                ],
                "Pos": "bind/testdata/testpkg/javapkg/classes.go:8:2",
                "Err": "malformed module path \"Java/java/beans\": missing dot in first path element"
        }
}
{
        "ImportPath": "Java/java/io",
        "DepOnly": true,
        "Incomplete": true,
        "Stale": true,
        "StaleReason": "build ID mismatch",
        "Error": {
                "ImportStack": [
                        "golang.org/x/mobile/bind/testdata/testpkg/javapkg",
                        "Java/java/io"
                ],
                "Pos": "bind/testdata/testpkg/javapkg/classes.go:9:2",
                "Err": "malformed module path \"Java/java/io\": missing dot in first path element"
        }
}
...

go list with javapkg

go1.13rc1 list -json -deps=true -- golang.org/x/mobile/bind/testdata/testpkg/javapkg

results in

{
        "ImportPath": "Java/java/beans",
        "DepOnly": true,
        "Incomplete": true,
        "Stale": true,
        "StaleReason": "build ID mismatch",
        "Error": {
                "ImportStack": [
                        "golang.org/x/mobile/bind/testdata/testpkg/javapkg",
                        "Java/java/beans"
                ],
                "Pos": "bind/testdata/testpkg/javapkg/classes.go:8:2",
                "Err": "malformed module path \"Java/java/beans\": missing dot in first path element"
        }
}
{
        "ImportPath": "Java/java/io",
        "DepOnly": true,
        "Incomplete": true,
        "Stale": true,
        "StaleReason": "build ID mismatch",
        "Error": {
                "ImportStack": [
                        "golang.org/x/mobile/bind/testdata/testpkg/javapkg",
                        "Java/java/io"
                ],
                "Pos": "bind/testdata/testpkg/javapkg/classes.go:9:2",
                "Err": "malformed module path \"Java/java/io\": missing dot in first path element"
        }
}

go list with a Go file with unknown imports

package main

import "foo"

func main() {}

and

go1.13rc1 list -json -deps=true -- ./foo.go

results in

build command-line-arguments: cannot load foo: malformed module path "foo": missing dot in first path element

It looks like the underlying problem here is that you're trying to use gomobile in module mode. That doesn't work yet in general (see #27234).

The error message here is correct: go get in module mode does not know how to resolve a missing import path that does not contain a dot, since that is not a valid FQDN.

Duplicate of #27234

OK, so we might need to fix Go itself for reverse binding. @hyangah , what do you think?

Let's continue discussion at #27234 (comment)

I think in the module mode, we should generate this fake packages inside the main module so go list knows they don't need to be resolved.

so, is this bug fixed?

Yes. This issue happens when Go module is enabled and reverse binding is used at the same time. In the current plan, we don't enable reverse binding when Go module is enabled.