From d5679c4c6e5940ffc8a406fd4a220f1fda55075b Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Thu, 23 Jul 2026 17:27:31 +0800 Subject: [PATCH 1/2] 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..b4ba397e --- /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{ + "XGot_CmpApp_Main": reflect.ValueOf(q.XGot_CmpApp_Main), + }, + TypedConsts: map[string]ixgo.TypedConst{}, + UntypedConsts: map[string]ixgo.UntypedConst{ + "XGoPackage": {"untyped bool", constant.MakeBool(bool(q.XGoPackage))}, + }, + }) +} diff --git a/internal/ixgo/pkgs.go b/internal/ixgo/pkgs.go index aa89f434..b0dabe0b 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 @@ -17,6 +18,7 @@ import ( _ "github.com/goplus/ixgo/pkg/net/rpc" _ "github.com/goplus/ixgo/pkg/net/rpc/jsonrpc" + _ "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() From c355e3a2b1f0a78711866945c4e8ba018183db43 Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Fri, 24 Jul 2026 14:43:33 +0800 Subject: [PATCH 2/2] test(llard): cover comparator formula loading --- testdata/kodo-e2e/formulas/pnggroup/libpng/Libpng_cmp.gox | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 testdata/kodo-e2e/formulas/pnggroup/libpng/Libpng_cmp.gox diff --git a/testdata/kodo-e2e/formulas/pnggroup/libpng/Libpng_cmp.gox b/testdata/kodo-e2e/formulas/pnggroup/libpng/Libpng_cmp.gox new file mode 100644 index 00000000..7a62727d --- /dev/null +++ b/testdata/kodo-e2e/formulas/pnggroup/libpng/Libpng_cmp.gox @@ -0,0 +1,5 @@ +compareVer (a, b) => { + // Prefer released versions over libpng's non-semver beta tags. For example, + // v1.6.58 is valid semver while v1.7.0beta89 is not. + return semver.compare(a.Version, b.Version) +}