golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.82k stars 17.65k forks source link

cmd/go: clean -x removes *.so but doesn't list such files in output #33573

Open zephyrtronium opened 5 years ago

zephyrtronium commented 5 years ago

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

$ go version
go version go1.12.7 linux/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
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/zephyrtronium/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/zephyrtronium/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build755048247=/tmp/go-build -gno-record-gcc-switches"

What did you do?

~/mygo/plugintest$ printf 'package main\n\nvar String = "Hello, world!"\n' >plugin.go
~/mygo/plugintest$ go build -buildmode=plugin
~/mygo/plugintest$ go clean -x

What did you expect to see?

rm -f including plugintest.so, or plugintest.so still present in the directory.

What did you see instead?

cd /home/zephyrtronium/go/src/github.com/zephyrtronium/plugintest
rm -f plugintest plugintest.exe plugintest.test plugintest.test.exe plugin plugin.exe

plugintest.so was removed by go clean, but not listed in its output. It seems that any files removed via https://github.com/golang/go/blob/master/src/cmd/go/internal/clean/clean.go#L323 aren't printed, which includes *.so (which the documentation says come from SWIG).

zephyrtronium commented 5 years ago

Reading through clean.go, it looks like there are three reasonable options:

  1. Add files matching cleanFile and cleanExt to allRemove, which currently only contains possible executable file outputs. This is an easy fix, and I'm currently trying it locally.
  2. Remove .so from cleanExt and instead remove those files in the way that *.exe is removed. This seems appropriate because a shared object in the package directory is probably from any of the various shared build modes rather than from SWIG in the modern era. I'm still uncomfortable with any files being removed without being printed in -n and -x.
  3. Follow up on // TODO: Remove once Makefiles are forgotten. It's been over seven years since the go command was released, and almost five years since go generate. It's impossible to be certain that no one is using Makefiles, but at the very least, the go command isn't included in (the text of) the Go 1 compatibility promise.
gopherbot commented 3 years ago

Change https://golang.org/cl/339789 mentions this issue: cmd/go: go clean should list all deleted files