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: clean sub command should interop with generate a bit better #10059

Closed
mmlb opened this issue Mar 2, 2015 · 1 comment
Closed

cmd/go: clean sub command should interop with generate a bit better #10059

mmlb opened this issue Mar 2, 2015 · 1 comment

Comments

@mmlb
Copy link

mmlb commented Mar 2, 2015

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:

  1. 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.
  2. 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.
@robpike
Copy link
Contributor

robpike commented Mar 3, 2015

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.

@robpike robpike closed this as completed Mar 3, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants