]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: record full source path to input .go files
authorRuss Cox <rsc@golang.org>
Mon, 9 Sep 2013 17:04:14 +0000 (13:04 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 9 Sep 2013 17:04:14 +0000 (13:04 -0400)
Fixes #5122.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13395046

src/cmd/cgo/ast.go
src/cmd/go/test.bash

index dbae3b7b16d5de2b8531dae6a0653f76f02586c8..37c1c8f65c120f62736671327760c0bcff654c8c 100644 (file)
@@ -13,6 +13,7 @@ import (
        "go/scanner"
        "go/token"
        "os"
+       "path/filepath"
        "strings"
 )
 
@@ -44,6 +45,13 @@ func sourceLine(n ast.Node) int {
 // a list of exported functions, and the actual AST, to be rewritten and
 // printed.
 func (f *File) ReadGo(name string) {
+       // Create absolute path for file, so that it will be used in error
+       // messages and recorded in debug line number information.
+       // This matches the rest of the toolchain. See golang.org/issue/5122.
+       if aname, err := filepath.Abs(name); err == nil {
+               name = aname
+       }
+
        // Two different parses: once with comments, once without.
        // The printer is not good enough at printing comments in the
        // right place when we start editing the AST behind its back,
index 2a7c1927ed578845184a4759772151cfffc4d089..847a3e10a1c0d9d6816320b4ec27aca751b315ee 100755 (executable)
@@ -463,6 +463,26 @@ import "C"
 rm -rf $d
 unset GOPATH
 
+TEST cgo shows full path names
+d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
+export GOPATH=$d
+mkdir -p $d/src/x/y/dirname
+echo '
+package foo
+import "C"
+func f() {
+' >$d/src/x/y/dirname/foo.go
+if ./testgo build x/y/dirname >$d/err 2>&1; then
+       echo build succeeded unexpectedly.
+       ok=false
+elif ! grep x/y/dirname $d/err >/dev/null; then
+       echo error did not use full path.
+       cat $d/err
+       ok=false
+fi
+rm -rf $d
+unset GOPATH
+
 # clean up
 if $started; then stop; fi
 rm -rf testdata/bin testdata/bin1