blob: fc5445d9e3b8e7f4ea2f6dd2f30b7145950a5e18 [file] [log] [blame]
#!/usr/bin/env bash
# Copyright 2023 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# This script copies this directory to
# Just point it at a Go commit or a local Go checkout.
set -e
if [ "$#" -ne 1 ]; then
echo 'gen.bash expects one argument: a commit hash to generate the package from or a path to a Go checkout'
exit 1
# Determine the source.
if [ -d $1 ]; then
echo "assuming Go checkout at $1..."
# Select the Go checkout.
echo "using $1 as a commit hash..."
# Check out Go.
TMP=$(mktemp -d)
git -C $TMP clone
git -C $TMP/go checkout $1
# Define src and dst.
DST=$(dirname $0)
# Copy.
rsync -av --delete $SRC/ $DST
rm $DST/mkexp.bash
# Remove the trace_test.go file and the testprogs it invokes.
# This really tests the tracer, it's not necessary to it bring along
# The trace tests are also problematic because they fail to run on
# Go versions before tip. The testprog directory is problematic because
# of //go:build ignore, so we'd have to complicate the logic below to
# support it.
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.
rm $DST/testdata/mktests.go
# Make some packages internal.
mv $DST/raw $DST/internal/raw
mv $DST/event $DST/internal/event
mv $DST/version $DST/internal/version
mv $DST/testtrace $DST/internal/testtrace
# Move the debug commands out of testdata.
mv $DST/testdata/cmd $DST/cmd
# Fix up import paths.
find $DST -name '*.go' | xargs -- sed -i 's/internal\/trace\/v2/\/x\/exp\/trace/'
find $DST -name '*.go' | xargs -- sed -i 's/\/x\/exp\/trace\/raw/\/x\/exp\/trace\/internal\/raw/'
find $DST -name '*.go' | xargs -- sed -i 's/\/x\/exp\/trace\/event/\/x\/exp\/trace\/internal\/event/'
find $DST -name '*.go' | xargs -- sed -i 's/\/x\/exp\/trace\/event\/go122/\/x\/exp\/trace\/internal\/event\/go122/'
find $DST -name '*.go' | xargs -- sed -i 's/\/x\/exp\/trace\/version/\/x\/exp\/trace\/internal\/version/'
find $DST -name '*.go' | xargs -- sed -i 's/\/x\/exp\/trace\/testtrace/\/x\/exp\/trace\/internal\/testtrace/'
find $DST -name '*.go' | xargs -- sed -i 's/internal\/txtar/\/x\/tools\/txtar/'
# Add build tag for Go 1.21 and generated code comment.
find $DST -name '*.go' | xargs -- sed -i '/LICENSE file./a \
// Code generated by "gen.bash" from internal/trace/v2; DO NOT EDIT.\n\n//go:build go1.21'
# Format the files.
find $DST -name '*.go' | xargs -- gofmt -w -s
# Restore known files.
git checkout gen.bash flightrecorder.go flightrecorder_test.go