From 92e7954dbc99a8a1b56393c3c797b5f537b4e473 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 7 Jul 2018 16:43:47 +0200 Subject: [PATCH] add default types --- cmd/aicra/build-controllers.go | 1 - cmd/aicra/build-types.go | 11 +++++------ cmd/aicra/main.go | 29 ++++++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/cmd/aicra/build-controllers.go b/cmd/aicra/build-controllers.go index 5f06d31..9309d86 100644 --- a/cmd/aicra/build-controllers.go +++ b/cmd/aicra/build-controllers.go @@ -14,7 +14,6 @@ import ( // recursively and generate .so files // into the @out folder with the same structure func buildControllers(in string, out string) error { - clifmt.Title("compile controllers") /* (1) Create build folder */ clifmt.Align(" . create output folder") diff --git a/cmd/aicra/build-types.go b/cmd/aicra/build-types.go index 516bd42..24ca7a4 100644 --- a/cmd/aicra/build-types.go +++ b/cmd/aicra/build-types.go @@ -14,7 +14,6 @@ import ( // recursively and generate .so files // into the @out folder with the same structure func buildTypes(in string, out string) error { - clifmt.Title("compile types") /* (1) Create build folder */ clifmt.Align(" . create output folder") @@ -24,7 +23,7 @@ func buildTypes(in string, out string) error { } fmt.Printf("ok\n") - /* (1) List recursively */ + /* (2) List recursively */ types := []string{} err = filepath.Walk(in, func(path string, f os.FileInfo, err error) error { if strings.HasSuffix(path, "/main.go") { @@ -37,7 +36,7 @@ func buildTypes(in string, out string) error { return err } - /* (2) Print files */ + /* (3) Print files */ for _, name := range types { // 1. process output file name @@ -46,20 +45,20 @@ func buildTypes(in string, out string) error { clifmt.Align(fmt.Sprintf(" . compile %s", clifmt.Color(33, name))) - // 3. compile + // 2. compile stdout, err := exec.Command("go", "build", "-buildmode=plugin", "-o", outfile, infile, ).Output() - // 4. success + // 3. success if err == nil { fmt.Printf("ok\n") continue } - // 5. debug error + // 4. debug error fmt.Printf("error\n") if len(stdout) > 0 { fmt.Printf("%s\n%s\n%s\n", clifmt.Color(31, "-=-"), stdout, clifmt.Color(31, "-=-")) diff --git a/cmd/aicra/main.go b/cmd/aicra/main.go index 031aacf..96d4a03 100644 --- a/cmd/aicra/main.go +++ b/cmd/aicra/main.go @@ -58,6 +58,9 @@ func main() { return } + // default types folder + dtPath := filepath.Join(os.Getenv("GOPATH"), "src/git.xdrm.io/go/aicra/checker/default") + /* (3) Check path are existing dirs ---------------------------------------------------------*/ clifmt.Title("file check") @@ -82,7 +85,17 @@ func main() { fmt.Printf("ok\n") } - /* (3) Types path */ + /* (3) Default types path */ + clifmt.Align(" . default types") + if stat, err := os.Stat(dtPath); err != nil || !stat.IsDir() { + fmt.Printf("missing\n") + compileTypes = false + + } else { + fmt.Printf("ok\n") + } + + /* (4) Types path */ clifmt.Align(" . custom types") if stat, err := os.Stat(tPath); err != nil || !stat.IsDir() { fmt.Printf("missing\n") @@ -112,21 +125,31 @@ func main() { /* (2) Compile controllers */ if compileControllers { + clifmt.Title("compile controllers") err = buildControllers(cPath, filepath.Join(projectPath, ".build/controller")) if err != nil { fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err) } } - /* (3) Compile types */ + /* (3) Compile DEFAULT types */ + clifmt.Title("compile default types") + err = buildTypes( + dtPath, + filepath.Join(projectPath, ".build/types")) + if err != nil { + fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err) + } + /* (4) Compile types */ if compileTypes { + clifmt.Title("compile types") err = buildTypes(tPath, filepath.Join(projectPath, ".build/types")) if err != nil { fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err) } } - /* (4) finished */ + /* (5) finished */ fmt.Printf("\n[ %s ] files are located inside the %s directory inside the project folder\n", clifmt.Color(32, "finished"), clifmt.Color(33, ".build"),