fix
This commit is contained in:
parent
6273ded5d7
commit
0ab05816ea
|
@ -1,71 +0,0 @@
|
||||||
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 {
|
|
||||||
|
|
||||||
/* (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
|
|
||||||
}
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
// from the sources in the @in folder
|
// from the sources in the @in folder
|
||||||
// recursively and generate .so files
|
// recursively and generate .so files
|
||||||
// into the @out folder with the same structure
|
// into the @out folder with the same structure
|
||||||
func buildTypes(in string, out string) error {
|
func compile(in string, out string) error {
|
||||||
|
|
||||||
/* (1) Create build folder */
|
/* (1) Create build folder */
|
||||||
clifmt.Align(" . create output folder")
|
clifmt.Align(" . create output folder")
|
|
@ -152,7 +152,7 @@ func main() {
|
||||||
/* (2) Compile controllers */
|
/* (2) Compile controllers */
|
||||||
if compileControllers {
|
if compileControllers {
|
||||||
clifmt.Title("compile controllers")
|
clifmt.Title("compile controllers")
|
||||||
err = buildControllers(cPath, filepath.Join(projectPath, ".build/controller"))
|
err = compile(cPath, filepath.Join(projectPath, ".build/controller"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err)
|
fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err)
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ func main() {
|
||||||
/* (3) Compile middlewares */
|
/* (3) Compile middlewares */
|
||||||
if compileMiddlewares {
|
if compileMiddlewares {
|
||||||
clifmt.Title("compile middlewares")
|
clifmt.Title("compile middlewares")
|
||||||
err = buildTypes(mPath, filepath.Join(projectPath, ".build/middleware"))
|
err = compile(mPath, filepath.Join(projectPath, ".build/middleware"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err)
|
fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err)
|
||||||
}
|
}
|
||||||
|
@ -169,16 +169,14 @@ func main() {
|
||||||
|
|
||||||
/* (4) Compile DEFAULT types */
|
/* (4) Compile DEFAULT types */
|
||||||
clifmt.Title("compile default types")
|
clifmt.Title("compile default types")
|
||||||
err = buildTypes(
|
err = compile(dtPath, filepath.Join(projectPath, ".build/type"))
|
||||||
dtPath,
|
|
||||||
filepath.Join(projectPath, ".build/type"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err)
|
fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err)
|
||||||
}
|
}
|
||||||
/* (5) Compile types */
|
/* (5) Compile types */
|
||||||
if compileTypes {
|
if compileTypes {
|
||||||
clifmt.Title("compile types")
|
clifmt.Title("compile types")
|
||||||
err = buildTypes(tPath, filepath.Join(projectPath, ".build/type"))
|
err = compile(tPath, filepath.Join(projectPath, ".build/type"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err)
|
fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,9 +98,9 @@ func (i *Request) LoadController(method string) (func(implement.Arguments, *impl
|
||||||
/* (1) Build controller path */
|
/* (1) Build controller path */
|
||||||
path := strings.Join(i.Path, "-")
|
path := strings.Join(i.Path, "-")
|
||||||
if len(path) == 0 {
|
if len(path) == 0 {
|
||||||
path = fmt.Sprintf(".build/controller/ROOT/main.so")
|
path = fmt.Sprintf(".build/controller/ROOT.so")
|
||||||
} else {
|
} else {
|
||||||
path = fmt.Sprintf(".build/controller/%s/main.so", path)
|
path = fmt.Sprintf(".build/controller/%s.so", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (2) Format url */
|
/* (2) Format url */
|
||||||
|
|
Loading…
Reference in New Issue