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 mod tidy downloads v1 module, not clear whether it's necessary or not #46939

Closed
marystern opened this issue Jun 26, 2021 · 1 comment
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@marystern
Copy link

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

$ go version
go version go1.16.4 linux/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
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"

What did you do?

I'm trying to understand why go mod tidy is accessing a v1 module when only the v2 module is required. in particular, this line seems odd as a v1 module that is not required is being downloaded (full details further below):

$ go mod tidy
go: downloading github.com/hajimehoshi/ebiten v1.12.12

..but..

(main module does not need package github.com/hajimehoshi/ebiten)

Here are the full details (create a main.go file and then make it into a module and run go mod tidy).

(
cat <<EOF
package main

import (
	"log"

	"github.com/hajimehoshi/ebiten/v2"
	"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)

type Game struct{}

func (g *Game) Update() error {
	return nil
}

func (g *Game) Draw(screen *ebiten.Image) {
	ebitenutil.DebugPrint(screen, "Hello, World!")
}

func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
	return 320, 240
}

func main() {
	ebiten.SetWindowSize(640, 480)
	ebiten.SetWindowTitle("Hello, World!")
	if err := ebiten.RunGame(&Game{}); err != nil {
		log.Fatal(err)
	}
}

EOF
) > main.go

$ go mod init local
go: creating new go.mod: module local
go: to add module requirements and sums:
	go mod tidy

$ go mod tidy
go: finding module for package github.com/hajimehoshi/ebiten/v2/ebitenutil
go: finding module for package github.com/hajimehoshi/ebiten/v2
go: downloading github.com/hajimehoshi/ebiten/v2 v2.1.2
go: downloading github.com/hajimehoshi/ebiten v1.12.12          <<<*** WHY? ***
go: found github.com/hajimehoshi/ebiten/v2 in github.com/hajimehoshi/ebiten/v2 v2.1.2
go: found github.com/hajimehoshi/ebiten/v2/ebitenutil in github.com/hajimehoshi/ebiten/v2 v2.1.2
go: downloading golang.org/x/sys v0.0.0-20210415045647-66c3f260301c
go: downloading github.com/gofrs/flock v0.8.0
go: downloading golang.org/x/mobile v0.0.0-20210220033013-bdb1ca9a1e08
go: downloading golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb
go: downloading golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
go: downloading golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56


$ cat go.mod
module local

go 1.16

require github.com/hajimehoshi/ebiten/v2 v2.1.2

$ go mod why github.com/hajimehoshi/ebiten/v2
# github.com/hajimehoshi/ebiten/v2
local
github.com/hajimehoshi/ebiten/v2

$ go mod why github.com/hajimehoshi/ebiten
# github.com/hajimehoshi/ebiten
(main module does not need package github.com/hajimehoshi/ebiten)

$ go mod graph
local github.com/hajimehoshi/ebiten/v2@v2.1.2
github.com/hajimehoshi/ebiten/v2@v2.1.2 github.com/go-gl/glfw/v3.3/glfw@v0.0.0-20210410170116-ea3d685f79fb
github.com/hajimehoshi/ebiten/v2@v2.1.2 github.com/gofrs/flock@v0.8.0
github.com/hajimehoshi/ebiten/v2@v2.1.2 github.com/hajimehoshi/bitmapfont/v2@v2.1.3
github.com/hajimehoshi/ebiten/v2@v2.1.2 github.com/hajimehoshi/file2byteslice@v0.0.0-20200812174855-0e5e8a80490e
github.com/hajimehoshi/ebiten/v2@v2.1.2 github.com/hajimehoshi/go-mp3@v0.3.2
github.com/hajimehoshi/ebiten/v2@v2.1.2 github.com/hajimehoshi/oto@v0.7.1
github.com/hajimehoshi/ebiten/v2@v2.1.2 github.com/jakecoffman/cp@v1.1.0
github.com/hajimehoshi/ebiten/v2@v2.1.2 github.com/jfreymuth/oggvorbis@v1.0.3
github.com/hajimehoshi/ebiten/v2@v2.1.2 golang.org/x/image@v0.0.0-20210220032944-ac19c3e999fb
github.com/hajimehoshi/ebiten/v2@v2.1.2 golang.org/x/mobile@v0.0.0-20210220033013-bdb1ca9a1e08
github.com/hajimehoshi/ebiten/v2@v2.1.2 golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c
github.com/hajimehoshi/ebiten/v2@v2.1.2 golang.org/x/sys@v0.0.0-20210415045647-66c3f260301c
github.com/hajimehoshi/ebiten/v2@v2.1.2 golang.org/x/tools@v0.1.0
github.com/hajimehoshi/ebiten/v2@v2.1.2 gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c
github.com/hajimehoshi/bitmapfont/v2@v2.1.3 github.com/pkg/browser@v0.0.0-20180916011732-0a3d74bf9ce4
github.com/hajimehoshi/bitmapfont/v2@v2.1.3 golang.org/x/image@v0.0.0-20190703141733-d6a02ce849c9
github.com/hajimehoshi/bitmapfont/v2@v2.1.3 golang.org/x/text@v0.3.0
github.com/hajimehoshi/go-mp3@v0.3.2 github.com/hajimehoshi/oto@v0.6.1
github.com/hajimehoshi/oto@v0.7.1 golang.org/x/mobile@v0.0.0-20190415191353-3e0bab5405d6
github.com/hajimehoshi/oto@v0.7.1 golang.org/x/sys@v0.0.0-20190429190828-d89cdac9e872
github.com/jfreymuth/oggvorbis@v1.0.3 github.com/jfreymuth/vorbis@v1.0.2
golang.org/x/image@v0.0.0-20210220032944-ac19c3e999fb golang.org/x/text@v0.3.0
golang.org/x/mobile@v0.0.0-20210220033013-bdb1ca9a1e08 golang.org/x/exp@v0.0.0-20190731235908-ec7cb31e5a56
golang.org/x/mobile@v0.0.0-20210220033013-bdb1ca9a1e08 golang.org/x/image@v0.0.0-20190802002840-cff245a6509b
golang.org/x/mobile@v0.0.0-20210220033013-bdb1ca9a1e08 golang.org/x/mod@v0.1.1-0.20191209134235-331c550502dd
golang.org/x/mobile@v0.0.0-20210220033013-bdb1ca9a1e08 golang.org/x/tools@v0.0.0-20200117012304-6edc0a871e69
golang.org/x/tools@v0.1.0 github.com/yuin/goldmark@v1.2.1
golang.org/x/tools@v0.1.0 golang.org/x/mod@v0.3.0
golang.org/x/tools@v0.1.0 golang.org/x/net@v0.0.0-20201021035429-f5854403a974
golang.org/x/tools@v0.1.0 golang.org/x/sync@v0.0.0-20201020160332-67f06af15bc9
golang.org/x/tools@v0.1.0 golang.org/x/sys@v0.0.0-20210119212857-b64e53b001e4
golang.org/x/tools@v0.1.0 golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1
gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c github.com/kr/pretty@v0.2.1
golang.org/x/image@v0.0.0-20190703141733-d6a02ce849c9 golang.org/x/text@v0.3.0
github.com/hajimehoshi/oto@v0.6.1 golang.org/x/mobile@v0.0.0-20190415191353-3e0bab5405d6
github.com/hajimehoshi/oto@v0.6.1 golang.org/x/sys@v0.0.0-20190429190828-d89cdac9e872
golang.org/x/mobile@v0.0.0-20190415191353-3e0bab5405d6 golang.org/x/exp@v0.0.0-20190306152737-a1d7652674e8
golang.org/x/mobile@v0.0.0-20190415191353-3e0bab5405d6 golang.org/x/image@v0.0.0-20190227222117-0694c2d4d067
golang.org/x/mobile@v0.0.0-20190415191353-3e0bab5405d6 golang.org/x/sys@v0.0.0-20190312061237-fead79001313
golang.org/x/exp@v0.0.0-20190731235908-ec7cb31e5a56 github.com/BurntSushi/xgb@v0.0.0-20160522181843-27f122750802
golang.org/x/exp@v0.0.0-20190731235908-ec7cb31e5a56 golang.org/x/image@v0.0.0-20190227222117-0694c2d4d067
golang.org/x/exp@v0.0.0-20190731235908-ec7cb31e5a56 golang.org/x/mobile@v0.0.0-20190312151609-d3739f865fa6
golang.org/x/exp@v0.0.0-20190731235908-ec7cb31e5a56 golang.org/x/mod@v0.1.0
golang.org/x/exp@v0.0.0-20190731235908-ec7cb31e5a56 golang.org/x/sys@v0.0.0-20190412213103-97732733099d
golang.org/x/exp@v0.0.0-20190731235908-ec7cb31e5a56 golang.org/x/tools@v0.0.0-20190312151545-0bb0c0a6e846
golang.org/x/image@v0.0.0-20190802002840-cff245a6509b golang.org/x/text@v0.3.0
golang.org/x/mod@v0.1.1-0.20191209134235-331c550502dd golang.org/x/crypto@v0.0.0-20191011191535-87dc89f01550
golang.org/x/mod@v0.1.1-0.20191209134235-331c550502dd golang.org/x/tools@v0.0.0-20191119224855-298f0cb1881e
golang.org/x/mod@v0.1.1-0.20191209134235-331c550502dd golang.org/x/xerrors@v0.0.0-20191011141410-1b5146add898
golang.org/x/tools@v0.0.0-20200117012304-6edc0a871e69 golang.org/x/mod@v0.1.1-0.20191105210325-c90efee705ee
golang.org/x/tools@v0.0.0-20200117012304-6edc0a871e69 golang.org/x/net@v0.0.0-20190620200207-3b0461eec859
golang.org/x/tools@v0.0.0-20200117012304-6edc0a871e69 golang.org/x/sync@v0.0.0-20190423024810-112230192c58
golang.org/x/tools@v0.0.0-20200117012304-6edc0a871e69 golang.org/x/xerrors@v0.0.0-20191011141410-1b5146add898
golang.org/x/mod@v0.3.0 golang.org/x/crypto@v0.0.0-20191011191535-87dc89f01550
golang.org/x/mod@v0.3.0 golang.org/x/tools@v0.0.0-20191119224855-298f0cb1881e
golang.org/x/mod@v0.3.0 golang.org/x/xerrors@v0.0.0-20191011141410-1b5146add898
golang.org/x/net@v0.0.0-20201021035429-f5854403a974 golang.org/x/crypto@v0.0.0-20200622213623-75b288015ac9
golang.org/x/net@v0.0.0-20201021035429-f5854403a974 golang.org/x/sys@v0.0.0-20200930185726-fdedc70b468f
golang.org/x/net@v0.0.0-20201021035429-f5854403a974 golang.org/x/text@v0.3.3
github.com/kr/pretty@v0.2.1 github.com/kr/text@v0.1.0
golang.org/x/image@v0.0.0-20190227222117-0694c2d4d067 golang.org/x/text@v0.3.0
golang.org/x/mod@v0.1.0 golang.org/x/crypto@v0.0.0-20190510104115-cbcb75029529
golang.org/x/tools@v0.0.0-20190312151545-0bb0c0a6e846 golang.org/x/net@v0.0.0-20190311183353-d8887717615a
golang.org/x/crypto@v0.0.0-20191011191535-87dc89f01550 golang.org/x/net@v0.0.0-20190404232315-eb5bcb51f2a3
golang.org/x/crypto@v0.0.0-20191011191535-87dc89f01550 golang.org/x/sys@v0.0.0-20190412213103-97732733099d
golang.org/x/tools@v0.0.0-20191119224855-298f0cb1881e golang.org/x/net@v0.0.0-20190620200207-3b0461eec859
golang.org/x/tools@v0.0.0-20191119224855-298f0cb1881e golang.org/x/sync@v0.0.0-20190423024810-112230192c58
golang.org/x/tools@v0.0.0-20191119224855-298f0cb1881e golang.org/x/xerrors@v0.0.0-20190717185122-a985d3407aa7
golang.org/x/mod@v0.1.1-0.20191105210325-c90efee705ee golang.org/x/crypto@v0.0.0-20191011191535-87dc89f01550
golang.org/x/mod@v0.1.1-0.20191105210325-c90efee705ee golang.org/x/xerrors@v0.0.0-20191011141410-1b5146add898
golang.org/x/net@v0.0.0-20190620200207-3b0461eec859 golang.org/x/crypto@v0.0.0-20190308221718-c2843e01d9a2
golang.org/x/net@v0.0.0-20190620200207-3b0461eec859 golang.org/x/sys@v0.0.0-20190215142949-d0b11bdaac8a
golang.org/x/net@v0.0.0-20190620200207-3b0461eec859 golang.org/x/text@v0.3.0
golang.org/x/crypto@v0.0.0-20200622213623-75b288015ac9 golang.org/x/net@v0.0.0-20190404232315-eb5bcb51f2a3
golang.org/x/crypto@v0.0.0-20200622213623-75b288015ac9 golang.org/x/sys@v0.0.0-20190412213103-97732733099d
golang.org/x/text@v0.3.3 golang.org/x/tools@v0.0.0-20180917221912-90fa682c2a6e
github.com/kr/text@v0.1.0 github.com/kr/pty@v1.1.1
golang.org/x/crypto@v0.0.0-20190510104115-cbcb75029529 golang.org/x/net@v0.0.0-20190404232315-eb5bcb51f2a3
golang.org/x/crypto@v0.0.0-20190510104115-cbcb75029529 golang.org/x/sys@v0.0.0-20190412213103-97732733099d
golang.org/x/net@v0.0.0-20190311183353-d8887717615a golang.org/x/crypto@v0.0.0-20190308221718-c2843e01d9a2
golang.org/x/net@v0.0.0-20190311183353-d8887717615a golang.org/x/text@v0.3.0
golang.org/x/net@v0.0.0-20190404232315-eb5bcb51f2a3 golang.org/x/crypto@v0.0.0-20190308221718-c2843e01d9a2
golang.org/x/net@v0.0.0-20190404232315-eb5bcb51f2a3 golang.org/x/text@v0.3.0
golang.org/x/crypto@v0.0.0-20190308221718-c2843e01d9a2 golang.org/x/sys@v0.0.0-20190215142949-d0b11bdaac8a

What did you expect to see?

I expected to only see the v2 module, and not the v1.

(Is this something to do with transitive dependencies? Does "mod why" report these?)

What did you see instead?

both v1 and v2 being downloaded.

@dmitshur dmitshur added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 28, 2021
@dmitshur dmitshur added this to the Backlog milestone Jun 28, 2021
@dmitshur dmitshur changed the title go mod tidy downloads unnecessary v1 module? cmd/go: go mod tidy downloads v1 module, not clear whether it's necessary or not Jun 28, 2021
@jayconrod
Copy link
Contributor

This is happening when go mod tidy is attempting to resolve the import of github.com/hajimehoshi/ebiten/v2 (or ebitenutil) to a module. There's no marker within the import path that indicates what part of the string is the containing module, and what's a subdirectory within the module. For example, it's possible this package could be in the v2 subdirectory of the module github.com/hajimehoshi/ebiten.

So the go command attempts to fetch each possible prefix of the module. It will try to download the latest version of github.com, github.com/hajimehoshi, and so on. Usually there's only one actual module in that list, but if there's more than one module that provides that package, the go command picks the longest match to add to go.mod.

Resolving a package to a module has more information on this.

As part of this lookup process, extra modules may be downloaded into the module cache (hence the downloading messages). In this case, github.com/hajimehoshi/ebiten won't appear in go.mod or go.sum though and won't be used in later builds.

@golang golang locked and limited conversation to collaborators Jul 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go 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