我正在尝试使用ldflags选项编译beego:
bee pack -v -ba="-ldflags '-s -w'"
然后去抱怨:
go build -o /var/folders/XXX/XXX/T/beePack-4329015000/XXXX -ldflags='-s -w'
invalid value "'-s" for flag -ldflags: missing =<value> in <pattern>=<value>
我正在将最新的beego与go1.12.6结合使用。看起来beego正在使用space
分隔命令行并添加了一些检查。
有什么想法吗?
编辑
使用-ldflags ='-s -w'
GOOS=linux bee pack -v -exr=vendor -ba="-ldflags='-s -w'"
我知道了
+ go build -o /var/folders/xxx/xxx/T/beePack-2277518000/xxx -ldflags='-s -w'
invalid value "'-s" for flag -ldflags: missing =<value> in <pattern>=<value>
答案 0 :(得分:0)
我检查了蜜蜂工具的源代码。这应该是一个错误,我将在他们的GitHub存储库中发布一个问题。
此处是指向相关code的链接。请看下面的评论。
args := []string{"build", "-o", binPath}
if len(buildArgs) > 0 {
//Giulio: Here they split the input arguments using whitespace as delimiter.
//In your case it would become: "-ldflags='-s -w'" => ["-ldflags='-s", "-w'"]
args = append(args, strings.Fields(buildArgs)...)
}
if verbose {
//Giulio: The print is fine, reconstruct the same string with strings.Join
fmt.Fprintf(output, "\t%s%s+ go %s%s%s\n", "\x1b[32m", "\x1b[1m", strings.Join(args, " "), "\x1b[21m", "\x1b[0m")
}
//Giulio: but, here, they use the slice with splitted flags, i.e. ["-ldflags='-s", "-w'"], which is the real problem.
execmd := exec.Command("go", args...)