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/fix: fails to run on modules whose go directive value is in "1.n.m" format introduced in Go 1.21.0 #62584

Closed
alexbozhenko opened this issue Sep 12, 2023 · 10 comments
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@alexbozhenko
Copy link
Contributor

According to my understanding of these docs:
https://go.dev/doc/go1.21#tools
https://go.dev/doc/toolchain#version
https://go.dev/ref/mod#go-mod-file-go

before go 1.21 it was not allowed to specify the patch version in the go.mod.
so the code in fix cmd:

go/src/cmd/fix/main.go

Lines 78 to 79 in 905b58b

if before, after, found := strings.Cut(majorStr, "."); found {
majorStr, minorStr = before, after

does not handle string 1.21.0.
Existing code also won't work with go 1.21rc1

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

$ go version
go version go1.21.0 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
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/alex/.cache/go-build'
GOENV='/home/alex/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/alex/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/alex/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/alex/code/reproducer/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2636372290=/tmp/go-build -gno-record-gcc-switches'

What did you do?

$ mkdir reproducer
$ cd reproducer/
$ go mod init reproducer
$ cat go.mod
module reproducer

go 1.21.0

$ cat << EOF > main.go
//go:build OMIT
// +build OMIT

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}
EOF

$ go fix -tags OMIT .
invalid -go=go1.21.0
exit status 2

What did you expect to see?

Expected go fix to remove the deprecated build tag.

What did you see instead?

Error about invalid version.

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

heschi commented Sep 12, 2023

@JJJasonKing
Copy link

so should I update my go version to 1.21 or newer?

@peczenyj
Copy link

peczenyj commented Jan 5, 2024

ok so the workarond is to edit the go.mod after go mod init and remove the last .digit right?

@alexbozhenko
Copy link
Contributor Author

@heschi what do we need to do to merge linked PR? Thanks!

@bcmills bcmills added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label Jan 31, 2024
@bcmills
Copy link
Contributor

bcmills commented Jan 31, 2024

The aforementioned PR is https://go.dev/cl/527342. Not sure why it didn't cross-reference here. 🤔

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/527342 mentions this issue: cmd/fix: support go versions with patch release

@kolyshkin
Copy link
Contributor

@gopherbot Please backport to Go 1.22.

When I run go fix using Go 1.22.5, it complains:

invalid -go=go1.21.0
exit status 2

While go1.23rc2 fix works fine.

@gopherbot
Copy link
Contributor

gopherbot commented Aug 9, 2024

Backport issue(s) opened: #68824 (for 1.21), #68825 (for 1.22), #68826 (for 1.23).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@kolyshkin
Copy link
Contributor

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

Apparently I can't create backport PRs myself (see #68825 (comment))

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/603981 mentions this issue: [release-branch.go1.22] cmd/fix: support go versions with patch release

@dmitshur dmitshur changed the title cmd/fix: invalid -go=go1.21.0 cmd/fix: fails to run on modules whose go directive value is in "1.n.m" format introduced in Go 1.21.0 Aug 14, 2024
gopherbot pushed a commit that referenced this issue Aug 21, 2024
Support go version with patch release(e.g. 1.21.0)
and release candidates(e.g. 1.21rc1)
when parsing the go version in the fix command
by using new "go/version" package.

For #62584.
Fixes #68825.

Change-Id: I0ec16137c7a396c68039d374c770c4021fb54b4e
GitHub-Last-Rev: 76bced5
GitHub-Pull-Request: #62586
Reviewed-on: https://go-review.googlesource.com/c/go/+/527342
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Alex Bozhenko <alexbozhenko@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
(cherry picked from commit 7fd62ba)
Reviewed-on: https://go-review.googlesource.com/c/go/+/603981
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Bypass: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Kirill Kolyshkin <kolyshkin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
7 participants