|
| 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 | +cp -r $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 mktests.go because its a //go:build ignore file, so it would |
| 50 | +# complicate the logic below. This codebase isn't the source of truth |
| 51 | +# anyway. |
| 52 | +rm $DST/testdata/mktests.go |
| 53 | + |
| 54 | +# Make some packages internal. |
| 55 | +mv $DST/raw $DST/internal/raw |
| 56 | +mv $DST/event $DST/internal/event |
| 57 | +mv $DST/version $DST/internal/version |
| 58 | +mv $DST/testtrace $DST/internal/testtrace |
| 59 | + |
| 60 | +# Move the debug commands out of testdata. |
| 61 | +mv $DST/testdata/cmd $DST/cmd |
| 62 | + |
| 63 | +# Fix up import paths. |
| 64 | +find $DST -name '*.go' | xargs -- sed -i 's/internal\/trace\/v2/golang.org\/x\/exp\/trace/' |
| 65 | +find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/raw/golang.org\/x\/exp\/trace\/internal\/raw/' |
| 66 | +find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/event/golang.org\/x\/exp\/trace\/internal\/event/' |
| 67 | +find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/event\/go122/golang.org\/x\/exp\/trace\/internal\/event\/go122/' |
| 68 | +find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/version/golang.org\/x\/exp\/trace\/internal\/version/' |
| 69 | +find $DST -name '*.go' | xargs -- sed -i 's/golang.org\/x\/exp\/trace\/testtrace/golang.org\/x\/exp\/trace\/internal\/testtrace/' |
| 70 | +find $DST -name '*.go' | xargs -- sed -i 's/internal\/txtar/golang.org\/x\/tools\/txtar/' |
| 71 | + |
| 72 | +# Add build tag for Go 1.21 and generated code comment. |
| 73 | +find $DST -name '*.go' | xargs -- sed -i '/LICENSE file./a \ |
| 74 | +\ |
| 75 | +// Code generated by "gen.bash" from internal/trace/v2; DO NOT EDIT.\n\n//go:build go1.21' |
| 76 | + |
| 77 | +# Format the files. |
| 78 | +find $DST -name '*.go' | xargs -- gofmt -w -s |
0 commit comments