golang.org/x/exp@v0.0.0-20240506185415-9bf2ced13842/trace/gen.bash (about) 1 #!/usr/bin/env bash 2 # Copyright 2023 The Go Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style 4 # license that can be found in the LICENSE file. 5 6 # This script copies this directory to golang.org/x/exp/trace. 7 # Just point it at a Go commit or a local Go checkout. 8 9 set -e 10 11 if [ "$#" -ne 1 ]; then 12 echo 'gen.bash expects one argument: a go.googlesource.com/go commit hash to generate the package from or a path to a Go checkout' 13 exit 1 14 fi 15 16 # Determine the source. 17 if [ -d $1 ]; then 18 echo "assuming Go checkout at $1..." 19 20 # Select the Go checkout. 21 GODIR=$1 22 else 23 echo "using $1 as a commit hash..." 24 25 # Check out Go. 26 TMP=$(mktemp -d) 27 git -C $TMP clone https://go.googlesource.com/go 28 git -C $TMP/go checkout $1 29 GODIR=$TMP/go 30 fi 31 32 # Define src and dst. 33 SRC=$GODIR/src/internal/trace/v2 34 DST=$(dirname $0) 35 36 # Copy. 37 rsync -av --delete $SRC/ $DST 38 rm $DST/mkexp.bash 39 40 # Remove the trace_test.go file and the testprogs it invokes. 41 # This really tests the tracer, it's not necessary to it bring along 42 # The trace tests are also problematic because they fail to run on 43 # Go versions before tip. The testprog directory is problematic because 44 # of //go:build ignore, so we'd have to complicate the logic below to 45 # support it. 46 rm $DST/trace_test.go 47 rm -r $DST/testdata/testprog 48 49 # Remove the oldtrace testdata to avoid checking in new binary files. 50 # Remove oldtrace_test.go and internal/oldtrace/parser_test.go because 51 # they fail without this data. 52 rm -r $DST/internal/oldtrace/testdata 53 rm $DST/oldtrace_test.go 54 rm $DST/internal/oldtrace/parser_test.go 55 56 # Remove mktests.go because its a //go:build ignore file, so it would 57 # complicate the logic below. This codebase isn't the source of truth 58 # anyway. 59 rm $DST/testdata/mktests.go 60 61 # Make some packages internal. 62 mv $DST/raw $DST/internal/raw 63 mv $DST/event $DST/internal/event 64 mv $DST/version $DST/internal/version 65 mv $DST/testtrace $DST/internal/testtrace 66 67 # Move the debug commands out of testdata. 68 mv $DST/testdata/cmd $DST/cmd 69 70 # Fix up import paths. 71 find $DST -name '*.go' | xargs -- sed -i 's/internal\/trace\/v2/golang.org\/x\/exp\/trace/' 72 find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/raw/golang.org\/x\/exp\/trace\/internal\/raw/' 73 find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/event/golang.org\/x\/exp\/trace\/internal\/event/' 74 find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/event\/go122/golang.org\/x\/exp\/trace\/internal\/event\/go122/' 75 find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/version/golang.org\/x\/exp\/trace\/internal\/version/' 76 find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/testtrace/golang.org\/x\/exp\/trace\/internal\/testtrace/' 77 find $DST -name '*.go' | xargs -- sed -i 's/internal\/txtar/golang.org\/x\/tools\/txtar/' 78 79 # Add build tag for Go 1.21 and generated code comment. 80 find $DST -name '*.go' | xargs -- sed -i '/LICENSE file./a \ 81 \ 82 // Code generated by "gen.bash" from internal/trace/v2; DO NOT EDIT.\n\n//go:build go1.21' 83 84 # Format the files. 85 find $DST -name '*.go' | xargs -- gofmt -w -s 86 87 # Restore known files. 88 git checkout gen.bash flightrecorder.go flightrecorder_test.go