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/gofmt: go fmt not working when go:embed file is missing #43273

Closed
mewmew opened this issue Dec 19, 2020 · 8 comments
Closed

cmd/gofmt: go fmt not working when go:embed file is missing #43273

mewmew opened this issue Dec 19, 2020 · 8 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@mewmew
Copy link
Contributor

mewmew commented Dec 19, 2020

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

$ go version
go version devel +2ff33f5e44 Thu Dec 17 16:03:19 2020 +0000 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/u/.cache/go-build"
GOENV="/home/u/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/u/goget/pkg/mod"
GOOS="linux"
GOPATH="/home/u/goget"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/u/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/u/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel +2ff33f5e44 Thu Dec 17 16:03:19 2020 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3114393024=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Repository to reproduce issue: https://github.com/mewspring/embed-test

I tried to use go fmt to format main.go.

The main.go source file contains a go:embed directive reading the text file version.txt. This text file is generated by the gen_version.sh script.

Trying to run go fmt prior to generating the version.txt file fails, with the error message pattern version.txt: no matching files found.

$ git clone https://github.com/mewspring/embed-test
$ cd embed-test
$ go fmt
# Outputs: pattern version.txt: no matching files found

Generating version.txt using ./gen_version.sh and then running go fmt succeeds.

$ git clone https://github.com/mewspring/embed-test
$ cd embed-test
$ ./gen_version.sh
$ go fmt
# Outputs: main.go (as it was successfully formatted)

What did you expect to see?

Go fmt successfully formatting the source code (even if files or directives listed in go:embed directive are missing).

The contents of go:embed directives should only matter for the compilation step, not source code formatting.

Note: a warning may still be issued by go fmt if preferable, but this should not interrupt the formatting of the source file.

What did you see instead?

Trying to run go fmt prior to generating the version.txt file fails, with the error message pattern version.txt: no matching files found.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 19, 2020
@dmitshur dmitshur added this to the Go1.16 milestone Dec 19, 2020
@dmitshur
Copy link
Contributor

CC @rsc.

@bcmills
Copy link
Contributor

bcmills commented Dec 21, 2020

CC @jayconrod @matloob

@bcmills
Copy link
Contributor

bcmills commented Dec 21, 2020

This may be (fairly closely) related to #39442, but this particular issue is specific to the go:embed feature that is new in 1.16, so marking as release-blocker for 1.16.

@gopherbot
Copy link

Change https://golang.org/cl/280452 mentions this issue: cmd/go: remove check of existence of embed files

@iwdgo
Copy link
Contributor

iwdgo commented Dec 27, 2020

There does not seem to be any reason to expect embedded files to be present when go fmt is used.
The error message would be emitted during go build.

$ goissue fmt
main.go

$ goissue build
# github.com/mewspring/embed-test
.\main.go:11:5: go:embed cannot find file

$ goissue generate

$ goissue build

$ ls
embed-test.exe*  gen_version.sh*  go.mod  main.go  version.txt  version_date.txt  version_tag_and_commit.txt

@ALTree ALTree changed the title embed: go fmt not working when go:embed file is missing cmd/gofmt: go fmt not working when go:embed file is missing Dec 27, 2020
@cagedmantis
Copy link
Contributor

Friendly ping as this is a release blocker and the release is approaching.

@bcmills
Copy link
Contributor

bcmills commented Jan 15, 2021

@cagedmantis, this was blocked on #43632. (There is current activity on https://golang.org/cl/280452.)

@cagedmantis
Copy link
Contributor

Thanks for the update!

@golang golang locked and limited conversation to collaborators Jan 21, 2022
@rsc rsc unassigned iwdgo Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

7 participants
@cagedmantis @mewmew @dmitshur @bcmills @gopherbot @iwdgo and others