uber-go/mock

Flag `-write_generate_directive` produces wrong paths in the directive

maratori opened this issue · 0 comments

Actual behavior

Flag -write_generate_directive adds the go:generate directive, ignoring the future working directory. That leads to a failure of go generate.

Expected behavior

go:generate directive should be changed to respect that the current working directory will be different from the original execution.

To Reproduce

echo 'package pkg' > file.go
mockgen -write_generate_directive -source file.go -destination mocks/mock.go
grep 'go:generate' mocks/*
//go:generate mockgen -write_generate_directive -source file.go -destination mocks/mock.go
go generate ./...
2023/12/31 15:40:41 Loading input failed: failed parsing source file file.go: open file.go: no such file or directory
mocks/mock.go:12: running "mockgen": exit status 1

To fix

sed -i '' -e 's#-source file.go -destination mocks/mock.go#-source ../file.go -destination mock.go#' mocks/*
grep 'go:generate' mocks/*
//go:generate mockgen -write_generate_directive -source ../file.go -destination mock.go
go generate ./...