Skip to content

Commit

Permalink
Merge pull request #239 from goplus/gop
Browse files Browse the repository at this point in the history
fix no main pkg build
  • Loading branch information
visualfc authored Apr 24, 2023
2 parents 1f7205e + 4e56b34 commit 96f77c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func (ctx *Context) LoadFile(filename string, src interface{}) (*ssa.Package, er
}
root, _ := filepath.Split(filename)
ctx.setRoot(root)
return ctx.LoadAstFile("main", file)
return ctx.LoadAstFile(file.Name.Name, file)
}

func (ctx *Context) ParseFile(filename string, src interface{}) (*ast.File, error) {
Expand Down
11 changes: 8 additions & 3 deletions gopbuild/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,15 @@ func (c *Context) ParseFile(filename string, src interface{}) (*Package, error)
func (c *Context) loadPackage(srcDir string, pkgs map[string]*ast.Package) (*Package, error) {
mainPkg, ok := pkgs["main"]
if !ok {
return nil, fmt.Errorf("not a main package")
for _, v := range pkgs {
mainPkg = v
break
}
}
if f, err := igop.ParseBuiltin(c.fset, "main"); err == nil {
mainPkg.GoFiles = map[string]*goast.File{"_igop_builtin.go": f}
if c.ctx.Mode&igop.DisableCustomBuiltin == 0 {
if f, err := igop.ParseBuiltin(c.fset, mainPkg.Name); err == nil {
mainPkg.GoFiles = map[string]*goast.File{"_igop_builtin.go": f}
}
}
conf := &cl.Config{
WorkingDir: srcDir, TargetDir: srcDir, Fset: c.fset}
Expand Down

0 comments on commit 96f77c5

Please sign in to comment.