fix(plugin): fix incorrect build version info package name

This commit is contained in:
LinkinStar 2023-02-01 18:14:54 +08:00
parent ebaaaff4f1
commit b4ae373309
3 changed files with 9 additions and 8 deletions

View File

@ -7,7 +7,7 @@ DOCKER_CMD=docker
GO_ENV=CGO_ENABLED=0 GO111MODULE=on
Revision=$(shell git rev-parse --short HEAD)
GO_FLAGS=-ldflags="-X answercmd.Version=$(VERSION) -X 'answercmd.Revision=$(Revision)' -X 'answercmd.Time=`date`' -extldflags -static"
GO_FLAGS=-ldflags="-X github.com/answerdev/answer/cmd.Version=$(VERSION) -X 'github.com/answerdev/answer/cmd.Revision=$(Revision)' -X 'github.com/answerdev/answer/cmd.Time=`date`' -extldflags -static"
GO=$(GO_ENV) $(shell which go)
build: generate

View File

@ -16,7 +16,7 @@ import (
"github.com/segmentfault/pacman/log"
)
// go build -ldflags "-X answercmd.Version=x.y.z"
// go build -ldflags "-X github.com/answerdev/answer/cmd.Version=x.y.z"
var (
// Name is the name of the project
Name = "answer"

View File

@ -191,9 +191,11 @@ func copyDirEntries(sourceFs embed.FS, sourceDir string, targetDir string) (err
func buildBinary(b *buildingMaterial) (err error) {
versionInfo := b.originalAnswerInfo
ldflags := fmt.Sprintf(`-ldflags="-X answercmd.Version=%s -X answercmd.Revision=%s -X answercmd.Time=%s`,
versionInfo.Version, versionInfo.Revision, versionInfo.Time)
err = b.newExecCmd("go", "build", ldflags, "-o", b.outputPath, ".").Run()
cmdPkg := "github.com/answerdev/answer/cmd"
ldflags := fmt.Sprintf("-X %s.Version='%s' -X %s.Revision='%s' -X %s.Time='%s'",
cmdPkg, versionInfo.Version, cmdPkg, versionInfo.Revision, cmdPkg, versionInfo.Time)
err = b.newExecCmd("go", "build",
"-ldflags", ldflags, "-o", b.outputPath, ".").Run()
if err != nil {
return err
}
@ -201,8 +203,7 @@ func buildBinary(b *buildingMaterial) (err error) {
}
func cleanByproduct(b *buildingMaterial) (err error) {
//return os.RemoveAll(b.tmpDir)
return nil
return os.RemoveAll(b.tmpDir)
}
func (b *buildingMaterial) newExecCmd(command string, args ...string) *exec.Cmd {
@ -238,6 +239,6 @@ func main() {
go 1.19
replace github.com/answerdev/answer latest => replace github.com/answerdev/answer feature-plugin
replace github.com/answerdev/answer latest => github.com/answerdev/answer feature-plugin
`
)