-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
Description
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 seemsMAINFILE
is deleted due to it being an expected binary generated viago 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.