Repository: goplus/gop
Pull request #1728 (2024-02-12 06:33:38)

gop build/install/test/run: use share importer


Patch:
diff --git a/cmd/internal/build/build.go b/cmd/internal/build/build.go
index 82aaf6b9..fdee3a44 100644
--- a/cmd/internal/build/build.go
+++ b/cmd/internal/build/build.go
@@ -28,7 +28,6 @@ import (
 	"github.com/goplus/gop/cl"
 	"github.com/goplus/gop/cmd/internal/base"
 	"github.com/goplus/gop/x/gocmd"
-	"github.com/goplus/gop/x/gopenv"
 	"github.com/goplus/gop/x/gopprojs"
 	"github.com/goplus/gox"
 )
@@ -75,9 +74,11 @@ func runCmd(cmd *base.Command, args []string) {
 		log.Panicln("too many arguments:", args)
 	}
 
-	gopEnv := gopenv.Get()
-	conf := &gop.Config{Gop: gopEnv}
-	confCmd := &gocmd.BuildConfig{Gop: gopEnv}
+	conf, err := gop.NewDefaultConf(".")
+	if err != nil {
+		log.Panicln("gop.NewDefaultConf:", err)
+	}
+	confCmd := &gocmd.BuildConfig{Gop: conf.Gop}
 	if *flagOutput != "" {
 		output, err := filepath.Abs(*flagOutput)
 		if err != nil {
diff --git a/cmd/internal/install/install.go b/cmd/internal/install/install.go
index f5d52f48..f7962a7b 100644
--- a/cmd/internal/install/install.go
+++ b/cmd/internal/install/install.go
@@ -27,7 +27,6 @@ import (
 	"github.com/goplus/gop/cl"
 	"github.com/goplus/gop/cmd/internal/base"
 	"github.com/goplus/gop/x/gocmd"
-	"github.com/goplus/gop/x/gopenv"
 	"github.com/goplus/gop/x/gopprojs"
 	"github.com/goplus/gox"
 	"github.com/goplus/mod/modfetch"
@@ -72,9 +71,11 @@ func runCmd(cmd *base.Command, args []string) {
 		cl.SetDisableRecover(true)
 	}
 
-	gopEnv := gopenv.Get()
-	conf := &gop.Config{Gop: gopEnv}
-	confCmd := &gocmd.Config{Gop: gopEnv}
+	conf, err := gop.NewDefaultConf(".")
+	if err != nil {
+		log.Panicln("gop.NewDefaultConf:", err)
+	}
+	confCmd := &gocmd.Config{Gop: conf.Gop}
 	confCmd.Flags = pass.Args
 	for _, proj := range projs {
 		install(proj, conf, confCmd)
diff --git a/cmd/internal/run/run.go b/cmd/internal/run/run.go
index 525ae141..e2a8b004 100644
--- a/cmd/internal/run/run.go
+++ b/cmd/internal/run/run.go
@@ -26,7 +26,6 @@ import (
 	"github.com/goplus/gop/cl"
 	"github.com/goplus/gop/cmd/internal/base"
 	"github.com/goplus/gop/x/gocmd"
-	"github.com/goplus/gop/x/gopenv"
 	"github.com/goplus/gop/x/gopprojs"
 	"github.com/goplus/gox"
 	"github.com/qiniu/x/log"
@@ -81,9 +80,11 @@ func runCmd(cmd *base.Command, args []string) {
 	}
 
 	noChdir := *flagNoChdir
-	gopEnv := gopenv.Get()
-	conf := &gop.Config{Gop: gopEnv}
-	confCmd := &gocmd.Config{Gop: gopEnv}
+	conf, err := gop.NewDefaultConf(".")
+	if err != nil {
+		log.Panicln("gop.NewDefaultConf:", err)
+	}
+	confCmd := &gocmd.Config{Gop: conf.Gop}
 	confCmd.Flags = pass.Args
 	run(proj, args, !noChdir, conf, confCmd)
 }
diff --git a/gengo.go b/gengo.go
index 17732fb8..29becfdb 100644
--- a/gengo.go
+++ b/gengo.go
@@ -83,7 +83,7 @@ func genGoDir(dir string, conf *Config, genTestPkg, recursively bool, flags GenF
 		} else {
 			fn = func(path string, d fs.DirEntry, err error) error {
 				if err == nil && d.IsDir() {
-					if strings.HasPrefix(d.Name(), "_") || hasMod(path) { // skip _
+					if strings.HasPrefix(d.Name(), "_") || (path != dir && hasMod(path)) { // skip _
 						return filepath.SkipDir
 					}
 					if e := genGoIn(path, conf, genTestPkg, flags); e != nil && notIgnNotated(e, conf) {


Test patch:
diff --git a/cmd/internal/test/test.go b/cmd/internal/test/test.go
index 65655165..a9d119ae 100644
--- a/cmd/internal/test/test.go
+++ b/cmd/internal/test/test.go
@@ -27,7 +27,6 @@ import (
 	"github.com/goplus/gop/cl"
 	"github.com/goplus/gop/cmd/internal/base"
 	"github.com/goplus/gop/x/gocmd"
-	"github.com/goplus/gop/x/gopenv"
 	"github.com/goplus/gop/x/gopprojs"
 	"github.com/goplus/gox"
 )
@@ -70,9 +69,11 @@ func runCmd(cmd *base.Command, args []string) {
 		cl.SetDisableRecover(true)
 	}
 
-	gopEnv := gopenv.Get()
-	conf := &gop.Config{Gop: gopEnv}
-	confCmd := &gocmd.Config{Gop: gopEnv}
+	conf, err := gop.NewDefaultConf(".")
+	if err != nil {
+		log.Panicln("gop.NewDefaultConf:", err)
+	}
+	confCmd := &gocmd.Config{Gop: conf.Gop}
 	confCmd.Flags = pass.Args
 	for _, proj := range projs {
 		test(proj, conf, confCmd)