diff --git a/go.mod b/go.mod index 3ada53b8..a5e4043f 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( google.golang.org/protobuf v1.34.2 gopkg.in/yaml.v3 v3.0.1 kcl-lang.io/kpm v0.9.2 - kcl-lang.io/lib v0.9.3 + kcl-lang.io/lib v0.10.0-alpha.1 ) require ( diff --git a/go.sum b/go.sum index 97d623f6..ed939a0a 100644 --- a/go.sum +++ b/go.sum @@ -1289,8 +1289,8 @@ k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 h1:kmDqav+P+/5e1i9tFfHq1qcF3sOrD k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= kcl-lang.io/kpm v0.9.2 h1:TNQLFWEYj9MEFZXpHGhp4/PHAv3eBogOjpYDyMIFZsU= kcl-lang.io/kpm v0.9.2/go.mod h1:4HTbPhB4DVtkamnIv5lrRcHtCVwzp4Pf/b+d3TN4nzs= -kcl-lang.io/lib v0.9.3 h1:Mlr+H0oaxujUQi6QD6eP+Fbi1waVsRWXddIzQhddK+Y= -kcl-lang.io/lib v0.9.3/go.mod h1:tu+tzwGgHLzYZSIxUG/ntipStrxZd6OvutWYPTxS7cs= +kcl-lang.io/lib v0.10.0-alpha.1 h1:GMVB75Pc1W29gcl1WlVgdgUscH6h+d9No0fzBH0rNYg= +kcl-lang.io/lib v0.10.0-alpha.1/go.mod h1:tu+tzwGgHLzYZSIxUG/ntipStrxZd6OvutWYPTxS7cs= oras.land/oras-go v1.2.5 h1:XpYuAwAb0DfQsunIyMfeET92emK8km3W4yEzZvUbsTo= oras.land/oras-go v1.2.5/go.mod h1:PuAwRShRZCsZb7g8Ar3jKKQR/2A/qN+pkYxIOd/FAoo= oras.land/oras-go/v2 v2.5.0 h1:o8Me9kLY74Vp5uw07QXPiitjsw7qNXi8Twd+19Zf02c= diff --git a/kclvm_test.go b/kclvm_test.go index 85414932..5fb6a5ea 100644 --- a/kclvm_test.go +++ b/kclvm_test.go @@ -380,16 +380,39 @@ func TestGetSchemaType(t *testing.T) { } func TestGetSchemaTypeMapping(t *testing.T) { - result, err := kcl.GetSchemaTypeMapping("test.k", "schema Person:\n name: str", "") + result, err := kcl.GetSchemaTypeMapping("test.k", "schema Person:\n name: str\n\nschema Sub(Person):\n count: int\n", "") if err != nil { t.Fatal(err) } + personSchema := gpyrpc.KclType{ + Filename: "test.k", + PkgPath: "__main__", + Type: "schema", + SchemaName: "Person", + Properties: map[string]*gpyrpc.KclType{ + "name": { + Type: "str", + Line: 1, + Properties: map[string]*gpyrpc.KclType{}, + Required: []string{}, + UnionTypes: []*gpyrpc.KclType{}, + Decorators: []*gpyrpc.Decorator{}, + Examples: map[string]*gpyrpc.Example{}, + }, + }, + Required: []string{"name"}, + UnionTypes: []*gpyrpc.KclType{}, + Decorators: []*gpyrpc.Decorator{}, + Examples: map[string]*gpyrpc.Example{}, + } assert2.Equal(t, map[string]*gpyrpc.KclType{ - "Person": { + "Person": &personSchema, + "Sub": { Filename: "test.k", PkgPath: "__main__", Type: "schema", - SchemaName: "Person", + SchemaName: "Sub", + BaseSchema: &personSchema, Properties: map[string]*gpyrpc.KclType{ "name": { Type: "str", @@ -400,8 +423,17 @@ func TestGetSchemaTypeMapping(t *testing.T) { Decorators: []*gpyrpc.Decorator{}, Examples: map[string]*gpyrpc.Example{}, }, + "count": { + Type: "int", + Line: 2, + Properties: map[string]*gpyrpc.KclType{}, + Required: []string{}, + UnionTypes: []*gpyrpc.KclType{}, + Decorators: []*gpyrpc.Decorator{}, + Examples: map[string]*gpyrpc.Example{}, + }, }, - Required: []string{"name"}, + Required: []string{"count", "name"}, UnionTypes: []*gpyrpc.KclType{}, Decorators: []*gpyrpc.Decorator{}, Examples: map[string]*gpyrpc.Example{}, diff --git a/pkg/native/cgo.go b/pkg/native/cgo.go index b7d8d63d..2bf5a915 100644 --- a/pkg/native/cgo.go +++ b/pkg/native/cgo.go @@ -23,7 +23,7 @@ void kclvm_service_free_string(void *f,const char * res) { free_string = (void (*)(const char *))f; return free_string(res); } -const char* kclvm_service_call_with_length(void *f,kclvm_service* c,const char * method,const char * args,size_t * result_len){ +const char* kclvm_service_call_with_length(void *f,kclvm_service* c,const char * method,const char * args,size_t args_len,size_t * result_len){ const char* (*service_call_with_length)(kclvm_service*,const char *,const char *,size_t *); service_call_with_length = (const char* (*)(kclvm_service*,const char *,const char *,size_t *))f; return service_call_with_length(c,method,args,result_len); @@ -75,7 +75,7 @@ func KclvmServiceFreeString(str *C.char) { // KclvmServiceCall calls kclvm service by c api // args should be serialized as protobuf byte stream -func KclvmServiceCall(serv *C.kclvm_service, method *C.char, args *C.char) (*C.char, C.size_t) { +func KclvmServiceCall(serv *C.kclvm_service, method *C.char, args *C.char, args_len C.size_t) (*C.char, C.size_t) { const fnName = "kclvm_service_call_with_length" serviceCall, err := lib.GetSymbolPointer(fnName) @@ -85,6 +85,6 @@ func KclvmServiceCall(serv *C.kclvm_service, method *C.char, args *C.char) (*C.c } var size C.size_t = C.SIZE_MAX - buf := C.kclvm_service_call_with_length(serviceCall, serv, method, args, &size) + buf := C.kclvm_service_call_with_length(serviceCall, serv, method, args, args_len, &size) return buf, size } diff --git a/pkg/native/client.go b/pkg/native/client.go index 3e09c1d8..e43ce255 100644 --- a/pkg/native/client.go +++ b/pkg/native/client.go @@ -85,7 +85,7 @@ func cApiCall[I interface { defer C.free(unsafe.Pointer(cIn)) - cOut, cOutSize := KclvmServiceCall(c.client, cCallName, cIn) + cOut, cOutSize := KclvmServiceCall(c.client, cCallName, cIn, C.size_t(len(inBytes))) defer KclvmServiceFreeString(cOut) diff --git a/pkg/runtime/kclvm.go b/pkg/runtime/kclvm.go index b9cfbc06..b0c1094d 100644 --- a/pkg/runtime/kclvm.go +++ b/pkg/runtime/kclvm.go @@ -16,7 +16,7 @@ import ( "kcl-lang.io/kcl-go/pkg/env" "kcl-lang.io/kcl-go/pkg/logger" "kcl-lang.io/kcl-go/pkg/path" - "kcl-lang.io/lib" + "kcl-lang.io/lib/go/install" ) func init() { @@ -46,7 +46,7 @@ func installKclArtifact() { logger.GetLogger().Warningf("install kclvm failed: %s", err.Error()) } // Install lib - err = lib.InstallKclvm(path) + err = install.InstallKclvm(path) if err != nil { logger.GetLogger().Warningf("install kclvm failed: %s", err.Error()) }