Debian Codegraph @

trace/gen.bash

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/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 [scip-shell system . . `[`. "$#" -ne 1 ]; then
12 echoscip-shell system . . 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 [scip-shell system . . `[`. -d $1 ]; then
18 echoscip-shell system . . echo. "assuming Go checkout at $1..."
19
20 # Select the Go checkout.
21 GODIR=$1
22 else
23 echoscip-shell system . . echo. "using $1 as a commit hash..."
24
25 # Check out Go.
26 TMP=$(mktempscip-shell system . . mktemp. -d)
27 gitscip-shell system . . git. -C $TMP clone https://go.googlesource.com/go
28 gitscip-shell system . . git. -C $TMP/go checkout $1
29 GODIR=$TMP/go
30 fi
31
32 # Define src and dst.
33 SRC=$GODIR/src
34 DST=$(dirnamescip-shell system . . dirname. $0)
35
36 # Copy.
37 findscip-shell system . . find. "$DST" -mindepth 1 -not -name "$(basenamescip-shell system . . basename. $0)" -not -name "flightrecorder*.go" -exec rm -rf {} + # cleanup, except gen.bash and flight recorder
38 rsyncscip-shell system . . rsync. -av $SRC/internal/trace/ $DST
39 rsyncscip-shell system . . rsync. -av $SRC/internal/diff $DST/internal
40
41 # Remove the trace_test.go file and the testprogs it invokes.
42 # This really tests the tracer, it's not necessary to it bring along
43 # The trace tests are also problematic because they fail to run on
44 # Go versions before tip. The testprog directory is problematic because
45 # of //go:build ignore, so we'd have to complicate the logic below to
46 # support it.
47 rmscip-shell system . . rm. $DST/trace_test.go
48 rmscip-shell system . . rm. -r $DST/testdata/testprog
49
50 # Remove the tracev1 testdata to avoid checking in new binary files.
51 # Remove tracev1_test.go and internal/tracev1/parser_test.go because
52 # they fail without this data.
53 rmscip-shell system . . rm. -r $DST/internal/tracev1/testdata
54 rmscip-shell system . . rm. $DST/tracev1_test.go
55 rmscip-shell system . . rm. $DST/internal/tracev1/parser_test.go
56
57 # Remove files that are only pertinent to cmd/trace.
58 rmscip-shell system . . rm. $DST/export_test.go
59 rmscip-shell system . . rm. $DST/gc*.go
60 rmscip-shell system . . rm. $DST/mud*.go
61 rmscip-shell system . . rm. $DST/summary*.go
62 rmscip-shell system . . rm. -r $DST/traceviewer
63
64 # Remove mktests.go because its a //go:build ignore file, so it would
65 # complicate the logic below. This codebase isn't the source of truth
66 # anyway.
67 rmscip-shell system . . rm. $DST/testdata/mktests.go
68
69 # Make some packages internal.
70 mvscip-shell system . . mv. $DST/raw $DST/internal/raw
71 mvscip-shell system . . mv. $DST/tracev2 $DST/internal/tracev2
72 mvscip-shell system . . mv. $DST/version $DST/internal/version
73 mvscip-shell system . . mv. $DST/testtrace $DST/internal/testtrace
74
75 # Fix up import paths.
76 findscip-shell system . . find. $DST -name '*.go' | xargsscip-shell system . . xargs. -- sed -i'.tmp' -e 's internal/trace golang.org/x/exp/trace '
77 findscip-shell system . . find. $DST -name '*.go' | xargsscip-shell system . . xargs. -- sed -i'.tmp' -e 's golang.org/x/exp/trace/raw golang.org/x/exp/trace/internal/raw '
78 findscip-shell system . . find. $DST -name '*.go' | xargsscip-shell system . . xargs. -- sed -i'.tmp' -e 's golang.org/x/exp/trace/tracev2 golang.org/x/exp/trace/internal/tracev2 '
79 findscip-shell system . . find. $DST -name '*.go' | xargsscip-shell system . . xargs. -- sed -i'.tmp' -e 's golang.org/x/exp/trace/version golang.org/x/exp/trace/internal/version '
80 findscip-shell system . . find. $DST -name '*.go' | xargsscip-shell system . . xargs. -- sed -i'.tmp' -e 's golang.org/x/exp/trace/testtrace golang.org/x/exp/trace/internal/testtrace '
81 # Some tests rely on the following, relatively small internal packages
82 findscip-shell system . . find. $DST -name '*.go' | xargsscip-shell system . . xargs. -- sed -i'.tmp' -e 's internal/diff golang.org/x/exp/trace/internal/diff '
83 findscip-shell system . . find. $DST -name '*.go' | xargsscip-shell system . . xargs. -- sed -i'.tmp' -e 's internal/txtar golang.org/x/tools/txtar '
84 # Right now the only thing used from internal/testenv is testenv.Builder, which
85 # we can just inline
86 findscip-shell system . . find. $DST -name '*.go' | xargsscip-shell system . . xargs. -- sed -i'.tmp' -e '/"internal\/testenv"/dscip-shell filesystem . . `/"internal\/testenv"/d`.'
87 findscip-shell system . . find. $DST -name '*.go' | xargsscip-shell system . . xargs. -- sed -i'.tmp' -e 's testenv.Builder() os.Getenv("GO_BUILDER_NAME") g'
88 # Some of the tests rely on testing.(*T).ArtifactDir, which is a Go 1.26+
89 # feature. For now we use TempDir. Typically we should only see these tests
90 # fail if they were already broken in the main repository anyway.
91 findscip-shell system . . find. $DST -name '*.go' | xargsscip-shell system . . xargs. -- sed -i'.tmp' -e 's t.ArtifactDir t.TempDir '
92
93 # Add build tag for Go 1.23 and generated code comment.
94 findscip-shell system . . find. $DST -name '*.go' | xargsscip-shell system . . xargs. -- sed -i'.tmp' -e '/LICENSE file./a \
95 \
96 // Code generated by "gen.bash" from internal/trace; DO NOT EDIT.\
97 \
98 //go:build go1.23'
99
100 # Format the files.
101 findscip-shell system . . find. $DST -name '*.go' | xargsscip-shell system . . xargs. -- gofmt -w -s
102
103 # Delete sed backups
104 findscip-shell system . . find. $DST -name '*.go.tmp' -delete