diff --git a/cmd/internal/load/gop.go b/cmd/internal/load/gop.go index d5149f42..990aaebc 100644 --- a/cmd/internal/load/gop.go +++ b/cmd/internal/load/gop.go @@ -40,5 +40,5 @@ func BuildGopDir(ctx *igop.Context, path string) error { } func IsGopProject(dir string) bool { - return ContainsExt(dir, ".gop") + return ContainsExt(dir, ".gop", ".gox") } diff --git a/cmd/internal/load/load.go b/cmd/internal/load/load.go index 146481ea..92377880 100644 --- a/cmd/internal/load/load.go +++ b/cmd/internal/load/load.go @@ -30,13 +30,18 @@ func IsDir(target string) (bool, error) { return fi.IsDir(), nil } -func ContainsExt(srcDir string, ext string) bool { +func ContainsExt(srcDir string, exts ...string) bool { if f, err := os.Open(srcDir); err == nil { defer f.Close() fis, _ := f.Readdir(-1) for _, fi := range fis { - if !fi.IsDir() && filepath.Ext(fi.Name()) == ext { - return true + if !fi.IsDir() { + ext := filepath.Ext(fi.Name()) + for _, v := range exts { + if v == ext { + return true + } + } } } } diff --git a/gopbuild/build.go b/gopbuild/build.go index 2ab299fd..6373c0a8 100644 --- a/gopbuild/build.go +++ b/gopbuild/build.go @@ -20,6 +20,7 @@ package gopbuild //go:generate go run ../cmd/qexp -outdir ../pkg github.com/goplus/gop/builtin/ng //go:generate go run ../cmd/qexp -outdir ../pkg github.com/goplus/gop/builtin/iox //go:generate go run ../cmd/qexp -outdir ../pkg github.com/qiniu/x/errors +//go:generate go run ../cmd/qexp -outdir ../pkg github.com/qiniu/x/gsh import ( "bytes" @@ -37,16 +38,23 @@ import ( "github.com/goplus/mod/modfile" _ "github.com/goplus/igop/pkg/bufio" + _ "github.com/goplus/igop/pkg/context" + _ "github.com/goplus/igop/pkg/errors" _ "github.com/goplus/igop/pkg/fmt" _ "github.com/goplus/igop/pkg/github.com/goplus/gop/builtin" _ "github.com/goplus/igop/pkg/github.com/goplus/gop/builtin/iox" _ "github.com/goplus/igop/pkg/github.com/goplus/gop/builtin/ng" _ "github.com/goplus/igop/pkg/github.com/qiniu/x/errors" + _ "github.com/goplus/igop/pkg/github.com/qiniu/x/gsh" _ "github.com/goplus/igop/pkg/io" _ "github.com/goplus/igop/pkg/log" + _ "github.com/goplus/igop/pkg/math" _ "github.com/goplus/igop/pkg/math/big" _ "github.com/goplus/igop/pkg/math/bits" _ "github.com/goplus/igop/pkg/os" + _ "github.com/goplus/igop/pkg/os/exec" + _ "github.com/goplus/igop/pkg/path/filepath" + _ "github.com/goplus/igop/pkg/runtime" _ "github.com/goplus/igop/pkg/strconv" _ "github.com/goplus/igop/pkg/strings" ) @@ -76,7 +84,9 @@ func init() { cl.SetDebug(cl.FlagNoMarkAutogen) igop.RegisterFileProcess(".gop", BuildFile) igop.RegisterFileProcess(".gox", BuildFile) + igop.RegisterFileProcess(".gsh", BuildFile) RegisterClassFileType(".gmx", "Game", []*Class{{Ext: ".spx", Class: "Sprite"}}, "github.com/goplus/spx", "math") + RegisterClassFileType(".gsh", "App", nil, "github.com/qiniu/x/gsh", "math") } func BuildFile(ctx *igop.Context, filename string, src interface{}) (data []byte, err error) { @@ -151,7 +161,7 @@ type Context struct { func ClassKind(fname string) (isProj, ok bool) { ext := modfile.ClassExt(fname) switch ext { - case ".gmx": + case ".gmx", ".gsh": return true, true case ".spx": return fname == "main.spx", true diff --git a/gopbuild/build_test.go b/gopbuild/build_test.go index 7a911b89..0c9575f9 100644 --- a/gopbuild/build_test.go +++ b/gopbuild/build_test.go @@ -384,3 +384,46 @@ func main() { } `) } + +func TestGsh(t *testing.T) { + gopClTestEx(t, "exec.gsh", ` +gop "run", "./foo" +exec "gop run ./foo" +exec "FOO=100 gop run ./foo" +exec {"FOO": "101"}, "gop", "run", "./foo" +exec "gop", "run", "./foo" +exec "ls $HOME" +ls "${HOME}" + +`, `package main + +import "github.com/qiniu/x/gsh" + +type exec struct { + gsh.App +} +//line exec.gsh:2 +func (this *exec) MainEntry() { +//line exec.gsh:2:1 + this.Gop_Exec("gop", "run", "./foo") +//line exec.gsh:3:1 + this.Exec__1("gop run ./foo") +//line exec.gsh:4:1 + this.Exec__1("FOO=100 gop run ./foo") +//line exec.gsh:5:1 + this.Exec__0(map[string]string{"FOO": "101"}, "gop", "run", "./foo") +//line exec.gsh:6:1 + this.Exec__2("gop", "run", "./foo") +//line exec.gsh:7:1 + this.Exec__1("ls $HOME") +//line exec.gsh:8:1 + this.Gop_Exec("ls", this.Gop_Env("HOME")) +} +func (this *exec) Main() { + gsh.Gopt_App_Main(this) +} +func main() { + new(exec).Main() +} +`) +}