Beispiel #1
0
//生成代码
// 此处只生成swift代码,不生成golang代码.
// 限制: 输出只能有一个参数,
func MustGenerateCode(req *GenerateRequest) {
	config := reflectToTplConfig(req)
	outBs := tplGenerateCode(config)
	outB := kmgFormat.RemoteEmptyLine([]byte(outBs))
	kmgFile.MustWriteFileWithMkdir(req.OutFilePath, outB)
	if req.NeedSource {
		//生成xxx-Bridging-Header.h NSData+Compression.h NSData+Compression.m
		BridgingHeaderContent := `
//  请将该文件放到根目录的项目名文件下
#import "NSData+Compression.h"
	`
		path := strings.Split(req.OutFilePath, "/")
		parPath := strings.Join(path[:(len(path)-1)], "/") + "/"
		BridgingHeaderPath := parPath + req.OutProjectName + "-Bridging-Header.h"
		NSDataCompressionMethodPath := parPath + "NSData+Compression.m"
		NSDataCompressionHeadPath := parPath + "NSData+Compression.h"
		InfoListPath := parPath + "Info.plist"
		path = strings.Split(req.XcodeprojPath, "/")
		projectPath := strings.Join(path[:(len(path)-1)], "/") + "/"
		podFilePath := projectPath + "Podfile"
		xcodeprojPath := req.XcodeprojPath
		kmgFile.MustWriteFileWithMkdir(BridgingHeaderPath, []byte(BridgingHeaderContent))
		kmgFile.MustWriteFileWithMkdir(NSDataCompressionMethodPath, []byte(NSDataCompressionMethod()))
		kmgFile.MustWriteFileWithMkdir(NSDataCompressionHeadPath, []byte(NSDataCompressionHead()))
		kmgFile.MustWriteFileWithMkdir(InfoListPath, []byte(InfoList()))
		kmgFile.MustWriteFileWithMkdir(podFilePath, []byte(Podfile(req.OutProjectName)))
		kmgFileToXcode.AddFilesToXcode([]string{req.OutFilePath, BridgingHeaderPath, NSDataCompressionMethodPath, NSDataCompressionHeadPath}, xcodeprojPath)
		cmd := kmgCmd.CmdBash("export LANG=UTF-8;pod install")
		cmd.SetDir(projectPath)
		cmd.MustRun()
	}
}
Beispiel #2
0
func LinuxGetAllProcessByBinName(binName string) []*Process {
	if !kmgPlatform.LinuxAmd64.Compatible(kmgPlatform.GetCompiledPlatform()) {
		panic(kmgSys.ErrPlatformNotSupport)
	}
	b, err := kmgCmd.CmdBash(CmdProcessByBinName(binName)).GetExecCmd().CombinedOutput()
	if err != err {
		fmt.Println(err)
	}
	return Extract(string(b))
}
Beispiel #3
0
func AddFileToXcode(FilePath string, ProjectPath string) []byte {
	dir := defaultEnv.Env().ProjectPath + "/"
	if !kmgStrings.IsStartWith(FilePath, "~") && !kmgStrings.IsStartWith(FilePath, "/") {
		FilePath = dir + FilePath
	}
	if !kmgStrings.IsStartWith(ProjectPath, "~") && !kmgStrings.IsStartWith(ProjectPath, "/") {
		ProjectPath = dir + ProjectPath
	}
	cmd := kmgCmd.CmdBash("export LANG=UTF-8;ruby AddFileToXcode.rb " + FilePath + " " + ProjectPath)
	cmd.SetDir(dir + "src/github.com/bronze1man/kmg/kmgFileToXcode")
	out := cmd.MustRunAndReturnOutput()
	return out
}
Beispiel #4
0
func runCommand(kmgc *kmgConfig.Env, args []string) {
	os.Chdir(kmgc.ProjectPath)
	logDir := filepath.Join(kmgc.LogPath, "run")
	kmgFile.MustMkdirAll(logDir)
	thisLogFilePath := filepath.Join(logDir, time.Now().Format(kmgTime.FormatFileName)+".log")
	kmgFile.MustWriteFile(thisLogFilePath, []byte{})
	if !kmgPlatform.GetCompiledPlatform().Compatible(kmgPlatform.WindowsAmd64) {
		lastLogPath := filepath.Join(logDir, "last.log")
		if kmgFile.MustFileExist(lastLogPath) {
			kmgFile.MustSymlink(kmgFile.MustReadSymbolLink(lastLogPath), filepath.Join(logDir, "last2.log"))
		}
		kmgFile.MustSymlink(filepath.Base(thisLogFilePath), lastLogPath)
	}
	//TODO 大部分命令是 kmg gorun xxx 在这个地方可以直接调用gorun解决问题,这样可以少开一个进程加快了一些速度
	// 问题: 上述做法不靠谱,会导致last.log没有用处.
	//if len(args) >= 2 && args[0] == "kmg" && strings.EqualFold(args[1], "gorun") {
	//	os.Args = append(args[1:], os.Args[1:]...)
	//	goCmd.GoRunCmd()
	//	return
	//}
	// 下面的做法不靠谱,会让signle无法传递
	//err := kmgCmd.CmdSlice(append(args, os.Args[1:]...)).
	//	SetDir(kmgc.ProjectPath).
	//	RunAndTeeOutputToFile(thisLogFilePath)
	// TODO bash转义
	bashCmd := strings.Join(append(args, os.Args[1:]...), " ")
	bashCmdStr := bashCmd + " 2>&1 | tee -i " + thisLogFilePath + " ; test ${PIPESTATUS[0]} -eq 0"
	if kmgPlatform.IsWindows() {
		err := kmgCmd.CmdString(bashCmdStr).SetDir(kmgc.ProjectPath).StdioRun()
		if err != nil {
			err = fmt.Errorf("kmg make: %s", err)
			kmgConsole.ExitOnErr(err)
		}
		return
	} else {
		err := kmgCmd.CmdBash(bashCmdStr).SetDir(kmgc.ProjectPath).StdioRun()
		if err != nil {
			err = fmt.Errorf("kmg make: %s", err)
			kmgConsole.ExitOnErr(err)
		}
		return
	}
}
Beispiel #5
0
func main() {
	//var exitSignalProcessor func(signal os.Signal) // 只杀掉一层子进程不管用,bash -c 不会传递信号.
	go func() {
		kmgCmd.MustRun("kmg go install github.com/bronze1man/kmg/kmgCmd/testPackage/testCmdChildren")
		cmd := kmgCmd.CmdBash("./bin/testCmdChildren cmd | tee -i /tmp/1.log")
		//exitSignalProcessor = func(signal os.Signal){
		//	err := cmd.GetExecCmd().Process.Signal(signal)
		//	if err!=nil{
		//		panic(err)
		//	}
		//}
		cmd.MustRun()
		fmt.Println("parent Must Run return")
	}()
	ch := make(chan os.Signal, 10)
	signal.Notify(ch, os.Interrupt, os.Kill, syscall.SIGTERM)
	thisSignal := <-ch
	fmt.Println("parent", thisSignal)
	//if exitSignalProcessor!=nil {
	//	exitSignalProcessor(thisSignal)
	//}
}