Skip to content

Commit

Permalink
extension: update go to go1.23.1
Browse files Browse the repository at this point in the history
We want to use the latest go when developing our own
release/testing support tools and scripts.
So, update go.mod to do so.

However, we need to be careful when using
the `installtools` script.
The purpose of `installtools` is to install tools
needed by integration tests. It selected the latest
version of each tool compatible with the default
go version in the system. For example, in the CI is
setup with go1.22, we want to install tools that
officially claim they support go1.22.

`installtools` detects the go version using
the `go` command. As we change our go.mod to use
go1.23.1 as the go directive, the `go` command running
under our project's repo directory (with GOTOOLCHAIN=auto)
will always be go1.23.1 or newer. That makes go1.22 CI
meaningless.

So, pass `GOTOOLCHAIN=local` when `installtools` computes
the go version using `go list`.

Previously we used `go run` to build/invoke this tool.
But it turned out `go run`/`go generate` modify
(or will modify) `GOROOT` and/or `PATH` when toolchain
switch occurs, which will prevent `installtools`
from detecting the system default toolchain version
even with `GOTOOLCHAIN=local`, or cause the
build fail due to mismatching GOROOT and go toolchain
picked up from PATH.

Therefore, in this CL, we build the binary (it's ok to
build the binary with go1.23.1+), and then run
the installed binary ourselves so the execution of
the binary doesn't get inherit the modified GOROOT/PATH.

For golang#3411

Change-Id: I3e116cf48fb431196359ec42049e70c0b75814ef
  • Loading branch information
hyangah committed Oct 10, 2024
1 parent 81f04c5 commit b4defa9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 34 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/test-long-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,19 @@ jobs:
check-latest: true
cache: true

- name: Install dependencies
- name: Install NPM dependencies
run: npm ci
working-directory: ./extension

- name: Compile
run: npm run vscode:prepublish
working-directory: ./extension

- name: Install Go tools (Modules mode)
- name: Install tools dependencies
run: |
go version
go run ./tools/installtools/main.go
go install ./tools/installtools
installtools
working-directory: ./extension
env:
GO111MODULE: on
EXT: "${{ matrix.os == 'windows-latest' && '.exe' || ''}}"

- name: Run unit tests
run: npm run unit-test
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/test-long.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,19 @@ jobs:
check-latest: true
cache: true

- name: Install dependencies
- name: Install NPM dependencies
run: npm ci
working-directory: ./extension

- name: Compile
run: npm run vscode:prepublish
working-directory: ./extension

- name: Install Go tools (Modules mode)
- name: Install tools dependencies
run: |
go version
go run ./tools/installtools/main.go
go install ./tools/installtools
installtools
working-directory: ./extension
env:
GO111MODULE: on
EXT: "${{ matrix.os == 'windows-latest' && '.exe' || ''}}"

- name: Run unit tests
run: npm run unit-test
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/test-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,11 @@ jobs:
run: npm run vscode:prepublish
working-directory: ./extension

- name: Install Go tools (Modules mode)
- name: Install tools dependencies
run: |
go version
go run ./tools/installtools/main.go
go install ./tools/installtools
installtools
working-directory: ./extension
env:
GO111MODULE: on
EXT: "${{ matrix.os == 'windows-latest' && '.exe' || ''}}"

- name: Run unit tests
run: npm run unit-test
Expand Down
4 changes: 1 addition & 3 deletions extension/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/golang/vscode-go/extension

go 1.21

toolchain go1.21.9
go 1.23.1

require (
github.com/golang/vscode-go v0.0.0-00010101000000-000000000000
Expand Down
17 changes: 6 additions & 11 deletions extension/tools/installtools/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func main() {
if ver < 21 {
exitf("unsupported go version: 1.%v", ver)
}
fmt.Printf("installing tools for go1.%d...\n", ver)

bin, err := goBin()
if err != nil {
Expand All @@ -80,7 +81,7 @@ func exitf(format string, args ...interface{}) {
// goVersion returns an integer N if go's version is 1.N.
func goVersion() (int, error) {
cmd := exec.Command("go", "list", "-e", "-f", `{{context.ReleaseTags}}`, "--", "unsafe")
cmd.Env = append(os.Environ(), "GO111MODULE=off")
cmd.Env = append(os.Environ(), "GO111MODULE=off", "GOTOOLCHAIN=local")
out, err := cmd.Output()
if err != nil {
return 0, fmt.Errorf("go list error: %v", err)
Expand All @@ -106,7 +107,9 @@ func goBin() (string, error) {
if gobin := os.Getenv("GOBIN"); gobin != "" {
return gobin, nil
}
out, err := exec.Command("go", "env", "GOPATH").Output()
cmd := exec.Command("go", "env", "GOPATH")
cmd.Env = append(os.Environ(), "GOTOOLCHAIN=local")
out, err := cmd.Output()
if err != nil {
return "", err
}
Expand All @@ -119,21 +122,13 @@ func goBin() (string, error) {

func installTools(binDir string, goMinorVersion int) error {
installCmd := "install"
if goMinorVersion < 16 {
installCmd = "get"
}

dir := ""
if installCmd == "get" { // run `go get` command from an empty directory.
dir = os.TempDir()
}
env := append(os.Environ(), "GO111MODULE=on")
env := append(os.Environ(), "GO111MODULE=on", "GOTOOLCHAIN=auto")
for _, tool := range tools {
ver := pickVersion(goMinorVersion, tool.versions, pickLatest(tool.path, tool.preferPreview))
path := tool.path + "@" + ver
cmd := exec.Command("go", installCmd, path)
cmd.Env = env
cmd.Dir = dir
fmt.Println("go", installCmd, path)
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("installing %v: %s\n%v", path, out, err)
Expand Down

0 comments on commit b4defa9

Please sign in to comment.