diff options
| author | Tobias Klauser <tklauser@distanz.ch> | 2022-04-01 09:41:57 +0200 |
|---|---|---|
| committer | Tobias Klauser <tobias.klauser@gmail.com> | 2022-04-03 07:18:10 +0000 |
| commit | 73a81d84b644da13bb11ce2e63d7f61041f7ebac (patch) | |
| tree | 072e2baca4b5026af69c54ed911d85caed34283c /src/cmd/cgo | |
| parent | 8e50298f12c9cb8dc8093c00059e46a302977b83 (diff) | |
| download | go-73a81d84b644da13bb11ce2e63d7f61041f7ebac.tar.xz | |
cmd/cgo: retain original file paths in godefs generated comment
Don't rewrite relative file paths to absolute file paths in the
godefs generated code comment.
Fixes #52063
Change-Id: Ie9c5bd021b8f3954e827838930861622c7aa90b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/396936
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/cgo')
| -rw-r--r-- | src/cmd/cgo/godefs.go | 4 | ||||
| -rw-r--r-- | src/cmd/cgo/main.go | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/src/cmd/cgo/godefs.go b/src/cmd/cgo/godefs.go index c0d59aee01..3a27b31bfb 100644 --- a/src/cmd/cgo/godefs.go +++ b/src/cmd/cgo/godefs.go @@ -16,11 +16,11 @@ import ( ) // godefs returns the output for -godefs mode. -func (p *Package) godefs(f *File) string { +func (p *Package) godefs(f *File, args []string) string { var buf bytes.Buffer fmt.Fprintf(&buf, "// Code generated by cmd/cgo -godefs; DO NOT EDIT.\n") - fmt.Fprintf(&buf, "// %s %s\n", filepath.Base(os.Args[0]), strings.Join(os.Args[1:], " ")) + fmt.Fprintf(&buf, "// %s %s\n", filepath.Base(args[0]), strings.Join(args[1:], " ")) fmt.Fprintf(&buf, "\n") override := make(map[string]string) diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go index 14642b7576..364d8b81fb 100644 --- a/src/cmd/cgo/main.go +++ b/src/cmd/cgo/main.go @@ -291,6 +291,10 @@ func main() { usage() } + // Save original command line arguments for the godefs generated comment. Relative file + // paths in os.Args will be rewritten to absolute file paths in the loop below. + osArgs := make([]string, len(os.Args)) + copy(osArgs, os.Args[:]) goFiles := args[i:] for _, arg := range args[:i] { @@ -390,7 +394,7 @@ func main() { p.PackagePath = f.Package p.Record(f) if *godefs { - os.Stdout.WriteString(p.godefs(f)) + os.Stdout.WriteString(p.godefs(f, osArgs)) } else { p.writeOutput(f, input) } |
