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

cmd/go: directory named go.mod defines new module but is otherwise ignored #30788

Closed
heschik opened this issue Mar 12, 2019 · 4 comments

Comments

Projects
None yet
4 participants
@heschik
Copy link
Contributor

commented Mar 12, 2019

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

go version devel +ee6bec958d Fri Mar 1 18:35:31 2019 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

I have no idea how I ended up with a go.mod directory, but I did. I discovered this in x/tools so that's where the repro is.

tools/imports (master)$ git reset --hard
HEAD is now at e65039ee internal/lsp: make sure completion items are never null
tools/imports (master)$ GO111MODULE=on go list .  
golang.org/x/tools/imports
tools/imports (master)$ mkdir go.mod
tools/imports (master)$ GO111MODULE=on go list .
go: finding golang.org/x/tools/imports latest
can't load package: package golang.org/x/tools/imports: unknown import path "golang.org/x/tools/imports": cannot find module providing package golang.org/x/tools/imports
tools/imports (master)$ GO111MODULE=on go mod tidy
go: finding golang.org/x/tools/imports latest
tools/imports (master)$ echo $?
0
tools/imports (master)$ echo 'module golang.org/x/tools' > ../go.mod
tools/imports (master*)$ GO111MODULE=on go mod tidy
tools/imports (master*)$ GO111MODULE=on go mod tidy                  
[snip]
tools/imports (master*)$ cat ../go.mod
module golang.org/x/tools

go 1.12

require golang.org/x/net v0.0.0-20190311183353-d8887717615a

The way it's ignored by tidy is strange; I imagine there are two code paths for finding go.mod and only one of them checks whether the file is a regular file. This is particularly confusing since Git won't show you an empty directory in git status.

@bcmills

This comment has been minimized.

Copy link
Member

commented Mar 13, 2019

I imagine there are two code paths for finding go.mod and only one of them checks whether the file is a regular file.

Three, actually. And you're right that only one of them checks for a file vs. a directory:

if fi, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil && !fi.IsDir() {

if _, err := os.Stat(filepath.Join(path, "go.mod")); err == nil {

_, err := os.Stat(filepath.Join(d, "go.mod"))

@bcmills

This comment has been minimized.

Copy link
Member

commented Mar 13, 2019

Make that four. And two of them check.

go/src/go/build/build.go

Lines 1042 to 1043 in 5f40351

info, err := os.Stat(filepath.Join(abs, "go.mod"))
if err == nil && !info.IsDir() {

@bcmills

This comment has been minimized.

Copy link
Member

commented Mar 13, 2019

Five.

if _, err := os.Stat(filepath.Join(path, "go.mod")); err == nil {

@gopherbot

This comment has been minimized.

Copy link

commented Mar 14, 2019

Change https://golang.org/cl/167393 mentions this issue: cmd: ignore the directory named go.mod

@gopherbot gopherbot closed this in fa5dbd0 Mar 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.