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: provide an option to print toolchain switch #63939

Open
hyangah opened this issue Nov 3, 2023 · 9 comments
Open

cmd/go: provide an option to print toolchain switch #63939

hyangah opened this issue Nov 3, 2023 · 9 comments
Assignees
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented Nov 3, 2023

Sometimes we want to trace how and where go picks up the target toolchain.
(is it from module cache? or is it from one of my PATH that may have a symlink?)
Either a debug environment variable or a flag (-x or -v) to enable tool switch activity logging can be helpful.

@heschi heschi added the GoCommand cmd/go label Nov 6, 2023
@heschi
Copy link
Contributor

heschi commented Nov 6, 2023

cc @bcmills @matloob

@heschi heschi added this to the Go1.22 milestone Nov 6, 2023
@heschi heschi added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 6, 2023
@bcmills
Copy link
Contributor

bcmills commented Nov 6, 2023

I think the existing -x flag is the right fit — it should emit a comment when we switch toolchains.

@raghvenders
Copy link
Contributor

raghvenders commented Nov 11, 2023

@bcmills , @hyangah - I would like to work on this feature change.

Currently I did a small local setup on this go.mod file.

Which are those go commands we can show the information about switch?


module change-tc

go 1.21.1

toolchain go1.21.4

by local go env modifies as below


set GOROOT=C:\Users\R\go\pkg\mod\golang.org\toolchain@v0.0.1-go1.21.4.windows-amd64
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\R\go\pkg\mod\golang.org\toolchain@v0.0.1-go1.21.4.windows-amd64\pkg\tool\windows_amd64

Note : Current relevant go [...] -x shows the updated toolchain location.

@raghvenders
Copy link
Contributor

raghvenders commented Nov 11, 2023

Are we refering situations mentioned - https://go.dev/doc/toolchain - Go toolchain switches, especially after it has been switched , but not showing the message during subsequent calls ?

@raghvenders
Copy link
Contributor

Can we fix this issue - cmd/go: go env GOMOD tries to download newer toolchain #61455 along with this. It has to make an appropriate switch here?

@raghvenders
Copy link
Contributor

raghvenders commented Nov 13, 2023

@hyangah - I did try to address for "toolchain not available" issue and switching to go version executing this command or local available go in PATH.
Please let me know if I can raise a CL for this.


C:\Users\R\golang\analyse-bugs>cat go.mod
module example.com/analyze-bugs

go 1.23

C:\Users\R\golang\analyse-bugs>"C:\Program Files\Go\bin\go" run .
go: downloading go1.23 (windows/amd64)
go: download go1.23 for windows/amd64: toolchain not available

C:\Users\R\golang\analyse-bugs>go run .
go: downloading go1.23 (windows/amd64)
go: download go1.23 for windows/amd64: toolchain not available
Switching to your local go version executing this command: devel go1.22-5f08b44799 Mon Nov 13 14:11:13 2023 +0000 windows/amd64
Swithing Go line in go.mod file to : go 1.22 ------ go.mod ------
module example.com/analyze-bugs

go 1.22
====================
Go.mod file is switched to go 1.22 . Kindly re-execute the relevant commands
C:\Users\R\golang\analyse-bugs>go run .
Hello World

@bcmills
Copy link
Contributor

bcmills commented Dec 4, 2023

@raghvenders, I think #61455 is basically orthogonal to this issue: this one is about logging when we do switch toolchains, while the other is about whether we switch toolchains at all for a particular command.

@raghvenders
Copy link
Contributor

sure I will send a separate CL for this one.

@raghvenders
Copy link
Contributor

@bcmills @hyangah - here is the CL for this - https://go-review.googlesource.com/c/go/+/548437

I have few questions currently toolchain switch is called at the very base of pretty every go command.

It must be called early in startup - See https://go.dev/doc/toolchain#select -

  1. If we use x where it is not a valid flag, it shows x is not valid flag but will show the toolchain switch message , for example : go help mod -x. Technically toolchain switch currently happens for all commands if needed and then execute the command as subprocess or syscall.exec.

Kindly suggest.

@gopherbot gopherbot modified the milestones: Go1.22, Go1.23 Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants