有沒有辦法配置/直接go build等go test來使用絕對路徑報告文件位置?我經(jīng)常go build從編輯器(解析輸出)運行,如果進程的當前工作目錄go build和編輯器本身不需要匹配,那就很方便了。到目前為止,我找到的唯一解決方案是封裝go build一個確定文件絕對路徑的腳本,然后在使用'd 原始參數(shù)cd調(diào)用之前立即轉(zhuǎn)到臨時目錄。go buildrealpath創(chuàng)建一個臨時目錄并cd訪問它只是為了欺騙 go 工具似乎是一個奇怪的解決方法,所以我想知道是否有更直接的解決方案。go tools除了包裝絕對路徑并cd隨機目錄之外,還有其他方法可以配置報告絕對路徑嗎?假設我的GOPATH是/go并且我有以下文件。// /go/src/nonexistent-website.com/example-2019-10-26/main.gopackage mainimport ( "fmt")func main() { fmt.Println("hi")}假設我故意在這個文件中引入一個錯誤。// /go/src/nonexistent-website.com/example-2019-10-26/main.gopackage main// import (// "fmt"// )func main() { fmt.Println("hi")}go build main.go報告以下錯誤:/go/src/nonexistent-website.com/example-2019-10-26$ go build main.go# command-line-arguments./main.go:9: undefined: fmt in fmt.Println 2go build ...如果給定絕對路徑,仍然報告./main.go為文件的路徑/go/src/nonexistent-website.com/example-2019-10-26$ go build `realpath main.go`# command-line-arguments./main.go:9: undefined: fmt in fmt.Println 2go build似乎生成了相對于調(diào)用它的目錄的路徑:go build這些是首先定向到cd根目錄時生成的路徑。/go/src/nonexistent-website.com/example-2019-10-26$ (a=`realpath main.go` && cd / && go build $a)# command-line-argumentsgo/src/nonexistent-website.com/example-2019-10-26/main.go:9: undefined: fmt in fmt.Println 2可以通過-ing 到保證是最新的目錄來go build誘導發(fā)出絕對路徑cd/go/src/nonexistent-website.com/example-2019-10-26$ (a=`realpath main.go` && cd `mktemp -d` && go build $a)# command-line-arguments/go/src/nonexistent-website.com/example-2019-10-26/main.go:9: undefined: fmt in fmt.Println 2
- 1 回答
- 0 關注
- 205 瀏覽
添加回答
舉報
0/150
提交
取消