From fd00ef814b1d1cef3f1035503e37a77ab4717d34 Mon Sep 17 00:00:00 2001 From: Peefy Date: Fri, 26 Jul 2024 21:39:44 +0800 Subject: [PATCH] fix: runtime init panic (#354) * fix: runtime init panic Signed-off-by: peefy * feat: set fast eval mode as default Signed-off-by: peefy --------- Signed-off-by: peefy --- .github/workflows/main_darwin.yml | 4 +- examples/plugin/main.go | 8 +- go.mod | 4 +- go.sum | 8 +- kclvm_test.go | 104 +++--------- pkg/kcl/api_test.go | 159 ++++++------------ pkg/kcl/{native_service.go => rpc_service.go} | 11 +- pkg/kcl/service.go | 11 +- pkg/kcl/testing_test.go | 11 -- pkg/kcl/utils.go | 15 -- pkg/native/api.go | 48 ------ pkg/native/api_test.go | 64 ------- pkg/plugin/api.go | 10 -- pkg/runtime/kclvm.go | 1 + pkg/spec/gpyrpc/gpyrpc.pb.go | 2 + 15 files changed, 102 insertions(+), 358 deletions(-) rename pkg/kcl/{native_service.go => rpc_service.go} (66%) delete mode 100644 pkg/kcl/utils.go delete mode 100644 pkg/native/api.go delete mode 100644 pkg/native/api_test.go diff --git a/.github/workflows/main_darwin.yml b/.github/workflows/main_darwin.yml index fe6434ef..2791bce3 100644 --- a/.github/workflows/main_darwin.yml +++ b/.github/workflows/main_darwin.yml @@ -7,9 +7,11 @@ on: - "releases/*" jobs: build-and-test: + # Ref: https://github.com/actions/runner-images/tree/main/images/macos + # Note: The arch of macos-13-xlarge and macos-14 is arm64 strategy: matrix: - os: [ macos-12, macos-13 ] + os: [ macos-12, macos-13, macos-13-xlarge, macos-14 ] runs-on: ${{ matrix.os }} steps: - name: Git checkout diff --git a/examples/plugin/main.go b/examples/plugin/main.go index 174035d4..af0bcd9d 100644 --- a/examples/plugin/main.go +++ b/examples/plugin/main.go @@ -1,16 +1,18 @@ +//go:build native +// +build native + package main import ( "fmt" - "kcl-lang.io/kcl-go/pkg/kcl" - "kcl-lang.io/kcl-go/pkg/native" // Import the native API + "kcl-lang.io/kcl-go/pkg/kcl" // Import the native API _ "kcl-lang.io/kcl-go/pkg/plugin/hello_plugin" // Import the hello plugin ) func main() { // Note we use `native.MustRun` here instead of `kcl.MustRun`, because it needs the cgo feature. - yaml := native.MustRun("main.k", kcl.WithCode(code)).GetRawYamlResult() + yaml := kcl.MustRun("main.k", kcl.WithCode(code)).GetRawYamlResult() fmt.Println(yaml) } diff --git a/go.mod b/go.mod index 2e9e7d47..1b91d065 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/chai2010/protorpc v1.1.4 github.com/getkin/kin-openapi v0.126.0 github.com/goccy/go-yaml v1.12.0 - github.com/gofrs/flock v0.12.0 + github.com/gofrs/flock v0.12.1 github.com/golang/protobuf v1.5.4 github.com/google/go-cmp v0.6.0 github.com/iancoleman/strcase v0.3.0 @@ -22,7 +22,7 @@ require ( google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 gopkg.in/yaml.v3 v3.0.1 - kcl-lang.io/kpm v0.9.2 + kcl-lang.io/kpm v0.9.3 kcl-lang.io/lib v0.10.0-alpha.1 ) diff --git a/go.sum b/go.sum index 7c110b3c..32fd96ca 100644 --- a/go.sum +++ b/go.sum @@ -372,8 +372,8 @@ github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/goccy/go-yaml v1.12.0 h1:/1WHjnMsI1dlIBQutrvSMGZRQufVO3asrHfTwfACoPM= github.com/goccy/go-yaml v1.12.0/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU= -github.com/gofrs/flock v0.12.0 h1:xHW8t8GPAiGtqz7KxiSqfOEXwpOaqhpYZrTE2MQBgXY= -github.com/gofrs/flock v0.12.0/go.mod h1:FirDy1Ing0mI2+kB6wk+vyyAH+e6xiE+EYA0jnzV9jc= +github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= +github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 h1:zN2lZNZRflqFyxVaTIU61KNKQ9C0055u9CAfpmqUvo4= github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3/go.mod h1:nPpo7qLxd6XL3hWJG/O60sR8ZKfMCiIoNap5GvD12KU= @@ -1287,8 +1287,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9 honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 h1:kmDqav+P+/5e1i9tFfHq1qcF3sOrDp+YEkVDAHu7Jwk= 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/kpm v0.9.3 h1:lwFSrJTRyAzjygT5Oo/98DxCCiDZmujo46PcmRx54Ck= +kcl-lang.io/kpm v0.9.3/go.mod h1:4HTbPhB4DVtkamnIv5lrRcHtCVwzp4Pf/b+d3TN4nzs= 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= diff --git a/kclvm_test.go b/kclvm_test.go index 5fb6a5ea..beb5d96d 100644 --- a/kclvm_test.go +++ b/kclvm_test.go @@ -312,17 +312,11 @@ func TestGetSchemaType(t *testing.T) { 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{}, + Type: "str", + Line: 1, }, }, - Required: []string{"name"}, - UnionTypes: []*gpyrpc.KclType{}, + Required: []string{"name"}, Decorators: []*gpyrpc.Decorator{ { Name: "info", @@ -332,7 +326,6 @@ func TestGetSchemaType(t *testing.T) { }, }, }, - Examples: map[string]*gpyrpc.Example{}, }, }, result) p, err := filepath.Abs("./testdata/main.k") @@ -351,30 +344,17 @@ func TestGetSchemaType(t *testing.T) { SchemaName: "Person", Properties: map[string]*gpyrpc.KclType{ "name": { - Type: "str", - Line: 1, - Default: "\"kcl\"", - Properties: map[string]*gpyrpc.KclType{}, - Required: []string{}, - UnionTypes: []*gpyrpc.KclType{}, - Decorators: []*gpyrpc.Decorator{}, - Examples: map[string]*gpyrpc.Example{}, + Type: "str", + Line: 1, + Default: "\"kcl\"", }, "age": { - Type: "int", - Line: 2, - Default: "1", - Properties: map[string]*gpyrpc.KclType{}, - Required: []string{}, - UnionTypes: []*gpyrpc.KclType{}, - Decorators: []*gpyrpc.Decorator{}, - Examples: map[string]*gpyrpc.Example{}, + Type: "int", + Line: 2, + Default: "1", }, }, - Required: []string{"name", "age"}, - UnionTypes: []*gpyrpc.KclType{}, - Decorators: []*gpyrpc.Decorator{}, - Examples: map[string]*gpyrpc.Example{}, + Required: []string{"name", "age"}, }, }, result) } @@ -391,19 +371,11 @@ func TestGetSchemaTypeMapping(t *testing.T) { 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{}, + Type: "str", + Line: 1, }, }, - Required: []string{"name"}, - UnionTypes: []*gpyrpc.KclType{}, - Decorators: []*gpyrpc.Decorator{}, - Examples: map[string]*gpyrpc.Example{}, + Required: []string{"name"}, } assert2.Equal(t, map[string]*gpyrpc.KclType{ "Person": &personSchema, @@ -415,28 +387,15 @@ func TestGetSchemaTypeMapping(t *testing.T) { BaseSchema: &personSchema, 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{}, + Type: "str", + Line: 1, }, "count": { - Type: "int", - Line: 2, - Properties: map[string]*gpyrpc.KclType{}, - Required: []string{}, - UnionTypes: []*gpyrpc.KclType{}, - Decorators: []*gpyrpc.Decorator{}, - Examples: map[string]*gpyrpc.Example{}, + Type: "int", + Line: 2, }, }, - Required: []string{"count", "name"}, - UnionTypes: []*gpyrpc.KclType{}, - Decorators: []*gpyrpc.Decorator{}, - Examples: map[string]*gpyrpc.Example{}, + Required: []string{"count", "name"}, }, }, result) @@ -456,30 +415,17 @@ func TestGetSchemaTypeMapping(t *testing.T) { SchemaName: "Person", Properties: map[string]*gpyrpc.KclType{ "name": { - Type: "str", - Line: 1, - Default: "\"kcl\"", - Properties: map[string]*gpyrpc.KclType{}, - Required: []string{}, - UnionTypes: []*gpyrpc.KclType{}, - Decorators: []*gpyrpc.Decorator{}, - Examples: map[string]*gpyrpc.Example{}, + Type: "str", + Line: 1, + Default: "\"kcl\"", }, "age": { - Type: "int", - Line: 2, - Default: "1", - Properties: map[string]*gpyrpc.KclType{}, - Required: []string{}, - UnionTypes: []*gpyrpc.KclType{}, - Decorators: []*gpyrpc.Decorator{}, - Examples: map[string]*gpyrpc.Example{}, + Type: "int", + Line: 2, + Default: "1", }, }, - Required: []string{"name", "age"}, - UnionTypes: []*gpyrpc.KclType{}, - Decorators: []*gpyrpc.Decorator{}, - Examples: map[string]*gpyrpc.Example{}, + Required: []string{"name", "age"}, }, }, result) } diff --git a/pkg/kcl/api_test.go b/pkg/kcl/api_test.go index 03d59a30..574190bf 100644 --- a/pkg/kcl/api_test.go +++ b/pkg/kcl/api_test.go @@ -1,130 +1,69 @@ -// Copyright The KCL Authors. All rights reserved. +//go:build native +// +build native package kcl import ( "fmt" - "path/filepath" - "reflect" - "sort" "testing" - "github.com/stretchr/testify/assert" - "kcl-lang.io/kcl-go/pkg/tools/list" -) - -var _ = fmt.Sprint - -const case_path = "../../testdata/main.k" + assert2 "github.com/stretchr/testify/assert" -func TestKCLResultMap(t *testing.T) { - var data = map[string]interface{}{ - "key1": "value1", - "key2": "value2", - } - result := NewResult(data) - m, _ := result.ToMap() - tAssert(t, m["key1"] == "value1", m) - tAssert(t, m["key2"] == "value2", m) -} + "kcl-lang.io/kcl-go/pkg/plugin" + _ "kcl-lang.io/kcl-go/pkg/plugin/hello_plugin" +) -func TestKCLResultInt(t *testing.T) { - result := NewResult(1) - m, _ := result.ToInt() - tAssert(t, *m == 1) -} +const code = ` +import kcl_plugin.hello -func TestRun(t *testing.T) { - const k_code = ` name = "kcl" -i = 123 -f = 1.5 +sum = hello.add(option("a"), option("b")) ` +const codeWithPlugin = ` +import kcl_plugin.my_plugin - result, err := RunFiles([]string{case_path}, WithCode(k_code)) - tAssert(t, err == nil, err) - tAssert(t, result != nil) - - opts := WithCode(k_code) - opts.Merge(WithKFilenames(case_path)) - result, err = RunWithOpts(opts) - tAssert(t, result != nil) - tAssert(t, err == nil, err) - - result, err = Run(case_path, WithCode(k_code)) - tAssert(t, err == nil, err) - tAssert(t, result.Len() > 0) - tAssert(t, result.First().Get("name") == "kcl") - - var s string - var i int - var f float64 - - _, err = result.Get(0).GetValue("name", &s) - tAssert(t, err == nil, err) - tAssert(t, s == "kcl", s) - - _, err = result.Get(0).GetValue("i", &i) - tAssert(t, err == nil, err) - tAssert(t, i == 123, i) - - _, err = result.Get(0).GetValue("f", &f) - tAssert(t, err == nil, err) - tAssert(t, f == 1.5, f) - - _, err = result.Tail().GetValue("name", &s) - tAssert(t, err == nil, err) - tAssert(t, s == "kcl", s) - - result.First().YAMLString() - result.Tail().JSONString() -} - -// go test -run=TestRun_failed -func TestRun_failed(t *testing.T) { - _, err := Run(case_path, WithCode(`x = {`)) - tAssert(t, err != nil, err) -} - -func TestGetSchemaType(t *testing.T) { - const k_code = `a=1` +value1 = my_plugin.config_append({key1 = "value1"}, "key2", "value2") +value2 = my_plugin.list_append([1, 2, 3], 4) +` - result, err := GetSchemaType("main.k", k_code, "") - tAssert(t, err == nil) - _ = result +func TestNativeRun(t *testing.T) { + yaml := MustRun("main.k", WithCode(code), WithOptions("a=1", "b=2")).GetRawYamlResult() + fmt.Println(yaml) } -func TestListUpstreamFiles(t *testing.T) { - deps, err := list.ListUpStreamFiles("./testdata/complicate", &list.DepOptions{Files: []string{"appops/projectA/base/base.k", "appops/projectA/dev/main.k", "base/render/server/server_render.k"}}) - if err != nil { - t.Fatal(err) - } - - expect := []string{ - "base/frontend/server/server.k", - "base/frontend/container/container.k", - "base/frontend/container/container_port.k", - "base/frontend/server", - "base/frontend/container", - } - - sort.Strings(deps) - sort.Strings(expect) +func ExampleNativeRunPaths() { + yaml := MustRunPaths([]string{"testdata/1.k", "testdata/2.k"}).GetRawYamlResult() + fmt.Println(yaml) - if !reflect.DeepEqual(deps, expect) { - t.Fatalf("\nexpect = %v\ngot = %v", expect, deps) - } + // output: + // a: b + // c: d } -func TestGetFullSchemaType(t *testing.T) { - testPath := filepath.Join(".", "testdata", "get_schema_ty") - tys, err := GetFullSchemaType( - []string{filepath.Join(testPath, "aaa")}, - "", - WithExternalPkgs(fmt.Sprintf("bbb=%s", filepath.Join(testPath, "bbb"))), - ) - assert.Equal(t, err, nil) - assert.Equal(t, len(tys), 1) - assert.Equal(t, tys[0].Filename, filepath.Join("testdata", "get_schema_ty", "bbb", "main.k")) - assert.Equal(t, tys[0].SchemaName, "B") +func TestNativeRunWithPlugin(t *testing.T) { + plugin.RegisterPlugin(plugin.Plugin{ + Name: "my_plugin", + MethodMap: map[string]plugin.MethodSpec{ + "config_append": { + Body: func(args *plugin.MethodArgs) (*plugin.MethodResult, error) { + config := args.MapArg(0) + k := args.StrArg(1) + v := args.StrArg(2) + config[k] = v + return &plugin.MethodResult{V: config}, nil + }, + }, + "list_append": { + Body: func(args *plugin.MethodArgs) (*plugin.MethodResult, error) { + values := args.ListArg(0) + v := args.Arg(1) + values = append(values, v) + return &plugin.MethodResult{V: values}, nil + }, + }, + }, + }) + + yaml := MustRun("main.k", WithCode(codeWithPlugin)).GetRawYamlResult() + assert2.Equal(t, yaml, "value1:\n key1: value1\n key2: value2\nvalue2:\n- 1\n- 2\n- 3\n- 4") } diff --git a/pkg/kcl/native_service.go b/pkg/kcl/rpc_service.go similarity index 66% rename from pkg/kcl/native_service.go rename to pkg/kcl/rpc_service.go index 8d8c1337..5eaafab4 100644 --- a/pkg/kcl/native_service.go +++ b/pkg/kcl/rpc_service.go @@ -1,16 +1,13 @@ -//go:build native -// +build native +//go:build rpc +// +build rpc package kcl -import ( - "kcl-lang.io/kcl-go/pkg/native" - "kcl-lang.io/kcl-go/pkg/service" -) +import "kcl-lang.io/kcl-go/pkg/service" // Service returns the interaction interface between KCL Go SDK and KCL Rust core. // When `go build tags=native` is opened, use CGO and dynamic libraries to interact. // When closed, use the default RPC interaction logic to avoid CGO usage. func Service() service.KclvmService { - return native.NewNativeServiceClient() + return service.NewKclvmServiceClient() } diff --git a/pkg/kcl/service.go b/pkg/kcl/service.go index a430492a..bf0f00e2 100644 --- a/pkg/kcl/service.go +++ b/pkg/kcl/service.go @@ -1,13 +1,16 @@ -//go:build !native -// +build !native +//go:build !rpc +// +build !rpc package kcl -import "kcl-lang.io/kcl-go/pkg/service" +import ( + "kcl-lang.io/kcl-go/pkg/native" + "kcl-lang.io/kcl-go/pkg/service" +) // Service returns the interaction interface between KCL Go SDK and KCL Rust core. // When `go build tags=native` is opened, use CGO and dynamic libraries to interact. // When closed, use the default RPC interaction logic to avoid CGO usage. func Service() service.KclvmService { - return service.NewKclvmServiceClient() + return native.NewNativeServiceClient() } diff --git a/pkg/kcl/testing_test.go b/pkg/kcl/testing_test.go index 65f88297..06c076c8 100644 --- a/pkg/kcl/testing_test.go +++ b/pkg/kcl/testing_test.go @@ -17,14 +17,3 @@ func tAssert(tb testing.TB, condition bool, args ...interface{}) { } } } - -func tAssertf(tb testing.TB, condition bool, format string, a ...interface{}) { - if !condition { - tb.Helper() - if msg := fmt.Sprintf(format, a...); msg != "" { - tb.Fatalf("tAssert failed, %s", msg) - } else { - tb.Fatalf("tAssert failed") - } - } -} diff --git a/pkg/kcl/utils.go b/pkg/kcl/utils.go deleted file mode 100644 index ea173331..00000000 --- a/pkg/kcl/utils.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright The KCL Authors. All rights reserved. - -package kcl - -import ( - "os" -) - -func isDir(path string) bool { - fileInfo, err := os.Stat(path) - if err != nil { - return false - } - return fileInfo.IsDir() -} diff --git a/pkg/native/api.go b/pkg/native/api.go deleted file mode 100644 index 6f358399..00000000 --- a/pkg/native/api.go +++ /dev/null @@ -1,48 +0,0 @@ -//go:build cgo -// +build cgo - -package native - -import ( - "kcl-lang.io/kcl-go/pkg/kcl" -) - -func MustRun(path string, opts ...kcl.Option) *kcl.KCLResultList { - v, err := Run(path, opts...) - if err != nil { - panic(err) - } - - return v -} - -func Run(path string, opts ...kcl.Option) (*kcl.KCLResultList, error) { - return run([]string{path}, opts...) -} - -func MustRunPaths(paths []string, opts ...kcl.Option) *kcl.KCLResultList { - v, err := RunPaths(paths, opts...) - if err != nil { - panic(err) - } - - return v -} - -func RunPaths(paths []string, opts ...kcl.Option) (*kcl.KCLResultList, error) { - return run(paths, opts...) -} - -func run(pathList []string, opts ...kcl.Option) (*kcl.KCLResultList, error) { - args, err := kcl.ParseArgs(pathList, opts...) - if err != nil { - return nil, err - } - - client := NewNativeServiceClient() - resp, err := client.ExecProgram(args.ExecProgram_Args) - if err != nil { - return nil, err - } - return kcl.ExecResultToKCLResult(&args, resp, args.GetLogger(), kcl.DefaultHooks) -} diff --git a/pkg/native/api_test.go b/pkg/native/api_test.go deleted file mode 100644 index aaa7d423..00000000 --- a/pkg/native/api_test.go +++ /dev/null @@ -1,64 +0,0 @@ -//go:build cgo -// +build cgo - -package native - -import ( - "fmt" - "testing" - - assert2 "github.com/stretchr/testify/assert" - - "kcl-lang.io/kcl-go/pkg/kcl" - "kcl-lang.io/kcl-go/pkg/plugin" - _ "kcl-lang.io/kcl-go/pkg/plugin/hello_plugin" -) - -const codeWithPlugin = ` -import kcl_plugin.my_plugin - -value1 = my_plugin.config_append({key1 = "value1"}, "key2", "value2") -value2 = my_plugin.list_append([1, 2, 3], 4) -` - -func TestNativeRun(t *testing.T) { - yaml := MustRun("main.k", kcl.WithCode(code), kcl.WithOptions("a=1", "b=2")).GetRawYamlResult() - fmt.Println(yaml) -} - -func ExampleNativeRunPaths() { - yaml := MustRunPaths([]string{"testdata/1.k", "testdata/2.k"}).GetRawYamlResult() - fmt.Println(yaml) - - // output: - // a: b - // c: d -} - -func TestNativeRunWithPlugin(t *testing.T) { - plugin.RegisterPlugin(plugin.Plugin{ - Name: "my_plugin", - MethodMap: map[string]plugin.MethodSpec{ - "config_append": { - Body: func(args *plugin.MethodArgs) (*plugin.MethodResult, error) { - config := args.MapArg(0) - k := args.StrArg(1) - v := args.StrArg(2) - config[k] = v - return &plugin.MethodResult{V: config}, nil - }, - }, - "list_append": { - Body: func(args *plugin.MethodArgs) (*plugin.MethodResult, error) { - values := args.ListArg(0) - v := args.Arg(1) - values = append(values, v) - return &plugin.MethodResult{V: values}, nil - }, - }, - }, - }) - - yaml := MustRun("main.k", kcl.WithCode(codeWithPlugin)).GetRawYamlResult() - assert2.Equal(t, yaml, "value1:\n key1: value1\n key2: value2\nvalue2:\n- 1\n- 2\n- 3\n- 4") -} diff --git a/pkg/plugin/api.go b/pkg/plugin/api.go index e401420d..32078f9d 100644 --- a/pkg/plugin/api.go +++ b/pkg/plugin/api.go @@ -3,20 +3,10 @@ package plugin import ( - "os" "strings" "sync" ) -// Debug flag for kcl-plugin -var DebugMode = false - -func init() { - if s := strings.ToLower(os.Getenv("KCLVM_PLUGIN_DEBUG")); s != "" && s != "false" && s != "0" { - DebugMode = true - } -} - var pluginManager struct { allPlugin map[string]Plugin allMethodSpec map[string]MethodSpec diff --git a/pkg/runtime/kclvm.go b/pkg/runtime/kclvm.go index b0c1094d..bb2adc40 100644 --- a/pkg/runtime/kclvm.go +++ b/pkg/runtime/kclvm.go @@ -20,6 +20,7 @@ import ( ) func init() { + env.EnableFastEvalMode() if !env.GetDisableInstallArtifact() { installKclArtifact() } diff --git a/pkg/spec/gpyrpc/gpyrpc.pb.go b/pkg/spec/gpyrpc/gpyrpc.pb.go index 91dd497d..24d8efaa 100644 --- a/pkg/spec/gpyrpc/gpyrpc.pb.go +++ b/pkg/spec/gpyrpc/gpyrpc.pb.go @@ -7917,10 +7917,12 @@ func (*UnimplementedKclvmServiceServer) ListVariables(context.Context, *ListVari func (*UnimplementedKclvmServiceServer) ExecProgram(context.Context, *ExecProgram_Args) (*ExecProgram_Result, error) { return nil, status.Errorf(codes.Unimplemented, "method ExecProgram not implemented") } + // Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0. func (*UnimplementedKclvmServiceServer) BuildProgram(context.Context, *BuildProgram_Args) (*BuildProgram_Result, error) { return nil, status.Errorf(codes.Unimplemented, "method BuildProgram not implemented") } + // Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0. func (*UnimplementedKclvmServiceServer) ExecArtifact(context.Context, *ExecArtifact_Args) (*ExecProgram_Result, error) { return nil, status.Errorf(codes.Unimplemented, "method ExecArtifact not implemented")