Get proper GOPATH in trim function (#5744)

Set GOPATH string to empty in build-constants.go
Check for both compile time GOPATH and default GOPATH
while trimming the file path in the stack trace.
Fixes #5741
master
kannappanr 7 years ago committed by Harshavardhana
parent 4d02f9bccf
commit b87cc3d643
  1. 4
      cmd/build-constants.go
  2. 10
      cmd/logger.go

@ -16,13 +16,11 @@
package cmd package cmd
import "go/build"
// DO NOT EDIT THIS FILE DIRECTLY. These are build-time constants // DO NOT EDIT THIS FILE DIRECTLY. These are build-time constants
// set through ‘buildscripts/gen-ldflags.go’. // set through ‘buildscripts/gen-ldflags.go’.
var ( var (
// GOPATH - GOPATH value at the time of build. // GOPATH - GOPATH value at the time of build.
GOPATH = build.Default.GOPATH GOPATH = ""
// Go get development tag. // Go get development tag.
goGetTag = "DEVELOPMENT.GOGET" goGetTag = "DEVELOPMENT.GOGET"

@ -19,6 +19,7 @@ package cmd
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"go/build"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -98,13 +99,17 @@ func (log *Logger) Printf(format string, args ...interface{}) {
func init() { func init() {
var goPathList []string var goPathList []string
var defaultgoPathList []string
// Add all possible GOPATH paths into trimStrings // Add all possible GOPATH paths into trimStrings
// Split GOPATH depending on the OS type // Split GOPATH depending on the OS type
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
goPathList = strings.Split(GOPATH, ";") goPathList = strings.Split(GOPATH, ";")
defaultgoPathList = strings.Split(build.Default.GOPATH, ";")
} else { } else {
// All other types of OSs // All other types of OSs
goPathList = strings.Split(GOPATH, ":") goPathList = strings.Split(GOPATH, ":")
defaultgoPathList = strings.Split(build.Default.GOPATH, ":")
} }
// Add trim string "{GOROOT}/src/" into trimStrings // Add trim string "{GOROOT}/src/" into trimStrings
@ -115,6 +120,11 @@ func init() {
for _, goPathString := range goPathList { for _, goPathString := range goPathList {
trimStrings = append(trimStrings, filepath.Join(goPathString, "src")+string(filepath.Separator)) trimStrings = append(trimStrings, filepath.Join(goPathString, "src")+string(filepath.Separator))
} }
for _, defaultgoPathString := range defaultgoPathList {
trimStrings = append(trimStrings, filepath.Join(defaultgoPathString, "src")+string(filepath.Separator))
}
// Add "github.com/minio/minio" as the last to cover // Add "github.com/minio/minio" as the last to cover
// paths like "{GOROOT}/src/github.com/minio/minio" // paths like "{GOROOT}/src/github.com/minio/minio"
// and "{GOPATH}/src/github.com/minio/minio" // and "{GOPATH}/src/github.com/minio/minio"

Loading…
Cancel
Save