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: go get with ... fails in module mode #29363

Closed
rsc opened this issue Dec 20, 2018 · 6 comments
Closed

cmd/go: go get with ... fails in module mode #29363

rsc opened this issue Dec 20, 2018 · 6 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Dec 20, 2018

This used to work and should ideally keep working.

$ go get -u github.com/google/codesearch/cmd/...
go: finding github.com/google/codesearch/cmd/... latest
go: finding github.com/google/codesearch/cmd latest
go: finding github.com/google/codesearch latest
go: downloading github.com/google/codesearch v0.0.0-20150617151851-a45d81b686e8
go: extracting github.com/google/codesearch v0.0.0-20150617151851-a45d81b686e8
go get github.com/google/codesearch/cmd/...: no matching versions for query "latest"
$ go list github.com/google/codesearch/...
go: warning: "github.com/google/codesearch/..." matched no packages
@rsc rsc added this to the Go1.13 milestone Dec 20, 2018
@ALTree ALTree added modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Dec 20, 2018
@thepudds
Copy link
Contributor

thepudds commented Dec 27, 2018

There might be some overlap with #27215 (including #27215 (comment), which describes how the documentation uses go get golang.org/x/perf/cmd/..., but that example fails, unless you have first done something like go get golang.org/x/perf/cmd/benchstat).

@hxzhao527
Copy link

hxzhao527 commented Jan 7, 2019

I think this caued by this

haveGoFiles = haveGoFilesCache.Do(dir, func() interface{} {
f, err := os.Open(dir)
if err != nil {
return false
}
defer f.Close()
names, _ := f.Readdirnames(-1)
for _, name := range names {
if strings.HasSuffix(name, ".go") {
info, err := os.Stat(filepath.Join(dir, name))
if err == nil && info.Mode().IsRegular() {
return true
}
}
}
return false
}).(bool)

when go get -u github.com/google/codesearch/cmd/..., dir is $GOPATH/pkg/mod/github.com/google/codesearch@v1.1.0/cmd/.... So os.Open will return error. And then no go source be throwed and get failed with not found.

I just motify this func to this:

haveGoFiles = haveGoFilesCache.Do(dir, func() interface{} {
		if strings.HasSuffix(dir, "/..."){
			dir = strings.TrimSuffix(dir, "/...")
			tmp, err := filepath.Glob(dir+"/**/*.go")
			if err != nil{
				return false
			}
			return len(tmp) > 0
		}
		f, err := os.Open(dir)
                ...

I did little test, to get

golang.org/x/tools/...
github.com/google/codesearch/cmd/...

And it works.

@gopherbot
Copy link

Change https://golang.org/cl/156757 mentions this issue: cmd/go: fix go get with ... fails in module mode

@mvdan
Copy link
Member

mvdan commented Jan 19, 2019

@bcmills any chance this could be fixed in 1.12, or backported into a 1.12.x release at a later time?

It's great that with https://go-review.googlesource.com/c/go/+/148517, one can tell a program's users to install a specific version easily via GO111MODULE=on go get foo.com/bar@v1.2.3. However, it's a shame that GO111MODULE=on go get foo.com/bar/cmd/...@v1.2.3 doesn't work.

I realise the plan is to fix it in 1.13, but that would mean easy install instructions would be delayed by six months, as one can't expect users to run on betas or master.

@bcmills
Copy link
Contributor

bcmills commented Apr 9, 2019

@mvdan, it's not obvious to me whether the fix will be small or simple enough to backport.

There have been two independent attempts so far, and both have some issues in the details of the semantics and implementation. (The interaction between wildcard-expansion and module resolution is, unfortunately, quite subtle.)

@gopherbot
Copy link

Change https://golang.org/cl/171138 mentions this issue: cmd/go: handle wildcards for unknown modules in "go get"

junkblocker added a commit to junkblocker/codesearch that referenced this issue Jul 12, 2019
junkblocker added a commit to junkblocker/go-pocket that referenced this issue Jul 12, 2019
@golang golang locked and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants