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

Comments

@hajimehoshi
Copy link
Contributor

@hajimehoshi hajimehoshi commented Jan 21, 2020

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 label Jan 21, 2020
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Jan 21, 2020

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>
@hajimehoshi

This comment has been minimized.

Copy link
Contributor Author

@hajimehoshi hajimehoshi commented Jan 23, 2020

@matloob

This comment has been minimized.

Copy link
Contributor

@matloob 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

This comment has been minimized.

Copy link
Contributor Author

@hajimehoshi hajimehoshi commented Jan 23, 2020

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

This comment has been minimized.

Copy link
Contributor Author

@hajimehoshi hajimehoshi commented Feb 5, 2020

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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Feb 5, 2020

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.