cmd: improve build command

This commit is contained in:
c9s 2022-01-23 14:44:17 +08:00
parent 5790c10a38
commit 1f18c36870
2 changed files with 5 additions and 6 deletions

View File

@ -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) {

View File

@ -11,7 +11,7 @@ import (
)
func init() {
BuildCmd.Flags().String("config", "", "config file")
BuildCmd.Flags().String("config", "bbgo.yaml", "config file")
RootCmd.AddCommand(BuildCmd)
}