Repository: goplus/gop
Pull request #1602 (2024-01-07 10:12:46)

gop.mod refector


Patch:
diff --git a/gendeps.go b/_gendeps.go
similarity index 98%
rename from gendeps.go
rename to _gendeps.go
index c02d461a..1c80fc29 100644
--- a/gendeps.go
+++ b/_gendeps.go
@@ -36,7 +36,7 @@ import (
 func GenDepMods(mod *gopmod.Module, dir string, recursively bool) (ret map[string]struct{}, err error) {
 	modBase := mod.Path()
 	ret = make(map[string]struct{})
-	for _, r := range mod.Import {
+	for _, r := range mod.Opt.Import {
 		ret[r.ClassfileMod] = struct{}{}
 	}
 	err = HandleDeps(mod, dir, recursively, func(pkgPath string) {
diff --git a/cmd/gopfmt/gopfmt.go b/cmd/gopfmt/gopfmt.go
index 500eb557..7cef6c6d 100644
--- a/cmd/gopfmt/gopfmt.go
+++ b/cmd/gopfmt/gopfmt.go
@@ -132,7 +132,7 @@ func (w *walker) walk(path string, d fs.DirEntry, err error) error {
 		dir, _ := filepath.Split(path)
 		fn, ok := w.dirMap[dir]
 		if !ok {
-			if mod, err := gop.LoadMod(path, nil, &gop.Config{DontUpdateGoMod: true}); err == nil {
+			if mod, err := gop.LoadMod(path); err == nil {
 				fn = func(ext string) (ok bool, class bool) {
 					switch ext {
 					case ".go", ".gop":
diff --git a/cmd/internal/env/env.go b/cmd/internal/env/env.go
index 43febb85..d5afc1f2 100644
--- a/cmd/internal/env/env.go
+++ b/cmd/internal/env/env.go
@@ -74,7 +74,7 @@ func runCmd(_ *base.Command, args []string) {
 	gopEnv["GOPROOT"] = env.GOPROOT()
 	gopEnv["GOP_GOCMD"] = gocmd.Name()
 	gopEnv["GOMODCACHE"] = modcache.GOMODCACHE
-	gopEnv["GOPMOD"], _ = mod.GOPMOD("", 0)
+	gopEnv["GOPMOD"], _ = mod.GOPMOD("")
 	gopEnv["HOME"] = env.HOME()
 
 	vars := flag.Args()
diff --git a/cmd/internal/gopfmt/fmt.go b/cmd/internal/gopfmt/fmt.go
index 40efc8a5..cab4619d 100644
--- a/cmd/internal/gopfmt/fmt.go
+++ b/cmd/internal/gopfmt/fmt.go
@@ -147,7 +147,7 @@ func (w *walker) walk(path string, d fs.DirEntry, err error) error {
 		dir, _ := filepath.Split(path)
 		fn, ok := w.dirMap[dir]
 		if !ok {
-			if mod, err := gop.LoadMod(path, nil, &gop.Config{DontUpdateGoMod: true}); err == nil {
+			if mod, err := gop.LoadMod(path); err == nil {
 				fn = func(ext string) (ok bool, class bool) {
 					switch ext {
 					case ".go", ".gop":
diff --git a/cmd/internal/gopget/get.go b/cmd/internal/gopget/get.go
index 1142f37f..e3a909cf 100644
--- a/cmd/internal/gopget/get.go
+++ b/cmd/internal/gopget/get.go
@@ -23,7 +23,6 @@ import (
 
 	"github.com/goplus/gop"
 	"github.com/goplus/gop/cmd/internal/base"
-	"github.com/goplus/gop/x/gopenv"
 	"github.com/goplus/mod/modcache"
 	"github.com/goplus/mod/modfetch"
 	"github.com/goplus/mod/modload"
@@ -62,11 +61,10 @@ func runCmd(cmd *base.Command, args []string) {
 
 func get(pkgPath string) {
 	modBase := ""
-	mod, err := modload.Load(".", 0)
+	mod, err := modload.Load(".")
 	noMod := gop.NotFound(err)
 	if !noMod {
 		check(err)
-		check(mod.UpdateGoMod(gopenv.Get(), true))
 		modBase = mod.Path()
 	}
 
@@ -79,18 +77,17 @@ func get(pkgPath string) {
 	pkgModRoot, err := modcache.Path(pkgModVer)
 	check(err)
 
-	pkgMod, err := modload.Load(pkgModRoot, 0)
+	pkgMod, err := modload.Load(pkgModRoot)
 	check(err)
-	if pkgMod.Project != nil {
-		mod.AddImport(pkgModVer.Path)
-		fmt.Fprintf(os.Stderr, "gop get: registered %s\n", pkgModVer.Path)
+	if pkgMod.HasProject() {
+		mod.Opt.AddImport(pkgModVer.Path)
+		fmt.Fprintf(os.Stderr, "gop get: import %s\n", pkgModVer.Path)
 	}
 
 	check(mod.AddRequire(pkgModVer.Path, pkgModVer.Version))
 	fmt.Fprintf(os.Stderr, "gop get: added %s %s\n", pkgModVer.Path, pkgModVer.Version)
 
 	check(mod.Save())
-	check(mod.UpdateGoMod(gopenv.Get(), false))
 }
 
 func check(err error) {
diff --git a/gengo.go b/gengo.go
index 57960606..4e0103f8 100644
--- a/gengo.go
+++ b/gengo.go
@@ -142,7 +142,7 @@ func genGoSingleFile(file string, conf *Config, flags GenFlags) (err error) {
 	if (flags & GenFlagPrompt) != 0 {
 		fmt.Fprintln(os.Stderr, "GenGo", file, "...")
 	}
-	out, err := LoadFiles([]string{file}, conf)
+	out, err := LoadFiles(".", []string{file}, conf)
 	if err != nil {
 		return errors.NewWith(err, `LoadFiles(files, conf)`, -2, "gop.LoadFiles", file)
 	}
@@ -226,7 +226,7 @@ func GenGoPkgPathEx(workDir, pkgPath string, conf *Config, allowExtern bool, fla
 		return remotePkgPath(pkgPath, conf, false, flags)
 	}
 
-	mod, err := gopmod.Load(workDir, 0)
+	mod, err := gopmod.Load(workDir)
 	if NotFound(err) && allowExtern {
 		return remotePkgPath(pkgPath, conf, recursively, flags)
 	} else if err != nil {
@@ -270,7 +270,7 @@ func GenGoFiles(autogen string, files []string, conf *Config) (result []string,
 			}
 		}
 	}
-	out, err := LoadFiles(files, conf)
+	out, err := LoadFiles(".", files, conf)
 	if err != nil {
 		err = errors.NewWith(err, `LoadFiles(files, conf)`, -2, "gop.LoadFiles", files, conf)
 		return
diff --git a/go.mod b/go.mod
index 8e12270d..c40d4154 100644
--- a/go.mod
+++ b/go.mod
@@ -4,9 +4,9 @@ go 1.18
 
 require (
 	github.com/fsnotify/fsnotify v1.7.0
-	github.com/goplus/c2go v0.7.17
-	github.com/goplus/gox v1.13.1-0.20231225053549-a6c41ff21756
-	github.com/goplus/mod v0.11.10-0.20231210062211-b9032d0f7810
+	github.com/goplus/c2go v0.7.19
+	github.com/goplus/gox v1.13.2
+	github.com/goplus/mod v0.12.0
 	github.com/qiniu/x v1.13.2
 	golang.org/x/tools v0.16.1
 )
@@ -16,7 +16,7 @@ require (
 	github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	golang.org/x/mod v0.14.0 // indirect
-	golang.org/x/sys v0.14.0 // indirect
+	golang.org/x/sys v0.15.0 // indirect
 )
 
 retract v1.1.12
diff --git a/go.sum b/go.sum
index ad407bef..17af2381 100644
--- a/go.sum
+++ b/go.sum
@@ -4,14 +4,12 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
 github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
 github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
-github.com/goplus/c2go v0.7.17 h1:q/b0Fv1ggJUo0E0ZN/3t8zoE9vmJYTDtAlNSzedeCAA=
-github.com/goplus/c2go v0.7.17/go.mod h1:HhlHE5OAwrJyjg3Dz6yj3b1drugJdoUiWeUl+G3NnU4=
-github.com/goplus/gox v1.13.0/go.mod h1:MOJnwqA8/rSUkn0vsayHFK7TD/3XQrdexMTqdzR70X0=
-github.com/goplus/gox v1.13.1-0.20231225053549-a6c41ff21756 h1:KkSgwZXFW5YbgCv++a0Bvzc+zKBR8SsSKo/9C1BkOjI=
-github.com/goplus/gox v1.13.1-0.20231225053549-a6c41ff21756/go.mod h1:iIchh0wp8Ye0DOPcFgHc5d0qlMOx8/OJ+DBQfe7hcTs=
-github.com/goplus/mod v0.11.9/go.mod h1:YxrBMhvWGcvLU14j8e7qyKSVnj5Loba7GgH1rNXJtDg=
-github.com/goplus/mod v0.11.10-0.20231210062211-b9032d0f7810 h1:d+1SoTwaKrHwMp2EZPzZxV8VnqVr+QxXQCtz/zn+Tow=
-github.com/goplus/mod v0.11.10-0.20231210062211-b9032d0f7810/go.mod h1:YxrBMhvWGcvLU14j8e7qyKSVnj5Loba7GgH1rNXJtDg=
+github.com/goplus/c2go v0.7.19 h1:pPMarGN1RiNJFAYlL8oZlM7VNXeg054B4czDgBlck0o=
+github.com/goplus/c2go v0.7.19/go.mod h1:EJgnt9CEHnXuWQc4y78w3DhKErL1aBzgE41NZaEa/3c=
+github.com/goplus/gox v1.13.2 h1:XZZtLcZasRVKOYNzTnJ9E2Cu350TWu9K+CYMJTItkis=
+github.com/goplus/gox v1.13.2/go.mod h1:iIchh0wp8Ye0DOPcFgHc5d0qlMOx8/OJ+DBQfe7hcTs=
+github.com/goplus/mod v0.12.0 h1:b1nPDFRPjksb/BXBUiIA1uVNHc3egRVfYSlShlq3nZE=
+github.com/goplus/mod v0.12.0/go.mod h1:ZtlS9wHOcAVxZ/zq7WLdKVes1HG/8Yn3KNuWZGcpeTs=
 github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
 github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
 github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
@@ -20,7 +18,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
 github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/qiniu/x v1.13.1/go.mod h1:INZ2TSWSJVWO/RuELQROERcslBwVgFG7MkTfEdaQz9E=
 github.com/qiniu/x v1.13.2 h1:mgWOfB9Rpk6AEtlBoObZVxH+b2FHSntYrxc4KX5Ta98=
 github.com/qiniu/x v1.13.2/go.mod h1:INZ2TSWSJVWO/RuELQROERcslBwVgFG7MkTfEdaQz9E=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -30,11 +27,10 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
-golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
+golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
 golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
 golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
-golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
 golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
 golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -43,13 +39,13 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
 golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
 golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
 golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
-golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
+golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
-golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
 golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
+golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -58,27 +54,26 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
-golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
+golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
 golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
 golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
-golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
+golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
 golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
 golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
+golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
 golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
 golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
-golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
 golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
 golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
diff --git a/load.go b/load.go
index 6e363ffc..58567d10 100644
--- a/load.go
+++ b/load.go
@@ -121,13 +121,11 @@ type Config struct {
 	Filter   func(fs.FileInfo) bool
 	Importer types.Importer
 
-	DontUpdateGoMod     bool
-	DontCheckModChanged bool
-	IgnoreNotatedError  bool
+	IgnoreNotatedError bool
 }
 
-func LoadMod(dir string, gop *env.Gop, conf *Config) (mod *gopmod.Module, err error) {
-	mod, err = gopmod.Load(dir, 0)
+func LoadMod(dir string) (mod *gopmod.Module, err error) {
+	mod, err = gopmod.Load(dir)
 	if err != nil && !NotFound(err) {
 		err = errors.NewWith(err, `gopmod.Load(dir, 0)`, -2, "gopmod.Load", dir, 0)
 		return
@@ -136,22 +134,20 @@ func LoadMod(dir string, gop *env.Gop, conf *Config) (mod *gopmod.Module, err er
 		err = mod.ImportClasses()
 		if err != nil {
 			err = errors.NewWith(err, `mod.RegisterClasses()`, -2, "(*gopmod.Module).RegisterClasses", mod)
-			return
-		}
-		if !conf.DontUpdateGoMod {
-			err = mod.UpdateGoMod(gop, !conf.DontCheckModChanged)
-			if err != nil {
-				err = errors.NewWith(err, `mod.UpdateGoMod(gop, !conf.DontCheckModChanged)`, -2, "(*gopmod.Module).UpdateGoMod", mod, gop, !conf.DontCheckModChanged)
-			}
 		}
 		return
 	}
-	return new(gopmod.Module), nil
+	return gopmod.Default, nil
 }
 
 // -----------------------------------------------------------------------------
 
 func LoadDir(dir string, conf *Config, genTestPkg bool, promptGenGo ...bool) (out, test *gox.Package, err error) {
+	mod, err := LoadMod(dir)
+	if err != nil {
+		return
+	}
+
 	if conf == nil {
 		conf = new(Config)
 	}
@@ -159,15 +155,6 @@ func LoadDir(dir string, conf *Config, genTestPkg bool, promptGenGo ...bool) (ou
 	if fset == nil {
 		fset = token.NewFileSet()
 	}
-	gop := conf.Gop
-	if gop == nil {
-		gop = gopenv.Get()
-	}
-	mod, err := LoadMod(dir, gop, conf)
-	if err != nil {
-		return
-	}
-
 	pkgs, err := parser.ParseDirEx(fset, dir, parser.Config{
 		ClassKind: mod.ClassKind,
 		Filter:    conf.Filter,
@@ -182,6 +169,10 @@ func LoadDir(dir string, conf *Config, genTestPkg bool, promptGenGo ...bool) (ou
 
 	imp := conf.Importer
 	if imp == nil {
+		gop := conf.Gop
+		if gop == nil {
+			gop = gopenv.Get()
+		}
 		imp = NewImporter(mod, gop, fset)
 	}
 
@@ -232,7 +223,13 @@ func LoadDir(dir string, conf *Config, genTestPkg bool, promptGenGo ...bool) (ou
 
 // -----------------------------------------------------------------------------
 
-func LoadFiles(files []string, conf *Config) (out *gox.Package, err error) {
+func LoadFiles(dir string, files []string, conf *Config) (out *gox.Package, err error) {
+	mod, err := LoadMod(dir)
+	if err != nil {
+		err = errors.NewWith(err, `LoadMod(dir)`, -2, "gop.LoadMod", dir)
+		return
+	}
+
 	if conf == nil {
 		conf = new(Config)
 	}
@@ -240,16 +237,6 @@ func LoadFiles(files []string, conf *Config) (out *gox.Package, err error) {
 	if fset == nil {
 		fset = token.NewFileSet()
 	}
-	gop := conf.Gop
-	if gop == nil {
-		gop = gopenv.Get()
-	}
-	mod, err := LoadMod("", gop, conf)
-	if err != nil {
-		err = errors.NewWith(err, `loadMod("", gop, conf)`, -2, "gop.loadMod", "", gop, conf)
-		return
-	}
-
 	pkgs, err := parser.ParseFiles(fset, files, parser.ParseComments)
 	if err != nil {
 		err = errors.NewWith(err, `parser.ParseFiles(fset, files, parser.ParseComments)`, -2, "parser.ParseFiles", fset, files, parser.ParseComments)
@@ -259,6 +246,10 @@ func LoadFiles(files []string, conf *Config) (out *gox.Package, err error) {
 		err = errors.NewWith(ErrMultiPackges, `len(pkgs) != 1`, -1, "!=", len(pkgs), 1)
 		return
 	}
+	gop := conf.Gop
+	if gop == nil {
+		gop = gopenv.Get()
+	}
 	for _, pkg := range pkgs {
 		imp := conf.Importer
 		if imp == nil {
diff --git a/outline.go b/outline.go
index 11c355cd..06334797 100644
--- a/outline.go
+++ b/outline.go
@@ -35,26 +35,17 @@ import (
 // -----------------------------------------------------------------------------
 
 func Outline(dir string, conf *Config) (out outline.Package, err error) {
-	if conf == nil {
-		conf = new(Config)
-	}
-	fset := conf.Fset
-	if fset == nil {
-		fset = token.NewFileSet()
-	}
-	gop := conf.Gop
-	if gop == nil {
-		gop = gopenv.Get()
-	}
-
 	if dir, err = filepath.Abs(dir); err != nil {
 		return
 	}
-	mod, err := LoadMod(dir, gop, conf)
+	mod, err := LoadMod(dir)
 	if err != nil {
 		return
 	}
 
+	if conf == nil {
+		conf = new(Config)
+	}
 	filterConf := conf.Filter
 	filter := func(fi fs.FileInfo) bool {
 		if filterConf != nil && !filterConf(fi) {
@@ -66,6 +57,10 @@ func Outline(dir string, conf *Config) (out outline.Package, err error) {
 		}
 		return !strings.HasSuffix(fname, "_test")
 	}
+	fset := conf.Fset
+	if fset == nil {
+		fset = token.NewFileSet()
+	}
 	pkgs, err := parser.ParseDirEx(fset, dir, parser.Config{
 		ClassKind: mod.ClassKind,
 		Filter:    filter,
@@ -81,6 +76,10 @@ func Outline(dir string, conf *Config) (out outline.Package, err error) {
 
 	imp := conf.Importer
 	if imp == nil {
+		gop := conf.Gop
+		if gop == nil {
+			gop = gopenv.Get()
+		}
 		imp = NewImporter(mod, gop, fset)
 	}
 
@@ -113,7 +112,7 @@ func Outline(dir string, conf *Config) (out outline.Package, err error) {
 // -----------------------------------------------------------------------------
 
 func OutlinePkgPath(workDir, pkgPath string, conf *Config, allowExtern bool) (out outline.Package, err error) {
-	mod, err := gopmod.Load(workDir, 0)
+	mod, err := gopmod.Load(workDir)
 	if NotFound(err) && allowExtern {
 		remotePkgPathDo(pkgPath, func(pkgDir, modDir string) {
 			modFile := chmodModfile(modDir)
diff --git a/tidy.go b/tidy.go
index e48787b4..1e2f2c11 100644
--- a/tidy.go
+++ b/tidy.go
@@ -20,58 +20,52 @@ import (
 	"os"
 	"os/exec"
 
-	"github.com/goplus/mod"
 	"github.com/goplus/mod/env"
 	"github.com/goplus/mod/gopmod"
-	"github.com/goplus/mod/modfetch"
 	"github.com/qiniu/x/errors"
 )
 
 func Tidy(dir string, gop *env.Gop) (err error) {
-	modObj, err := gopmod.Load(dir, mod.GopModOnly)
+	modObj, err := gopmod.Load(dir)
 	if err != nil {
-		return errors.NewWith(err, `gopmod.Load(dir, mod.GopModOnly)`, -2, "gopmod.Load", dir, mod.GopModOnly)
+		return errors.NewWith(err, `gopmod.Load(dir, mod.GopModOnly)`, -2, "gopmod.Load", dir)
 	}
 
 	modRoot := modObj.Root()
-	depMods, err := GenDepMods(modObj, modRoot, true)
-	if err != nil {
-		return errors.NewWith(err, `GenDepMods(modObj, modRoot, true)`, -2, "gop.GenDepMods", modObj, modRoot, true)
-	}
+	/*
+		depMods, err := GenDepMods(modObj, modRoot, true)
+		if err != nil {
+			return errors.NewWith(err, `GenDepMods(modObj, modRoot, true)`, -2, "gop.GenDepMods", modObj, modRoot, true)
+		}
 
-	old := modObj.DepMods()
-	for modPath := range old {
-		if _, ok := depMods[modPath]; !ok { // removed
-			modObj.DropRequire(modPath)
+		old := modObj.DepMods()
+		for modPath := range old {
+			if _, ok := depMods[modPath]; !ok { // removed
+				modObj.DropRequire(modPath)
+			}
 		}
-	}
-	for modPath := range depMods {
-		if _, ok := old[modPath]; !ok { // added
-			if newMod, e := modfetch.Get(modPath); e != nil {
-				return errors.NewWith(e, `modfetch.Get(modPath)`, -1, "modfetch.Get", modPath)
-			} else {
-				modObj.AddRequire(newMod.Path, newMod.Version)
+		for modPath := range depMods {
+			if _, ok := old[modPath]; !ok { // added
+				if newMod, e := modfetch.Get(modPath); e != nil {
+					return errors.NewWith(e, `modfetch.Get(modPath)`, -1, "modfetch.Get", modPath)
+				} else {
+					modObj.AddRequire(newMod.Path, newMod.Version)
+				}
 			}
 		}
-	}
 
-	modObj.Cleanup()
-	err = modObj.Save()
-	if err != nil {
-		return errors.NewWith(err, `modObj.Save()`, -2, "(*gopmod.Module).Save")
-	}
-
-	conf := &Config{DontUpdateGoMod: true, Gop: gop}
+		modObj.Cleanup()
+		err = modObj.Save()
+		if err != nil {
+			return errors.NewWith(err, `modObj.Save()`, -2, "(*gopmod.Module).Save")
+		}
+	*/
+	conf := &Config{Gop: gop}
 	err = genGoDir(modRoot, conf, true, true, 0)
 	if err != nil {
 		return errors.NewWith(err, `genGoDir(modRoot, conf, true, true)`, -2, "gop.genGoDir", modRoot, conf, true, true)
 	}
 
-	err = modObj.UpdateGoMod(gop, true)
-	if err != nil {
-		return errors.NewWith(err, `modObj.UpdateGoMod(gop, true)`, -2, "(*gopmod.Module).UpdateGoMod", gop, true)
-	}
-
 	cmd := exec.Command("go", "mod", "tidy")
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stderr
diff --git a/watcher/changes.go b/watcher/changes.go
index 7c6e5770..4edc270f 100644
--- a/watcher/changes.go
+++ b/watcher/changes.go
@@ -70,7 +70,7 @@ func (p *Changes) doLookupMod(name string) *module {
 	if !ok {
 		mod = new(module)
 		mod.exts = make([]string, 0, 8)
-		m, e := gopmod.Load(p.root+name, 0)
+		m, e := gopmod.Load(p.root + name)
 		if e == nil {
 			m.ImportClasses(func(c *gopmod.Project) {
 				mod.exts = append(mod.exts, c.Ext)


Test patch:
diff --git a/env/path_test.go b/env/path_test.go
index 834235b3..419cd6a9 100644
--- a/env/path_test.go
+++ b/env/path_test.go
@@ -25,7 +25,7 @@ import (
 )
 
 func findGoModFile(dir string) (modfile string, noCacheFile bool, err error) {
-	modfile, err = mod.GOPMOD(dir, 0)
+	modfile, err = mod.GOMOD(dir)
 	if err != nil {
 		gopRoot, err := findGopRoot()
 		if err == nil {