You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We currently have a file that is generated via go generate to which the .go suffix is added to the filename. When packaging we run go clean which proceeds to delete the source file, this was unexpected. Here is a minimal example:
~/t
❯ tail -n +1 main.go print.dummy
==> main.go <==
package main
//go:generate cp print.dummy print.dummy.go
func main() {
printIt("hi")
}
==> print.dummy <==
package main
import "fmt"
func printIt(s string) {
fmt.Println(s)
}
~/t
❯ go generate && ls
main.go print.dummy print.dummy.go
~/t
❯ go clean -x
cd /home/mmlb/t
rm -f t t.exe t.test t.test.exe main main.exe print.dummy print.dummy.exe
I expect that the $source.file -> $source.file.go pattern is probably common enough that go clean should special case it. I was very surprised to see go clean -x purposefully deleting the file even though the match is documented/specified.
A couple of options are possible to handle this case:
Do not delete MAINFILE if it is not executable.
It seems MAINFILE is deleted due to it being an expected binary generated via go build *.go or similar.
Special case a file that shares the root file name of a .go source file as long as the root contains a . in the name.
The text was updated successfully, but these errors were encountered:
Working as intended, and has nothing to do with go generate.
Go clean removes executables, which include files named foo when there is a foo.go source file. Here, you have a file print.dummy.go and a file print.dummy, which go clean is documented to remove.
Rename print.dummy in your example and the problem will go away.
We currently have a file that is generated via
go generate
to which the.go
suffix is added to the filename. When packaging we rungo clean
which proceeds to delete the source file, this was unexpected. Here is a minimal example:I expect that the
$source.file -> $source.file.go
pattern is probably common enough thatgo clean
should special case it. I was very surprised to seego clean -x
purposefully deleting the file even though the match is documented/specified.A couple of options are possible to handle this case:
MAINFILE
if it is not executable.It seems
MAINFILE
is deleted due to it being an expected binary generated viago build *.go
or similar..go
source file as long as the root contains a.
in the name.The text was updated successfully, but these errors were encountered: