Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile/cmd/gomobile: gomobile init fails in an empty module #36668

Closed
hajimehoshi opened this issue Jan 21, 2020 · 6 comments
Closed

x/mobile/cmd/gomobile: gomobile init fails in an empty module #36668

hajimehoshi opened this issue Jan 21, 2020 · 6 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hajimehoshi
Copy link
Member

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

$ go version
go version go1.13.5 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="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/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-build725172147=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. Create an empty directory and go.mod file
$ mkdir gomobileinit
$ cd gomobileinit
$ go mod init foo
  1. Run gomobile init
$ gomobile init

What did you expect to see?

No errors.

What did you see instead?

$ gomobile init
gomobile: exit status 1

The cause is that go-list fails with an empty module:

$ go list -e -f '{{range context.ReleaseTags}}{{if eq . "go1.14"}}{{.}}{{end}}{{end}}'
build .: cannot find module for path .

With a Go file only with package main in the directory, this succeeds.

CC @hyangah

@gopherbot gopherbot added this to the Unreleased milestone Jan 21, 2020
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jan 21, 2020
@gopherbot
Copy link

Change https://golang.org/cl/215419 mentions this issue: cmd/gomobile: output an error message at gomobile-init

gopherbot pushed a commit to golang/mobile that referenced this issue Jan 21, 2020
Updates golang/go#36668

Change-Id: Ic93ea6334dae3fef953bbb928c5246b03279a22f
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/215419
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 21, 2020
@hajimehoshi
Copy link
Member Author

CC @matloob

@matloob
Copy link
Contributor

matloob commented Jan 23, 2020

You're running the go list command from gomubile, right?

When you run the command go list -e -f '{{range context.ReleaseTags}}{{if eq . "go1.14"}}{{.}}{{end}}{{end}}' you're implicitly telling go list to list the package ., the current directory. And that package doesn't exist so go mobile complains.

If you want that command to always succeed you can add a package you know always to exist, such as something in the standard library.

@hajimehoshi
Copy link
Member Author

When you run the command go list -e -f '{{range context.ReleaseTags}}{{if eq . "go1.14"}}{{.}}{{end}}{{end}}' you're implicitly telling go list to list the package ., the current directory. And that package doesn't exist so go mobile complains.

Yes, that's right. I wanted to confirm this was expected. It was a little surprise that just checking the release tag failed in an empty module.

@hajimehoshi
Copy link
Member Author

FYI, the behavior is different between Go 1.14 and older.

$ go list -e 
build .: cannot find module for path .

$ go1.14beta1 list -e 
_/Users/hajimehoshi/test/empty

@gopherbot
Copy link

Change https://golang.org/cl/217700 mentions this issue: cmd/mobile: add an arbitrary package to go-list at gomobile-init

hajimehoshi added a commit to hajimehoshi/ebiten that referenced this issue Feb 15, 2020
This change also eliminates a hack for golang/go#36668
corfe83 added a commit to corfe83/ebiten that referenced this issue Feb 15, 2020
This change also eliminates a hack for golang/go#36668

Co-authored-by: Hajime Hoshi <hajimehoshi@gmail.com>
andydotxyz pushed a commit to fyne-io/fyne that referenced this issue Mar 5, 2020
Updates golang/go#36668
Cherry picked from github.com/golang/mobile
andydotxyz pushed a commit to fyne-io/fyne that referenced this issue Mar 5, 2020
go-list without a given module/package tries to analyze the module
at the current directory. If the current directory's module doesn't
have any Go files and is empty, go-list fails. This is the cause
of the problem that gomobile-init fails if the current directory
is such module.

This CL fixes this issue by giving an arbitrary standard library
when executing go-list.

Fixes golang/go#36668
Cherry picked from github.com/golang/mobile
andydotxyz pushed a commit to fyne-io/fyne that referenced this issue Apr 5, 2020
Updates golang/go#36668
Cherry picked from github.com/golang/mobile
andydotxyz pushed a commit to fyne-io/fyne that referenced this issue Apr 5, 2020
go-list without a given module/package tries to analyze the module
at the current directory. If the current directory's module doesn't
have any Go files and is empty, go-list fails. This is the cause
of the problem that gomobile-init fails if the current directory
is such module.

This CL fixes this issue by giving an arbitrary standard library
when executing go-list.

Fixes golang/go#36668
Cherry picked from github.com/golang/mobile
roderm pushed a commit to roderm/mobile that referenced this issue Sep 13, 2020
go-list without a given module/package tries to analyze the module
at the current directory. If the current directory's module doesn't
have any Go files and is empty, go-list fails. This is the cause
of the problem that gomobile-init fails if the current directory
is such module.

This CL fixes this issue by giving an arbitrary standard library
when executing go-list.

Fixes golang/go#36668

Change-Id: If72d88081c94c2b9ef19d2870b41956a07102122
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/217700
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
@golang golang locked and limited conversation to collaborators Feb 4, 2021
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 10, 2021
go-list without a given module/package tries to analyze the module
at the current directory. If the current directory's module doesn't
have any Go files and is empty, go-list fails. This is the cause
of the problem that gomobile-init fails if the current directory
is such module.

This CL fixes this issue by giving an arbitrary standard library
when executing go-list.

Fixes golang/go#36668

Change-Id: If72d88081c94c2b9ef19d2870b41956a07102122
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/217700
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 11, 2021
go-list without a given module/package tries to analyze the module
at the current directory. If the current directory's module doesn't
have any Go files and is empty, go-list fails. This is the cause
of the problem that gomobile-init fails if the current directory
is such module.

This CL fixes this issue by giving an arbitrary standard library
when executing go-list.

Fixes golang/go#36668

Change-Id: If72d88081c94c2b9ef19d2870b41956a07102122
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/217700
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants