From 1f18c3687005f6b0d236fab0d609f4e379fc74ed Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 23 Jan 2022 14:44:17 +0800 Subject: [PATCH] cmd: improve build command --- pkg/bbgo/builder.go | 9 ++++----- pkg/cmd/build.go | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/bbgo/builder.go b/pkg/bbgo/builder.go index dcee9dc39..30c9ea175 100644 --- a/pkg/bbgo/builder.go +++ b/pkg/bbgo/builder.go @@ -80,8 +80,6 @@ func Build(ctx context.Context, userConfig *Config, targetConfig BuildTargetConf return "", err } - defer os.RemoveAll(packageDir) - if err := compilePackage(packageDir, userConfig, imports); err != nil { return "", err } @@ -110,8 +108,9 @@ func Build(ctx context.Context, userConfig *Config, targetConfig BuildTargetConf output := filepath.Join(buildDir, binary) - logrus.Infof("building binary %s from %s...", output, buildTarget) - buildCmd := exec.CommandContext(ctx, "go", "build", "-tags", "wrapper", "-o", output, buildTarget) + args := []string{"build", "-tags", "wrapper", "-o", output, buildTarget} + logrus.Debugf("building binary %s from %s: go %v", output, buildTarget, args) + buildCmd := exec.CommandContext(ctx, "go", args...) buildCmd.Env = append(os.Environ(), buildEnvs...) buildCmd.Stdout = os.Stdout buildCmd.Stderr = os.Stderr @@ -119,7 +118,7 @@ func Build(ctx context.Context, userConfig *Config, targetConfig BuildTargetConf return output, err } - return output, nil + return output, os.RemoveAll(packageDir) } func BuildTarget(ctx context.Context, userConfig *Config, target BuildTargetConfig) (string, error) { diff --git a/pkg/cmd/build.go b/pkg/cmd/build.go index 6740e4791..3a8c5c22d 100644 --- a/pkg/cmd/build.go +++ b/pkg/cmd/build.go @@ -11,7 +11,7 @@ import ( ) func init() { - BuildCmd.Flags().String("config", "", "config file") + BuildCmd.Flags().String("config", "bbgo.yaml", "config file") RootCmd.AddCommand(BuildCmd) }