Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cmd/go/alldocs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/cmd/go/internal/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ var (
BuildCover bool // -cover flag
BuildCoverMode string // -covermode flag
BuildCoverPkg []string // -coverpkg flag
BuildFullpath bool // -fullpath flag
BuildJSON bool // -json flag
BuildN bool // -n flag
BuildO string // -o flag
Expand Down
8 changes: 6 additions & 2 deletions src/cmd/go/internal/load/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ func (p *Package) setLoadPackageDataError(err error, path string, stk *ImportSta
isScanErr = true // For stack push/pop below.

scanPos := scanErr[0].Pos
scanPos.Filename = base.ShortPath(scanPos.Filename)
if !cfg.BuildFullpath {
scanPos.Filename = base.ShortPath(scanPos.Filename)
}
pos = scanPos.String()
err = errors.New(scanErr[0].Msg)
}
Expand Down Expand Up @@ -507,7 +509,9 @@ func (p *PackageError) setPos(posList []token.Position) {
return
}
pos := posList[0]
pos.Filename = base.ShortPath(pos.Filename)
if !cfg.BuildFullpath {
pos.Filename = base.ShortPath(pos.Filename)
}
p.Pos = pos.String()
}

Expand Down
1 change: 0 additions & 1 deletion src/cmd/go/internal/test/testflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func init() {
cf.StringVar(&testCPUProfile, "cpuprofile", "", "")
cf.BoolVar(&testFailFast, "failfast", false, "")
cf.StringVar(&testFuzz, "fuzz", "", "")
cf.Bool("fullpath", false, "")
cf.StringVar(&testList, "list", "", "")
cf.StringVar(&testMemProfile, "memprofile", "", "")
cf.String("memprofilerate", "", "")
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/go/internal/work/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ and test commands:
arguments to pass on each gccgo compiler/linker invocation.
-gcflags '[pattern=]arg list'
arguments to pass on each go tool compile invocation.
-fullpath
show full file names in error messages.
-installsuffix suffix
a suffix to use in the name of the package installation directory,
in order to keep output separate from default builds.
Expand Down Expand Up @@ -323,6 +325,7 @@ func AddBuildFlags(cmd *base.Command, mask BuildFlagMask) {
cmd.Flag.Var(buildCompiler{}, "compiler", "")
cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", "default", "")
cmd.Flag.Var((*buildvcsFlag)(&cfg.BuildBuildvcs), "buildvcs", "")
cmd.Flag.BoolVar(&cfg.BuildFullpath, "fullpath", false, "")
cmd.Flag.Var(&load.BuildGcflags, "gcflags", "")
cmd.Flag.Var(&load.BuildGccgoflags, "gccgoflags", "")
if mask&OmitModFlag == 0 {
Expand Down
14 changes: 8 additions & 6 deletions src/cmd/go/internal/work/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,14 @@ func (sh *Shell) reportCmd(desc, dir string, cmdOut []byte, cmdErr error) error
// prefixes, the only way to find them is to look.
// This doesn't always produce a relative path --
// /foo is shorter than ../../.., for example.
if reldir := base.ShortPath(dir); reldir != dir {
out = replacePrefix(out, dir, reldir)
if filepath.Separator == '\\' {
// Don't know why, sometimes this comes out with slashes, not backslashes.
wdir := strings.ReplaceAll(dir, "\\", "/")
out = replacePrefix(out, wdir, reldir)
if !cfg.BuildFullpath {
if reldir := base.ShortPath(dir); reldir != dir {
out = replacePrefix(out, dir, reldir)
if filepath.Separator == '\\' {
// Don't know why, sometimes this comes out with slashes, not backslashes.
wdir := strings.ReplaceAll(dir, "\\", "/")
out = replacePrefix(out, wdir, reldir)
}
}
}
dirP := filepath.Dir(dir)
Expand Down
9 changes: 9 additions & 0 deletions src/cmd/go/testdata/script/test_fullpath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ stdout '^ +.+/gopath/src/x/fullpath/fullpath_test.go:8: test failed'
! go test ./x/...
stdout '^ +fullpath_test.go:8: test failed'

# compiler diagnostics should also use full paths.
! go test -C ./y -fullpath .
stderr '^.*'${/}'y'${/}'y.go:3:9: undefined: mistake$'
! stderr '^\./y.go:3:9: undefined: mistake$'

-- go.mod --
module example
-- x/fullpath/fullpath_test.go --
Expand All @@ -19,3 +24,7 @@ import (
func TestFullPath(t *testing.T) {
t.Error("test failed")
}
-- y/y.go --
package y

var _ = mistake