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: go vet does not support -overlay #44957

Open
eandre opened this issue Mar 12, 2021 · 3 comments
Open

cmd/go: go vet does not support -overlay #44957

eandre opened this issue Mar 12, 2021 · 3 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@eandre
Copy link

eandre commented Mar 12, 2021

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

$ go version
go version go1.16 darwin/arm64

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="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/eandre/Library/Caches/go-build"
GOENV="/Users/eandre/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/eandre/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/eandre"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.16/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.16/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hc/w9bwjfwd69dd6_6thw6xqmkw0000gn/T/go-build2213810525=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Consider the following txtar:

-- go.mod --
module test.pkg
-- foo/foo_test.go --
package foo

import "testing"

func TestFoo(t *testing.T) { }
-- tmp/bar.go --
package foo
-- foo/overlay.json --
{"Replace": {"bar.go": "../tmp/bar.go"}}

I ran cd foo && go test -overlay=overlay.json . and expected the tests to pass.

What did you expect to see?

$ go test -overlay=overlay.json .
ok  	test.pkg/foo 0.123s

What did you see instead?

$ go test -overlay=overlay.json .
# test.pkg/foo
vet: open bar.go: no such file or directory
FAIL	test.pkg/foo [build failed]
FAIL
exit status 2

The issue is because the overlay is added to GoTestFiles but go vet does not support (or receive information about) overlays, so it tries to read the overlaid file directly from the filesystem where it does not exist.

@jayconrod jayconrod added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 12, 2021
@jayconrod jayconrod added this to the Backlog milestone Mar 12, 2021
@jayconrod
Copy link
Contributor

cc @matloob @bcmills

@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 12, 2021
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 12, 2021
@vithalklrk
Copy link

Hi, alldocs.go says this:
// -overlay file // read a JSON config file that provides an overlay for build operations. // The file is a JSON struct with a single field, named 'Replace', that // maps each disk file path (a string) to its backing file path, so that // a build will run as if the disk file path exists with the contents // given by the backing file paths, or as if the disk file path does not // exist if its backing file path is empty. Support for the -overlay flag // has some limitations: importantly, cgo files included from outside the // include path must be in the same directory as the Go package they are // included from, and **overlays will not appear when binaries and tests are // run through go run and go test** respectively.
Is the above description saying that this is not an issue? I am new, so I could be getting it wrong

@dolmen
Copy link
Contributor

dolmen commented Mar 31, 2024

Also: go vet accepts a -overlay <file> flag, but seems to ignore it:

$ go vet -overlay=overlay.json .

dolmen added a commit to dolmen-go/mejedi.golang-overlay-experiment.fork that referenced this issue Mar 31, 2024
Workaround limitation of embed regarding support of -overlay:
- add the overlay of the embeded file in the package tree (this is a
  limitation of embed patterns): cmd/main/.overlay-greeting
- inject a .go file via the overlay that overrides the content of the
  original embeded file with the embeded replacement file at runtime
  (both embedded files are in the final binary).

Unfortunately "go vet" doesn't work with overlays, so "make test" fails.
golang/go#44957
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) 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

7 participants