trace: update gen.bash for oldtrace and make it work seamlessly

Currently gen.bash doesn't work out-of-the-box because it doesn't
exactly replace contents in the trace directory in some cases. It also
may end up mutating the flight recorder files, which isn't great.

This change adds a special case for the flight recorder files, adds
support for oldtrace (which will be imported shortly), and also switches
to using rsync, which is more robust than cp for the initial copy (and
should hopefully capture file deletions correctly as well).

Change-Id: I3a808387a25c787a1edb70fcff1c95fb5649baeb
Reviewed-on: https://go-review.googlesource.com/c/exp/+/571615
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
diff --git a/trace/gen.bash b/trace/gen.bash
index 6dcaafd..fc5445d 100755
--- a/trace/gen.bash
+++ b/trace/gen.bash
@@ -34,7 +34,7 @@
 DST=$(dirname $0)
 
 # Copy.
-cp -r $SRC/* $DST
+rsync -av --delete $SRC/ $DST
 rm $DST/mkexp.bash
 
 # Remove the trace_test.go file and the testprogs it invokes.
@@ -46,6 +46,13 @@
 rm $DST/trace_test.go
 rm -r $DST/testdata/testprog
 
+# Remove the oldtrace testdata to avoid checking in new binary files.
+# Remove oldtrace_test.go and internal/oldtrace/parser_test.go because
+# they fail without this data.
+rm -r $DST/internal/oldtrace/testdata
+rm $DST/oldtrace_test.go
+rm $DST/internal/oldtrace/parser_test.go
+
 # Remove mktests.go because its a //go:build ignore file, so it would
 # complicate the logic below. This codebase isn't the source of truth
 # anyway.
@@ -76,3 +83,6 @@
 
 # Format the files.
 find $DST -name '*.go' | xargs -- gofmt -w -s
+
+# Restore known files.
+git checkout gen.bash flightrecorder.go flightrecorder_test.go