Skip to content

Commit

Permalink
chore: deprecated the BuildProgram and ExecArtifact functions
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Jul 24, 2024
1 parent fb28233 commit 0c9702d
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 68 deletions.
6 changes: 3 additions & 3 deletions pkg/native/cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ void kclvm_service_free_string(void *f,const char * res) {
return free_string(res);
}
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);
const char* (*service_call_with_length)(kclvm_service*,const char *,const char *,size_t,size_t *);
service_call_with_length = (const char* (*)(kclvm_service*,const char *,const char *,size_t,size_t *))f;
return service_call_with_length(c,method,args,args_len,result_len);
}
*/
import "C"
Expand Down
4 changes: 4 additions & 0 deletions pkg/native/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"kcl-lang.io/kcl-go/pkg/3rdparty/dlopen"
"kcl-lang.io/kcl-go/pkg/env"
"kcl-lang.io/kcl-go/pkg/plugin"
"kcl-lang.io/kcl-go/pkg/service"
"kcl-lang.io/kcl-go/pkg/spec/gpyrpc"
Expand Down Expand Up @@ -117,10 +118,13 @@ func (c *NativeServiceClient) ExecProgram(in *gpyrpc.ExecProgram_Args) (*gpyrpc.
return cApiCall[*gpyrpc.ExecProgram_Args, *gpyrpc.ExecProgram_Result](c, "KclvmService.ExecProgram", in)
}

// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0.
func (c *NativeServiceClient) BuildProgram(in *gpyrpc.BuildProgram_Args) (*gpyrpc.BuildProgram_Result, error) {
env.EnableFastEvalMode()
return cApiCall[*gpyrpc.BuildProgram_Args, *gpyrpc.BuildProgram_Result](c, "KclvmService.BuildProgram", in)
}

// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0.
func (c *NativeServiceClient) ExecArtifact(in *gpyrpc.ExecArtifact_Args) (*gpyrpc.ExecProgram_Result, error) {
return cApiCall[*gpyrpc.ExecArtifact_Args, *gpyrpc.ExecProgram_Result](c, "KclvmService.ExecArtifact", in)
}
Expand Down
65 changes: 0 additions & 65 deletions pkg/native/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package native
import (
"fmt"
"io"
"path"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -60,70 +59,6 @@ func TestExecProgramWithPluginError(t *testing.T) {
}
}

func TestExecArtifactWithPlugin(t *testing.T) {
output := path.Join(t.TempDir(), "example")
client := NewNativeServiceClient()
// BuildProgram
buildResult, err := client.BuildProgram(&gpyrpc.BuildProgram_Args{
ExecArgs: &gpyrpc.ExecProgram_Args{
KFilenameList: []string{"main.k"},
KCodeList: []string{code},
},
Output: output,
})
if err != nil {
t.Fatal(err)
}
// ExecArtifact
execResult, err := client.ExecArtifact(&gpyrpc.ExecArtifact_Args{
ExecArgs: &gpyrpc.ExecProgram_Args{
Args: []*gpyrpc.Argument{
{
Name: "a",
Value: "1",
},
{
Name: "b",
Value: "2",
},
},
},
Path: buildResult.Path,
})
if err != nil {
t.Fatal(err)
}
if execResult.ErrMessage != "" {
t.Fatal("error message must be empty")
}
}

func TestBuildProgramError(t *testing.T) {
src := `
a = 1
b = 2
`
output := path.Join(t.TempDir(), "example")
client := NewNativeServiceClient()
// BuildProgram
buildResult, err := client.BuildProgram(&gpyrpc.BuildProgram_Args{
ExecArgs: &gpyrpc.ExecProgram_Args{
KFilenameList: []string{"main.k"},
KCodeList: []string{src},
},
Output: output,
})
if err == nil {
t.Errorf("The BuildProgram should return compilation failure reason")
}
if !strings.Contains(err.Error(), "InvalidSyntax") {
t.Errorf("Unexpected error message: %q", err.Error())
}
if buildResult != nil {
t.Errorf("The BuildProgram should return nil if compilation fails")
}
}

func TestParseFile(t *testing.T) {
// Example: Test with string source
src := `schema Name:
Expand Down
2 changes: 2 additions & 0 deletions pkg/service/client_kclvm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (p *KclvmServiceClient) ExecProgram(args *gpyrpc.ExecProgram_Args) (resp *g
return
}

// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0.
func (p *KclvmServiceClient) BuildProgram(args *gpyrpc.BuildProgram_Args) (resp *gpyrpc.BuildProgram_Result, err error) {
p.Runtime.DoTask(func(c *rpc.Client, stderr io.Reader) {
resp, err = p.getClient(c).BuildProgram(args)
Expand All @@ -68,6 +69,7 @@ func (p *KclvmServiceClient) BuildProgram(args *gpyrpc.BuildProgram_Args) (resp
return
}

// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0.
func (p *KclvmServiceClient) ExecArtifact(args *gpyrpc.ExecArtifact_Args) (resp *gpyrpc.ExecProgram_Result, err error) {
p.Runtime.DoTask(func(c *rpc.Client, stderr io.Reader) {
resp, err = p.getClient(c).ExecArtifact(args)
Expand Down
4 changes: 4 additions & 0 deletions pkg/service/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ func (p *_KclvmServiceImpl) Ping(ctx context.Context, args *gpyrpc.Ping_Args) (*
func (p *_KclvmServiceImpl) ExecProgram(ctx context.Context, args *gpyrpc.ExecProgram_Args) (*gpyrpc.ExecProgram_Result, error) {
return p.c.ExecProgram(args)
}

// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0.
func (p *_KclvmServiceImpl) BuildProgram(ctx context.Context, args *gpyrpc.BuildProgram_Args) (*gpyrpc.BuildProgram_Result, error) {
return p.c.BuildProgram(args)
}

// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0.
func (p *_KclvmServiceImpl) ExecArtifact(ctx context.Context, args *gpyrpc.ExecArtifact_Args) (*gpyrpc.ExecProgram_Result, error) {
return p.c.ExecArtifact(args)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/service/kclvm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import "kcl-lang.io/kcl-go/pkg/spec/gpyrpc"
type KclvmService interface {
Ping(in *gpyrpc.Ping_Args) (out *gpyrpc.Ping_Result, err error)
ExecProgram(in *gpyrpc.ExecProgram_Args) (out *gpyrpc.ExecProgram_Result, err error)
// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0.
BuildProgram(in *gpyrpc.BuildProgram_Args) (out *gpyrpc.BuildProgram_Result, err error)
// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0.
ExecArtifact(in *gpyrpc.ExecArtifact_Args) (out *gpyrpc.ExecProgram_Result, err error)
ParseFile(in *gpyrpc.ParseFile_Args) (out *gpyrpc.ParseFile_Result, err error)
ParseProgram(in *gpyrpc.ParseProgram_Args) (out *gpyrpc.ParseProgram_Result, err error)
Expand Down
2 changes: 2 additions & 0 deletions pkg/service/rest_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,15 @@ func (p *restServer) handle_ExecProgram(w http.ResponseWriter, r *http.Request,
})
}

// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0.
func (p *restServer) handle_BuildProgram(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var args = new(gpyrpc.BuildProgram_Args)
p.handle(w, r, args, func() (proto.Message, error) {
return p.c.BuildProgram(args)
})
}

// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0.
func (p *restServer) handle_ExecArtifact(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var args = new(gpyrpc.ExecArtifact_Args)
p.handle(w, r, args, func() (proto.Message, error) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/spec/gpyrpc/gpyrpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/spec/gpyrpc/gpyrpc.pb.protorpc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/spec/gpyrpc/gpyrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ service KclvmService {
/// "id": 1
/// }
/// ```
// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0.
rpc BuildProgram(BuildProgram_Args) returns (BuildProgram_Result);

/// Execute the KCL artifact with args. **Note that it is not thread safe.**
Expand Down Expand Up @@ -430,6 +431,7 @@ service KclvmService {
/// "id": 1
/// }
/// ```
// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.11.0.
rpc ExecArtifact(ExecArtifact_Args) returns (ExecProgram_Result);

/// Override KCL file with args.
Expand Down

0 comments on commit 0c9702d

Please sign in to comment.