build controller + types is ok
This commit is contained in:
parent
c3bcf40e43
commit
5cc1e091e9
|
@ -25,7 +25,7 @@ func Info(s ...string) string {
|
|||
|
||||
func Title(s string) {
|
||||
title_index++
|
||||
fmt.Printf("\n%s (%d) %s %s\n", Color(33, ">>", false), title_index, s, Color(33, "<<", false))
|
||||
fmt.Printf("\n%s |%d| %s %s\n", Color(33, ">>", false), title_index, s, Color(33, "<<", false))
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,72 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.xdrm.io/go/aicra/clifmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Builds controllers as plugins (.so)
|
||||
// from the sources in the @in folder
|
||||
// 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")
|
||||
err := os.MkdirAll(out, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("ok\n")
|
||||
|
||||
/* (1) List recursively */
|
||||
sources := []string{}
|
||||
err = filepath.Walk(in, func(path string, f os.FileInfo, err error) error {
|
||||
if strings.HasSuffix(path, "i.go") {
|
||||
sources = append(sources, path)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
/* (2) Print files */
|
||||
for _, infile := range sources {
|
||||
|
||||
// 1. process output file name
|
||||
rel, _ := filepath.Rel(in, infile)
|
||||
outfile := strings.Replace(rel, ".go", ".so", 1)
|
||||
outfile = fmt.Sprintf("%s/%s", out, outfile)
|
||||
|
||||
clifmt.Align(fmt.Sprintf(" . compile %s", clifmt.Color(33, rel)))
|
||||
|
||||
// 3. compile
|
||||
stdout, err := exec.Command("go",
|
||||
"build", "-buildmode=plugin",
|
||||
"-o", outfile,
|
||||
infile,
|
||||
).Output()
|
||||
|
||||
// 4. success
|
||||
if err == nil {
|
||||
fmt.Printf("ok\n")
|
||||
continue
|
||||
}
|
||||
|
||||
// 5. 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, "-=-"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.xdrm.io/go/aicra/clifmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Builds types as plugins (.so)
|
||||
// from the sources in the @in folder
|
||||
// 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")
|
||||
err := os.MkdirAll(out, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("ok\n")
|
||||
|
||||
/* (1) List recursively */
|
||||
types := []string{}
|
||||
err = filepath.Walk(in, func(path string, f os.FileInfo, err error) error {
|
||||
if strings.HasSuffix(path, "/main.go") {
|
||||
types = append(types, filepath.Base(filepath.Dir(path)))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
/* (2) Print files */
|
||||
for _, name := range types {
|
||||
|
||||
// 1. process output file name
|
||||
infile := filepath.Join(in, name, "main.go")
|
||||
outfile := filepath.Join(out, fmt.Sprintf("%s.so", name))
|
||||
|
||||
clifmt.Align(fmt.Sprintf(" . compile %s", clifmt.Color(33, name)))
|
||||
|
||||
// 3. compile
|
||||
stdout, err := exec.Command("go",
|
||||
"build", "-buildmode=plugin",
|
||||
"-o", outfile,
|
||||
infile,
|
||||
).Output()
|
||||
|
||||
// 4. success
|
||||
if err == nil {
|
||||
fmt.Printf("ok\n")
|
||||
continue
|
||||
}
|
||||
|
||||
// 5. 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, "-=-"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -60,10 +60,10 @@ func main() {
|
|||
|
||||
/* (3) Check path are existing dirs
|
||||
---------------------------------------------------------*/
|
||||
clifmt.Title("Check files")
|
||||
clifmt.Title("file check")
|
||||
|
||||
/* (1) Project path */
|
||||
clifmt.Align(" . project root")
|
||||
clifmt.Align(" . project root")
|
||||
if stat, err := os.Stat(projectPath); err != nil || !stat.IsDir() {
|
||||
fmt.Printf("invalid\n\n")
|
||||
fmt.Printf("%s invalid project folder - %s\n\n", clifmt.Warn(), clifmt.Color(36, projectPath))
|
||||
|
@ -74,7 +74,7 @@ func main() {
|
|||
}
|
||||
|
||||
/* (2) Controllers path */
|
||||
clifmt.Align(" . controllers")
|
||||
clifmt.Align(" . controllers")
|
||||
if stat, err := os.Stat(cPath); err != nil || !stat.IsDir() {
|
||||
compileControllers = false
|
||||
fmt.Printf("missing\n")
|
||||
|
@ -83,7 +83,7 @@ func main() {
|
|||
}
|
||||
|
||||
/* (3) Types path */
|
||||
clifmt.Align(" . custom types")
|
||||
clifmt.Align(" . custom types")
|
||||
if stat, err := os.Stat(tPath); err != nil || !stat.IsDir() {
|
||||
fmt.Printf("missing\n")
|
||||
compileTypes = false
|
||||
|
@ -97,4 +97,39 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
/* (4) Compile
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Create build output dir */
|
||||
buildPath := filepath.Join(projectPath, ".build")
|
||||
clifmt.Align(" . create build folder")
|
||||
err = os.MkdirAll(buildPath, os.ModePerm)
|
||||
if err != nil {
|
||||
fmt.Printf("error\n\n")
|
||||
fmt.Printf("%s the directory %s cannot be created, check permissions.", clifmt.Warn(), clifmt.Color(33, buildPath))
|
||||
return
|
||||
}
|
||||
fmt.Printf("ok\n")
|
||||
|
||||
/* (2) Compile controllers */
|
||||
if compileControllers {
|
||||
err = buildControllers(cPath, filepath.Join(projectPath, ".build/controller"))
|
||||
if err != nil {
|
||||
fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err)
|
||||
}
|
||||
}
|
||||
|
||||
/* (3) Compile types */
|
||||
if compileTypes {
|
||||
err = buildTypes(tPath, filepath.Join(projectPath, ".build/types"))
|
||||
if err != nil {
|
||||
fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err)
|
||||
}
|
||||
}
|
||||
|
||||
/* (4) 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"),
|
||||
)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue