golang / go

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

x/exp/trace: gen.bash depends on GNU's sed, fails with BSD's #68403

Closed rhysh closed 1 month ago

rhysh commented 1 month ago

Go version

go version devel go1.23-06feff6279 Tue Jul 2 15:36:40 2024 -0700 darwin/arm64 [CL 596355 PS 1, parent is f12ac5be7045efcde39025c32cc01a20a305012c]

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/rhysh/Library/Caches/go-build'
GOENV='/Users/rhysh/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/rhysh/work/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/rhysh/work'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='devel go1.23-06feff6279 Tue Jul 2 15:36:40 2024 -0700'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/rhysh/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/rhysh/src/exp/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/pw/d_qmtcrd3vs0890gvmrq8qx80000gn/T/go-build1453705823=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

In the x/exp repo, on macOS,

$ (cd ./trace/ && ./gen.bash $(go env GOROOT))
$ git remote -v
origin  https://go.googlesource.com/exp (fetch)
origin  https://go.googlesource.com/exp (push)

I'm working with x/exp at CL 597177 PS 1, with a parent of golang/exp@7f521ea00fb803b5b0afbd67743292096b09056b

What did you see happen?

$ (cd ./trace/ && ./gen.bash $(go env GOROOT))
assuming Go checkout at /usr/local/go...
building file list ... done
deleting cmd/gotracevalidate/main.go
deleting cmd/gotracevalidate/
deleting cmd/gotraceraw/main.go
[ ... snip ... ]
traceviewer/static/webcomponents.min.js
version/
version/version.go

sent 4364398 bytes  received 2274 bytes  2911114.67 bytes/sec
total size is 4559026  speedup is 1.04
sed: 1: "./cmd/gotraceraw/main.go": invalid command code .

With git reporting 52 files modified and 3 deleted.

What did you expect to see?

I expected ./trace/gen.bash to copy the execution trace parser from GOROOT (which it did), to apply the code rewrites necessary to use it in its new location (did not) and without deleting the hand-maintained files in the ./trace directory (did not).

This relates to the meaning of sed's "-i" flag being different on GNU vs BSD.

I'll prepare a patch to make it work on both. That probably means using a non-empty backup suffix and subsequently deleting those copies. Does that sound like a good plan, @mknyszek @cagedmantis ?

gopherbot commented 1 month ago

Change https://go.dev/cl/598016 mentions this issue: trace: support BSD version of sed in gen.bash