aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2022-04-01 09:41:57 +0200
committerTobias Klauser <tobias.klauser@gmail.com>2022-04-03 07:18:10 +0000
commit73a81d84b644da13bb11ce2e63d7f61041f7ebac (patch)
tree072e2baca4b5026af69c54ed911d85caed34283c /misc
parent8e50298f12c9cb8dc8093c00059e46a302977b83 (diff)
downloadgo-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 'misc')
-rw-r--r--misc/cgo/testgodefs/testgodefs_test.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/misc/cgo/testgodefs/testgodefs_test.go b/misc/cgo/testgodefs/testgodefs_test.go
index 7628ffc595..d03769ea87 100644
--- a/misc/cgo/testgodefs/testgodefs_test.go
+++ b/misc/cgo/testgodefs/testgodefs_test.go
@@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "runtime"
"strings"
"testing"
)
@@ -58,9 +59,32 @@ func TestGoDefs(t *testing.T) {
t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, cmd.Stderr)
}
- if err := os.WriteFile(filepath.Join(dir, fp+"_defs.go"), out, 0644); err != nil {
+ fn := fp + "_defs.go"
+ if err := os.WriteFile(filepath.Join(dir, fn), out, 0644); err != nil {
t.Fatal(err)
}
+
+ // Verify that command line arguments are not rewritten in the generated comment,
+ // see go.dev/issue/52063
+ hasGeneratedByComment := false
+ for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
+ cgoExe := "cgo"
+ if runtime.GOOS == "windows" {
+ cgoExe = "cgo.exe"
+ }
+ if !strings.HasPrefix(line, "// "+cgoExe+" -godefs") {
+ continue
+ }
+ if want := "// " + cgoExe + " " + strings.Join(cmd.Args[3:], " "); line != want {
+ t.Errorf("%s: got generated comment %q, want %q", fn, line, want)
+ }
+ hasGeneratedByComment = true
+ break
+ }
+
+ if !hasGeneratedByComment {
+ t.Errorf("%s: comment with generating cgo -godefs command not found", fn)
+ }
}
main, err := os.ReadFile(filepath.Join("testdata", "main.go"))