Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gop.mod refector #1602

Merged
merged 4 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gendeps.go → _gendeps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/gopfmt/gopfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/gopfmt/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
13 changes: 5 additions & 8 deletions cmd/internal/gopget/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
}

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion env/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions gengo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
31 changes: 13 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand All @@ -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=
57 changes: 24 additions & 33 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -136,38 +134,27 @@ 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)
}
fset := conf.Fset
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,
Expand All @@ -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)
}

Expand Down Expand Up @@ -232,24 +223,20 @@ 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)
}
fset := conf.Fset
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)
Expand All @@ -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 {
Expand Down
Loading