From 57474710ff641b89bdcfe1dd52a0402e475d7fe6 Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Thu, 23 Jul 2026 17:27:31 +0800 Subject: [PATCH] fix(ixgo): export comparator classfile package --- .../pkg/github.com/goplus/llar/cmp/export.go | 35 +++++++++++++++++++ internal/ixgo/pkgs.go | 2 ++ internal/modules/comparator_test.go | 19 ++++++++++ 3 files changed, 56 insertions(+) create mode 100644 internal/ixgo/pkg/github.com/goplus/llar/cmp/export.go diff --git a/internal/ixgo/pkg/github.com/goplus/llar/cmp/export.go b/internal/ixgo/pkg/github.com/goplus/llar/cmp/export.go new file mode 100644 index 00000000..542bc60d --- /dev/null +++ b/internal/ixgo/pkg/github.com/goplus/llar/cmp/export.go @@ -0,0 +1,35 @@ +// export by github.com/goplus/ixgo/cmd/qexp + +package cmp + +import ( + q "github.com/goplus/llar/cmp" + + "go/constant" + "reflect" + + "github.com/goplus/ixgo" +) + +func init() { + ixgo.RegisterPackage(&ixgo.Package{ + Name: "cmp", + Path: "github.com/goplus/llar/cmp", + Deps: map[string]string{ + "github.com/goplus/llar/mod/module": "module", + }, + Interfaces: map[string]reflect.Type{}, + NamedTypes: map[string]reflect.Type{ + "CmpApp": reflect.TypeOf((*q.CmpApp)(nil)).Elem(), + }, + AliasTypes: map[string]reflect.Type{}, + Vars: map[string]reflect.Value{}, + Funcs: map[string]reflect.Value{ + "Gopt_CmpApp_Main": reflect.ValueOf(q.Gopt_CmpApp_Main), + }, + TypedConsts: map[string]ixgo.TypedConst{}, + UntypedConsts: map[string]ixgo.UntypedConst{ + "GopPackage": {"untyped bool", constant.MakeBool(bool(q.GopPackage))}, + }, + }) +} diff --git a/internal/ixgo/pkgs.go b/internal/ixgo/pkgs.go index d7d8040a..09590db7 100644 --- a/internal/ixgo/pkgs.go +++ b/internal/ixgo/pkgs.go @@ -5,6 +5,7 @@ package ixgo //go:generate qexp -outdir pkg github.com/goplus/llar/formula +//go:generate qexp -outdir pkg github.com/goplus/llar/cmp //go:generate qexp -outdir pkg github.com/goplus/llar/mod/versions //go:generate qexp -outdir pkg golang.org/x/mod/semver //go:generate qexp -outdir pkg github.com/goplus/llar/x/gnu @@ -178,6 +179,7 @@ import ( // _ "github.com/goplus/ixgo/pkg/testing/iotest" // _ "github.com/goplus/ixgo/pkg/testing/quick" // _ "github.com/goplus/ixgo/pkg/testing/slogtest" + _ "github.com/goplus/llar/internal/ixgo/pkg/github.com/goplus/llar/cmp" _ "github.com/goplus/llar/internal/ixgo/pkg/github.com/goplus/llar/formula" _ "github.com/goplus/llar/internal/ixgo/pkg/github.com/goplus/llar/mod/module" _ "github.com/goplus/llar/internal/ixgo/pkg/github.com/goplus/llar/mod/versions" diff --git a/internal/modules/comparator_test.go b/internal/modules/comparator_test.go index d3eb1d5d..dd1ba018 100644 --- a/internal/modules/comparator_test.go +++ b/internal/modules/comparator_test.go @@ -3,6 +3,7 @@ package modules import ( "io/fs" "os" + "path/filepath" "reflect" "testing" @@ -149,6 +150,24 @@ func TestLoadComparator_Fake(t *testing.T) { } } +func TestLoadComparator_OutsideModule(t *testing.T) { + formulaDir, err := filepath.Abs("testdata/DaveGamble/cJSON") + if err != nil { + t.Fatal(err) + } + + // Formula repositories do not contain go.mod. For example, llarhub stores + // CJSON_cmp.gox beside versions.json, so loading it must not invoke go list. + t.Chdir(t.TempDir()) + comp, err := loadComparatorFS(os.DirFS(formulaDir).(fs.ReadFileFS), "CJSON_cmp.gox") + if err != nil { + t.Fatalf("loadComparatorFS outside a module: %v", err) + } + if got := comp(module.Version{Version: "v1.0.0"}, module.Version{Version: "v2.0.0"}); got >= 0 { + t.Fatalf("comparison = %d, want a negative value", got) + } +} + func TestLoadComparator_InvalidFileExtension(t *testing.T) { // Create a temp file with wrong extension tempDir := t.TempDir()