Skip to content

Commit

Permalink
cl.NewPackage: allow conf.Importer = nil
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed May 19, 2022
1 parent 6e19d00 commit 8eeda5d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
12 changes: 9 additions & 3 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/goplus/gop/ast/fromgo"
"github.com/goplus/gop/token"
"github.com/goplus/gox"
"github.com/goplus/gox/packages"
"github.com/goplus/mod/modfile"
)

Expand Down Expand Up @@ -372,12 +373,17 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
if targetDir == "" {
targetDir = workingDir
}
fset := conf.Fset
imp := conf.Importer
if imp == nil {
imp = packages.NewImporter(fset, workingDir)
}
files := pkg.Files
interp := &nodeInterp{fset: conf.Fset, files: files, workingDir: workingDir}
interp := &nodeInterp{fset: fset, files: files, workingDir: workingDir}
ctx := &pkgCtx{syms: make(map[string]loader), nodeInterp: interp}
confGox := &gox.Config{
Fset: conf.Fset,
Importer: newGopImporter(conf.GopRoot, conf.Importer),
Fset: fset,
Importer: newGopImporter(conf.GopRoot, imp),
LoadNamed: ctx.loadNamed,
HandleErr: ctx.handleErr,
NodeInterpreter: interp,
Expand Down
1 change: 1 addition & 0 deletions cl/compile_spx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ func (this *Kai) onMsg(msg string) {

func TestSpxMainEntry(t *testing.T) {
conf := *gblConf
conf.Importer = nil
conf.NoAutoGenMain = false

gopSpxTestExConf(t, "Nocode", &conf, `
Expand Down
7 changes: 1 addition & 6 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/goplus/gop/parser"
"github.com/goplus/gop/x/gopenv"
"github.com/goplus/gox"
"github.com/goplus/gox/packages"
"github.com/goplus/mod/env"
"github.com/goplus/mod/gopmod"
)
Expand Down Expand Up @@ -58,10 +57,6 @@ func LoadDir(dir string, conf *Config) (out, test *gox.Package, err error) {
if gop == nil {
gop = gopenv.Get()
}
imp := conf.Importer
if imp == nil {
imp = packages.NewImporter(fset, dir)
}

mod, err := gopmod.Load(dir, gop)
if err != nil && err != syscall.ENOENT {
Expand Down Expand Up @@ -96,7 +91,7 @@ func LoadDir(dir string, conf *Config) (out, test *gox.Package, err error) {
WorkingDir: dir,
GopRoot: gop.Root,
Fset: fset,
Importer: imp,
Importer: conf.Importer,
LookupClass: mod.LookupClass,
}
for name, pkg := range pkgs {
Expand Down

0 comments on commit 8eeda5d

Please sign in to comment.