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: go clean doesn’t remove the binary whose name is defined in go.mod #41656

Closed
hitzhangjie opened this issue Sep 27, 2020 · 6 comments
Closed
Labels
FrozenDueToAge GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@hitzhangjie
Copy link
Contributor

hitzhangjie commented Sep 27, 2020

Hi, go clean doesn't remove the built binary, the filename of binary is the same as the module directive in go.mod.

What version of Go are you using (go version)?

$ go version
go version go1.15 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (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)

What did you do?

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.

What did you expect to see?

I want to see a.b.c, a.b.c.exe, a.b.c.test and a.b.c.test.exe are cleaned, too.

What did you see instead?

The files, a.b.c, a.b.c.exe, a.b.c.test and a.b.c.test.exe are kept.

@andybons andybons changed the title go clean doens't remove the binary whose name is defined in go.mod cmd/go: go clean doesn’t remove the binary whose name is defined in go.mod Sep 29, 2020
@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 29, 2020
@andybons andybons added this to the Unplanned milestone Sep 29, 2020
@andybons
Copy link
Member

@bcmills @jayconrod @matloob

@jayconrod jayconrod added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 29, 2020
@jayconrod jayconrod modified the milestones: Unplanned, Backlog Sep 29, 2020
@bcmills
Copy link
Contributor

bcmills commented Sep 29, 2020

$ 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() {}

@bcmills bcmills added the GoCommand cmd/go label Sep 29, 2020
@nasjp
Copy link

nasjp commented Sep 30, 2020

I'll work on this. OK?

@gopherbot
Copy link

Change https://golang.org/cl/262677 mentions this issue: fix(cmd): when module enabled, go clean removes built binary

@hitzhangjie
Copy link
Contributor Author

@bcmills @andybons @nasjp

Hi, I create a PR #41999, please take a look :)

gopherbot pushed a commit that referenced this issue Oct 22, 2020
Now "go clean" can remove binary as expected, when module enabled and the module name isn't  "main" or the name of folder.

Fixes issue #41656

Change-Id: I54b9435ece045e03a12dc230efe84c8dd381a07c
GitHub-Last-Rev: f4ea2d8
GitHub-Pull-Request: #41999
Reviewed-on: https://go-review.googlesource.com/c/go/+/262677
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Trust: Bryan C. Mills <bcmills@google.com>
@hitzhangjie
Copy link
Contributor Author

This issue has been fixed now, I'll close it.

@golang golang locked and limited conversation to collaborators Oct 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants