go version)?go version devel +2e9f0817f0 Tue Oct 30 04:39:53 2018 +0000 linux/amd64
Yes.
go env)?GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mvdan/go/cache"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mvdan/go/land:/home/mvdan/go"
GOPROXY=""
GORACE=""
GOROOT="/home/mvdan/tip"
GOTMPDIR=""
GOTOOLDIR="/home/mvdan/tip/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build160474966=/tmp/go-build -gno-record-gcc-switches"
Try to use a testdata Go module. This is useful so that one can have Go packages that can import each other, to be used as input for a tool's tests. Below is a simple reproduction script.
rm -rf testdata
mkdir testdata
cd testdata
go mod init testdata.tld/foo
cat >main.go <<EOF
package foo
import _ "golang.org/x/tools/go/packages"
EOF
echo ====
cat go.mod
echo ====
go build
echo ====
cat go.mod
echo ====
go mod tidy
echo ====
cat go.mod
echo ====
The go mod tidy at the end being a no-op.
The go mod tidy removing the dependency that go build added.
$ bash repro.sh
go: creating new go.mod: module testdata.tld/foo
====
module testdata.tld/foo
====
go: finding golang.org/x/tools/go/packages latest
go: finding golang.org/x/tools/go latest
go: finding golang.org/x/tools latest
====
module testdata.tld/foo
require golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b
====
====
module testdata.tld/foo
====
Thanks to @myitcv for helping debug what was going on.
Contrast #27852. (I don't think the two actually conflict, but the interaction between testdata and modules threads a fine line.)
I'm having the very same issue when creating a module directly in a sub-directory like _fuzz/. In this case, I was trying to track the tooling and build dependencies for fuzzing my module, without polluting the tiny go.mod that it has.
So I think the issue here is when the root module directory is itself a "hidden" directory as well.
Another fun problem - running go mod vendor with a non-empty go.mod is also impossible:
$ go mod vendor
go: no dependencies to vendor
Change https://golang.org/cl/196297 mentions this issue: cmd/go/internal/modload: do not prune the module root when walking directories
I went to re-triage this issue to see whether it was still reproducible and how involved a fix would be, and accidentally wrote a fix. 馃槄
Most helpful comment
I went to re-triage this issue to see whether it was still reproducible and how involved a fix would be, and accidentally wrote a fix. 馃槄