コード例 #1
0
ファイル: GoCrossCompileInit.go プロジェクト: iizotop/kmg
func (command *GoCrossCompileInit) Execute(context *console.Context) (err error) {
	kmgc, err := kmgConfig.LoadEnvFromWd()
	if err != nil {
		return
	}
	GOROOT := kmgc.GOROOT
	if GOROOT == "" {
		return fmt.Errorf("you must set $GOROOT in environment to use GoCrossComplieInit")
	}
	var makeShellArgs []string
	var makeShellName string
	runCmdPath := filepath.Join(GOROOT, "src")
	if runtime.GOOS == "windows" {
		makeShellName = "cmd"
		makeShellArgs = []string{"/C", filepath.Join(GOROOT, "src", "make.bat"), "--no-clean"}
	} else {
		makeShellName = filepath.Join(GOROOT, "src", "make.bash")
		makeShellArgs = []string{"--no-clean"}
	}
	for _, target := range kmgc.CrossCompileTarget {
		cmd := kmgCmd.NewStdioCmd(context, makeShellName, makeShellArgs...)
		kmgCmd.SetCmdEnv(cmd, "GOOS", target.GetGOOS())
		kmgCmd.SetCmdEnv(cmd, "GOARCH", target.GetGOARCH())
		cmd.Dir = runCmdPath
		err = cmd.Run()
		if err != nil {
			return err
		}
	}
	return
}
コード例 #2
0
ファイル: GoCrossCompile.go プロジェクト: iizotop/kmg
func (command *GoCrossCompile) Execute(context *console.Context) (err error) {
	if len(context.Args) <= 2 {
		return fmt.Errorf("need gofile parameter")
	}
	targetFile := context.FlagSet().Arg(0)
	kmgc, err := kmgConfig.LoadEnvFromWd()
	if err != nil {
		return
	}
	targetName := kmgFile.GetFileBaseWithoutExt(targetFile)
	if command.outputPath == "" {
		command.outputPath = filepath.Join(kmgc.ProjectPath, "bin")
	}
	for _, target := range kmgc.CrossCompileTarget {
		fileName := targetName + "_" + target.GetGOOS() + "_" + target.GetGOARCH()
		if target.GetGOOS() == "windows" {
			fileName = fileName + ".exe"
		}
		outputFilePath := filepath.Join(command.outputPath, fileName)
		cmd := kmgCmd.NewStdioCmd(context, "go", "build", "-o", outputFilePath, targetFile)
		kmgCmd.SetCmdEnv(cmd, "GOOS", target.GetGOOS())
		kmgCmd.SetCmdEnv(cmd, "GOARCH", target.GetGOARCH())
		kmgCmd.SetCmdEnv(cmd, "GOPATH", kmgc.GOPATHToString())
		err = cmd.Run()
		if err != nil {
			return err
		}
	}
	return
}
コード例 #3
0
ファイル: GoWatch.go プロジェクト: iizotop/kmg
func (command *GoWatch) restart() error {
	//kill old process
	err := command.stop()
	if err != nil {
		return err
	}
	//start new one
	var name string
	if filepath.Ext(command.mainFilePath) == ".go" {
		name = filepath.Base(command.mainFilePath[:len(command.mainFilePath)-len(".go")])
	} else {
		name = filepath.Base(command.mainFilePath)
	}
	command.targetFilePath = filepath.Join(command.wd, "bin", name+".exe")

	command.debugPrintln("target file path: ", command.targetFilePath)

	command.cmd = kmgCmd.NewStdioCmd(command.context, "go", "build", "-o", command.targetFilePath, command.mainFilePath)
	err = kmgCmd.SetCmdEnv(command.cmd, "GOPATH", command.GOPATH)
	if err != nil {
		return err
	}

	err = command.cmd.Run()
	if err != nil {
		return fmt.Errorf("rebuild error: %s", err.Error())
	}
	_, err = os.Stat(command.targetFilePath)
	if err != nil {
		return err
	}
	command.cmd = kmgCmd.NewStdioCmd(command.context, command.targetFilePath)
	err = kmgCmd.SetCmdEnv(command.cmd, "GOPATH", command.GOPATH)
	if err != nil {
		return err
	}
	err = command.cmd.Start()
	if err != nil {
		return fmt.Errorf("restart error: %s", err.Error())
	}
	fmt.Println("[kmg] app running pid:", command.cmd.Process.Pid)
	go func() {
		cmd := command.cmd
		err := cmd.Wait()
		fmt.Println("[kmg] app exit pid:", cmd.Process.Pid)
		if err != nil {
			command.debugPrintln("wait error: ", err.Error())
		}
	}()
	return nil
}
コード例 #4
0
ファイル: Go.go プロジェクト: iizotop/kmg
func (command *Go) Execute(context *console.Context) (err error) {
	cmd := kmgCmd.NewStdioCmd(context, "go", context.Args[2:]...)
	kmgc, err := kmgConfig.LoadEnvFromWd()
	if err != nil {
		return
	}
	err = kmgCmd.SetCmdEnv(cmd, "GOPATH", kmgc.GOPATHToString())
	if err != nil {
		return err
	}
	return cmd.Run()
}
コード例 #5
0
ファイル: GoTest.go プロジェクト: iizotop/kmg
func (command *GoTest) gobuild(path string) error {
	/*
		args := []string{"build"}
		if command.v {
			fmt.Println("building ")
		} */
	fmt.Printf("[gobuild] path[%s]\n", path)
	cmd := kmgCmd.NewStdioCmd(command.context, "go", "build")
	cmd.Dir = path
	err := kmgCmd.SetCmdEnv(cmd, "GOPATH", command.gopath)
	if err != nil {
		return err
	}
	return cmd.Run()
}
コード例 #6
0
ファイル: GoTest.go プロジェクト: iizotop/kmg
func (command *GoTest) gotest(path string) error {
	fmt.Printf("[gotest] path[%s]\n", path)
	args := []string{"test"}
	if command.v {
		args = append(args, "-v")
	}
	if command.bench != "" {
		args = append(args, "-bench", command.bench)
	}
	if command.runArg != "" {
		args = append(args, "-run", command.runArg)
	}

	cmd := kmgCmd.NewStdioCmd(command.context, "go", args...)
	cmd.Dir = path
	err := kmgCmd.SetCmdEnv(cmd, "GOPATH", command.gopath)
	if err != nil {
		return err
	}
	return cmd.Run()
}