Hi, go clean doesn't remove the built binary, the filename of binary is the same as the module directive in go.mod.
go version)?$ go version go version go1.15 darwin/amd64
Yes
go env)?go env Output
$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/zhangjie/Library/Caches/go-build"
GOENV="/Users/zhangjie/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/zhangjie/go/pkg/mod"
GONOPROXY="git.code.oa.com/"
GONOSUMDB="git.code.oa.com/"
GOOS="darwin"
GOPATH="/Users/zhangjie/go"
GOPRIVATE="git.code.oa.com/*"
GOPROXY="mirrors.tencent.com,direct"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/zhangjie/gotest/goclean/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0j/mvtnlhyj5j9cyqqq1b27bgg40000gn/T/go-build498757503=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.15 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.15
uname -v: Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64
ProductName: Mac OS X
ProductVersion: 10.15.7
BuildVersion: 19H2
lldb --version: lldb-1200.0.32.1
Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
file: goclean/main.go
file: goclean/go.mod, it defines the module a.b.c
After run cd goclean; go build, we get a binary goclean/a.b.c, then I run cd goclean; go clean -x, it says only the following list will be removed main main.exe goclean goclean.exe ...test ...test.exe. No a.b.c, a.b.c.exe, a.b.c.test, a.b.c.test.exe is listed.
I want to know if it's a bug, or it is designed like that.
I want to see a.b.c, a.b.c.exe, a.b.c.test and a.b.c.test.exe are cleaned, too.
The files, a.b.c, a.b.c.exe, a.b.c.test and a.b.c.test.exe are kept.
@bcmills @jayconrod @matloob
$ go version
go version devel +9a7a981a Tue Sep 29 08:21:48 2020 +0000 linux/amd64
$ (cd goclean; go build)
$ ls goclean/
a.b.c go.mod main.go
$ (cd goclean; go clean -x)
cd /tmp/tmp.WYzmKl7fkG/goclean
rm -f goclean goclean.exe goclean.test goclean.test.exe main main.exe
-- goclean/go.mod --
module a.b.c
go 1.16
-- goclean/main.go --
package main
func main() {}
I'll work on this. OK?
Change https://golang.org/cl/262677 mentions this issue: fix(cmd): when module enabled,go cleanremoves built binary
@bcmills @andybons @nasjp
Hi, I create a PR https://github.com/golang/go/pull/41999, please take a look :)
This issue has been fixed now, I'll close it.
Most helpful comment
I'll work on this. OK?