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

Open
mewmew opened this issue Dec 19, 2020 · 5 comments
Open

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

mewmew opened this issue Dec 19, 2020 · 5 comments

Comments

@mewmew
Copy link
Contributor

@mewmew 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 this to the Go1.16 milestone Dec 19, 2020
@dmitshur
Copy link
Member

@dmitshur dmitshur commented Dec 19, 2020

CC @rsc.

@bcmills
Copy link
Member

@bcmills bcmills commented Dec 21, 2020

@bcmills
Copy link
Member

@bcmills 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

@gopherbot gopherbot commented Dec 27, 2020

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

@iWdGo
Copy link
Contributor

@iWdGo 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.