[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bee pack -ba="-ldflags "-X "”两个引号问题 #812

Open
barryzxy opened this issue Dec 7, 2021 · 4 comments
Open

bee pack -ba="-ldflags "-X "”两个引号问题 #812

barryzxy opened this issue Dec 7, 2021 · 4 comments

Comments

@barryzxy
Copy link
barryzxy commented Dec 7, 2021

在执行一下命令是,有两个双引号,出现-X不识别问题
bee pack -be GOOS=windows -be GOARCH=amd64 -ba="-ldflags "-X 'main.BuildTime=$today' -X 'main.Version=$version'"" -a tmaiapp
以下是提醒

Z:\gowork\go1.17.4\pkg\tool\windows_amd64\link.exe: -X flag requires argument of the form importpath.name=value
2021/12/07 17:47:06 FATAL ▶ 0004 exit status 2

@wangqianwei
Copy link

有人可以处理这个问题么

@flycash
Copy link
Collaborator
flycash commented Nov 24, 2022

你可以看看 bee pack 命令是怎么处理的,我觉得近期没时间处理这个

@wangqianwei
Copy link

修改前的代码

        //// pack.go 506行
        args := []string{"build", "-o", binPath}
		if len(buildArgs) > 0 {
			args = append(args, strings.Fields(buildArgs)...)
		}

		if verbose {
			fmt.Fprintf(output, "\t%s%s+ go %s%s%s\n", "\x1b[32m", "\x1b[1m", strings.Join(args, " "), "\x1b[21m", "\x1b[0m")
		}

		execmd := exec.Command("go", args...)

可以做如下调整

        //// pack.go 506行
        var execmd *exec.Cmd
		buildCmdStr := "go build -o " + binPath + " " + buildArgs
		if runtime.GOOS == "windows" {
			execmd   = exec.Command("cmd", "/C", buildCmdStr)
		} else {
			execmd = exec.Command("/bin/bash", "-c", buildCmdStr)
		}

		if verbose {
			fmt.Fprintf(output, "\t%s%s+ %s%s%s\n", "\x1b[32m", "\x1b[1m", buildCmdStr, "\x1b[21m", "\x1b[0m")
		}

问题原因是因为buildArgs参数不能直接使用strings.Fields函数简单的通过空格来分割参数,并直接作为打包命令的参数来使用。buildArgs参数中的ldflags参数本身就带有多个空格。所以打包一定会存在问题。最小的改动就是直接拼接一下可执行的大打包命令。

@flycash
Copy link
Collaborator
flycash commented Jan 2, 2023

可以直接发一个合并请求吗?

Baihhh pushed a commit to Baihhh/bee that referenced this issue Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants