try 使用此命令:
go build -修剪路径
这是the Go command的-修剪路径
旗帜的文件:
-修剪路径
从生成的可执行文件中删除所有文件系统路径.
记录的文件名不是绝对文件系统路径
将开始一个模块路径@版本(当使用模块时),
或普通导入路径(当使用标准库或GOPATH时).
如果您只想删除一些前缀,可以这样做:
go build -gcflags "all=-修剪路径=%CD%;%GOPATH%" -asmflags "all=-修剪路径=%CD%;%GOPATH%"
the Compile command和the Asm command都调用objabi.ApplyRewrites
来修剪路径.根据the implementation of objabi.ApplyRewrites的说法,rewrites
参数是以;分隔的重写列表.
// ApplyRewrites returns the filename for file in the given directory,
// as rewritten by the rewrites argument.
//
// The rewrites argument is a ;-separated list of rewrites.
// Each rewrite is of the form "prefix" or "prefix=>replace",
// where prefix must match a leading sequence of path elements
// and is either removed entirely or replaced by the replacement.
func ApplyRewrites(file, rewrites string) (string, bool) {
start := 0
for i := 0; i <= len(rewrites); i++ {
if i == len(rewrites) || rewrites[i] == ';' {
if new, ok := applyRewrite(file, rewrites[start:i]); ok {
return new, true
}
start = i + 1
}
}
return file, false
}