From 8a7402abbf56ed11a2540c1d8beb569bd29e22d1 Mon Sep 17 00:00:00 2001 From: Rhys Hiltner Date: Thu, 11 Jul 2024 14:23:57 -0700 Subject: [PATCH] trace: support BSD version of sed in gen.bash 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 Reviewed-by: Carlos Amedee LUCI-TryBot-Result: Go LUCI Auto-Submit: Rhys Hiltner Reviewed-by: Mauri de Souza Meneguzzo --- trace/gen.bash | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/trace/gen.bash b/trace/gen.bash index 8d6a7f6ba..a34078a39 100755 --- a/trace/gen.bash +++ b/trace/gen.bash @@ -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