Skip to content

Commit

Permalink
Merge pull request #277 from visualfc/fixpatch
Browse files Browse the repository at this point in the history
fix path@patch not use
  • Loading branch information
visualfc authored Aug 28, 2024
2 parents 77ce770 + cb3ef8a commit 400ff58
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
4 changes: 4 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ func (ctx *Context) buildPackage(sp *SourcePackage) (pkg *ssa.Package, err error
}
var addin []*types.Package
for _, pkg := range ctx.Loader.Packages() {
path := pkg.Path()
if _, ok := ctx.pkgs[path]; ok && strings.HasSuffix(path, "@patch") {
continue
}
if !pkg.Complete() {
addin = append(addin, pkg)
}
Expand Down
56 changes: 43 additions & 13 deletions gopbuild/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ func gopClTest(t *testing.T, gopcode, expected string) {
}

func gopClTestEx(t *testing.T, filename string, gopcode, expected string) {
ctx := igop.NewContext(0)
gopClTestWith(t, igop.NewContext(0), filename, gopcode, expected)
}

func gopClTestWith(t *testing.T, ctx *igop.Context, filename string, gopcode, expected string) {
data, err := BuildFile(ctx, filename, gopcode)
if err != nil {
t.Fatalf("build gop error: %v", err)
Expand Down Expand Up @@ -428,9 +431,8 @@ func main() {
`)
}

func TestPackagePatch(t *testing.T) {
ctx := igop.NewContext(0)
RegisterPackagePatch(ctx, "github.com/qiniu/x/gsh", `package gsh
var patch_data = `package gsh
import "github.com/qiniu/x/gsh"
type Point struct {
Expand All @@ -454,15 +456,21 @@ func Gopt_App_Gopx_GetWidget[T any](app any, name string) {
var _ gsh.App
println(app, name)
}
`)
src := `
`

func TestPackagePatch(t *testing.T) {
ctx := igop.NewContext(0)
err := RegisterPackagePatch(ctx, "github.com/qiniu/x/gsh", patch_data)
if err != nil {
t.Fatal(err)
}
gopClTestWith(t, ctx, "main.gsh", `
getWidget(int,"info")
pt := &Point{100,200}
pt.Info()
println(pt.X)
dump(pt)
`
expected := `package main
`, `package main
import (
"fmt"
Expand Down Expand Up @@ -492,12 +500,34 @@ func (this *App) Main() {
func main() {
new(App).Main()
}
`
data, err := BuildFile(ctx, "main.gsh", src)
`)
}

func TestPackagePatchNoUse(t *testing.T) {
ctx := igop.NewContext(0)
err := RegisterPackagePatch(ctx, "github.com/qiniu/x/gsh", patch_data)
if err != nil {
t.Fatal(err)
}
if string(data) != expected {
t.Fatal("build error:\n", string(data))
}
gopClTestWith(t, ctx, "main.gsh", `
ls "${HOME}"
`, `package main
import "github.com/qiniu/x/gsh"
type App struct {
gsh.App
}
//line main.gsh:2
func (this *App) MainEntry() {
//line main.gsh:2:1
this.Gop_Exec("ls", this.Gop_Env("HOME"))
}
func (this *App) Main() {
gsh.Gopt_App_Main(this)
}
func main() {
new(App).Main()
}
`)
}

0 comments on commit 400ff58

Please sign in to comment.