Skip to content

Commit

Permalink
wip: #3074
Browse files Browse the repository at this point in the history
  • Loading branch information
hailaz committed Nov 13, 2023
1 parent d4b14fd commit 32bf6ed
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions cmd/gf/internal/cmd/cmd_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gbuild"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/genv"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/os/gproc"
"github.com/gogf/gf/v2/os/gtime"
Expand Down Expand Up @@ -232,12 +231,14 @@ func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, e
c.getBuildInVarStr(ctx, in),
)

envMap := make(map[string]string)

// start building
mlog.Print("start building...")
if in.Cgo {
genv.MustSet("CGO_ENABLED", "1")
envMap["CGO_ENABLED"] = "1"
} else {
genv.MustSet("CGO_ENABLED", "0")
envMap["CGO_ENABLED"] = "0"
}
var (
cmd = ""
Expand Down Expand Up @@ -276,8 +277,8 @@ func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, e
if system == "windows" {
ext = ".exe"
}
genv.MustSet("GOOS", system)
genv.MustSet("GOARCH", arch)
envMap["GOOS"] = system
envMap["GOARCH"] = arch

var outputPath string
if len(in.Output) > 0 {
Expand All @@ -289,10 +290,17 @@ func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, e
)
}
cmd = fmt.Sprintf(
`GOOS=%s GOARCH=%s go build %s -ldflags "%s" %s%s`,
system, arch, outputPath, ldFlags, in.Extra, file,
`go build %s -ldflags "%s" %s%s`,
outputPath, ldFlags, in.Extra, file,
)
}
for k, v := range envMap {
if runtime.GOOS == "windows" {
cmd = fmt.Sprintf(`set %s=%s&&`, k, v) + cmd
} else {
cmd = fmt.Sprintf(`%s=%s `, k, v) + cmd
}
}
mlog.Debug(cmd)
// It's not necessary printing the complete command string.
cmdShow, _ := gregex.ReplaceString(`\s+(-ldflags ".+?")\s+`, " ", cmd)
Expand Down

0 comments on commit 32bf6ed

Please sign in to comment.