Skip to content

Commit

Permalink
trace: support BSD version of sed in gen.bash
Browse files Browse the repository at this point in the history
The GNU version of sed (common on Linux) will modify files in place when
it sees the -i flag with no argument at all, as in [sed -i -e '...'].
The BSD version of sed (common on macOS) will modify files in place when
it's given an explicit zero-length argument, as in [sed -i '' -e '...'].

But they agree on at least one way of specifying a non-zero-length
backup suffix, [sed -i '.tmp' -e '...']. Use that and then delete the
backups.

In addition, change the expressions we pass to sed to make them a bit
more explicit and to require less escaping.

Fixes golang/go#68403

Change-Id: Icfc3863f4abe26bc77d9c0bc3b778067db6387de
Reviewed-on: https://go-review.googlesource.com/c/exp/+/598016
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Rhys Hiltner <rhys.hiltner@gmail.com>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
  • Loading branch information
rhysh authored and gopherbot committed Jul 19, 2024
1 parent e3f2596 commit 8a7402a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions trace/gen.bash
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,26 @@ mv $DST/testtrace $DST/internal/testtrace
mv $DST/testdata/cmd $DST/cmd

# Fix up import paths.
find $DST -name '*.go' | xargs -- sed -i 's/internal\/trace/golang.org\/x\/exp\/trace/'
find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/raw/golang.org\/x\/exp\/trace\/internal\/raw/'
find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/event/golang.org\/x\/exp\/trace\/internal\/event/'
find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/event\/go122/golang.org\/x\/exp\/trace\/internal\/event\/go122/'
find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/version/golang.org\/x\/exp\/trace\/internal\/version/'
find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/testtrace/golang.org\/x\/exp\/trace\/internal\/testtrace/'
find $DST -name '*.go' | xargs -- sed -i 's/internal\/txtar/golang.org\/x\/tools\/txtar/'
find $DST -name '*.go' | xargs -- sed -i'.tmp' -e 's internal/trace golang.org/x/exp/trace '
find $DST -name '*.go' | xargs -- sed -i'.tmp' -e 's golang.org/x/exp/trace/raw golang.org/x/exp/trace/internal/raw '
find $DST -name '*.go' | xargs -- sed -i'.tmp' -e 's golang.org/x/exp/trace/event golang.org/x/exp/trace/internal/event '
find $DST -name '*.go' | xargs -- sed -i'.tmp' -e 's golang.org/x/exp/trace/event/go122 golang.org/x/exp/trace/internal/event/go122 '
find $DST -name '*.go' | xargs -- sed -i'.tmp' -e 's golang.org/x/exp/trace/version golang.org/x/exp/trace/internal/version '
find $DST -name '*.go' | xargs -- sed -i'.tmp' -e 's golang.org/x/exp/trace/testtrace golang.org/x/exp/trace/internal/testtrace '
find $DST -name '*.go' | xargs -- sed -i'.tmp' -e 's internal/txtar golang.org/x/tools/txtar '

# Add build tag for Go 1.21 and generated code comment.
find $DST -name '*.go' | xargs -- sed -i '/LICENSE file./a \
find $DST -name '*.go' | xargs -- sed -i'.tmp' -e '/LICENSE file./a \
\
// Code generated by "gen.bash" from internal/trace; DO NOT EDIT.\n\n//go:build go1.21'
// Code generated by "gen.bash" from internal/trace; DO NOT EDIT.\
\
//go:build go1.21'

# Format the files.
find $DST -name '*.go' | xargs -- gofmt -w -s

# Delete sed backups
find $DST -name '*.go.tmp' -delete

# Restore known files.
git checkout gen.bash flightrecorder.go flightrecorder_test.go

0 comments on commit 8a7402a

Please sign in to comment.