Skip to content

Commit

Permalink
feat: support trimming multiple IDLs
Browse files Browse the repository at this point in the history
  • Loading branch information
DMwangnima committed Sep 24, 2024
1 parent 2bac1d3 commit 8b944ee
Show file tree
Hide file tree
Showing 28 changed files with 1,208 additions and 146 deletions.
5 changes: 4 additions & 1 deletion generator/golang/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func (g *GoBackend) Generate(req *plugin.Request, log backend.LogFunc) *plugin.R
g.prepareUtilities()
if g.utils.Features().TrimIDL {
g.log.Warn("You Are Using IDL Trimmer")
tr, err := trim.TrimAST(&trim.TrimASTArg{Ast: req.AST, TrimMethods: nil, Preserve: nil})
tr, err := trim.TrimASTWithCompose(&trim.TrimASTWithComposeArg{
TargetAST: req.AST,
ReadCfgFromLocal: true,
})
if err != nil {
g.log.Warn("trim error:", err.Error())
}
Expand Down
2 changes: 2 additions & 0 deletions tool/trimmer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func main() {
os.Exit(0)
}

// trimmer compose

var preserveInput *bool
if a.Preserve != "" {
preserve, err := strconv.ParseBool(a.Preserve)
Expand Down
25 changes: 25 additions & 0 deletions tool/trimmer/test_cases/config/idl_compose/idl_compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 CloudWeGo Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

idls:
test1.thrift:
trimmer:
methods:
- "TestService.func1"
- "TestService.func3"
preserve: true
preserved_structs:
- "useless"
match_go_name: true
test2.thrift:
21 changes: 21 additions & 0 deletions tool/trimmer/test_cases/config/trim_config/trim_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 CloudWeGo Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

methods:
- "TestService.func1"
- "TestService.func3"
preserve: true
preserved_structs:
- "useless"
match_go_name: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 CloudWeGo Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

idls:
test1.thrift:
trimmer:
methods:
- "TestService.func1"
- "TestService.func3"
preserve: true
preserved_structs:
- "useless"
match_go_name: true
test2.thrift:
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 CloudWeGo Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

methods:
- "TestService.func1"
- "TestService.func3"
preserve: true
preserved_structs:
- "useless"
match_go_name: true
35 changes: 35 additions & 0 deletions tool/trimmer/test_cases/multiple_idls/common1.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2024 CloudWeGo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace go tests.multiple.common

enum Common1Enum1 {
ONE
TWO
THREE
}

enum Common1Enum2 {
ONE
TWO
THERR
}

struct Common1Struct1 {
1: required string field
}

struct Common1Struct2 {
1: required string field
}
35 changes: 35 additions & 0 deletions tool/trimmer/test_cases/multiple_idls/common2.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2024 CloudWeGo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace go tests.multiple.common

enum Common2Enum1 {
ONE
TWO
THREE
}

enum Common2Enum2 {
ONE
TWO
THERR
}

struct Common2Struct1 {
1: required string field
}

struct Common2Struct2 {
1: required string field
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 CloudWeGo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace go multiple.include.common

include "../common1.thrift"

struct Test1Struct1 {
1: required common1.Common1Enum1 enumField
2: required common1.Common1Struct1 structField
}

service Test1 {
string Process(1: Test1Struct1 req)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 CloudWeGo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace go multiple.include.common

include "../common1.thrift"

struct Test2Struct1 {
1: required common1.Common1Enum2 enumField
2: required common1.Common1Struct2 structField
}

service Test2 {
string Process(1: Test2Struct1 req)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 CloudWeGo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace go multiple.include.common

include "../common1.thrift"
include "../common2.thrift"

struct Test3Struct1 {
1: required common1.Common1Enum1 enumField1
2: required common1.Common1Struct1 structField1
3: required common2.Common2Enum1 enumField2
4: required common2.Common2Struct1 structField2
}

service Test3 {
string Process(1: Test3Struct1 req)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 CloudWeGo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace go multiple.include.common

include "../common1.thrift"
include "../common2.thrift"

struct Test4Struct1 {
1: required common1.Common1Enum2 enumField1
2: required common1.Common1Struct2 structField1
3: required common2.Common2Enum2 enumField2
4: required common2.Common2Struct2 structField2
}

service Test4 {
string Process(1: Test4Struct1 req)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2024 CloudWeGo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace go multiple.include.common

include "../common1.thrift"
include "../common2.thrift"

struct Test5Struct1 {
1: required common1.Common1Enum1 enumField1
2: required common1.Common1Struct1 structField1
3: required common2.Common2Enum1 enumField2
4: required common2.Common2Struct1 structField2
}

struct Test5Struct2 {
1: required string stringField
}

service Test5 {
string Process(1: Test5Struct1 req)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 CloudWeGo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace go multiple.include.common

include "../common1.thrift"
include "../common2.thrift"
include "test5.thrift"

struct Test6Struct1 {
1: required common1.Common1Enum2 enumField1
2: required common1.Common1Struct2 structField1
3: required common2.Common2Enum2 enumField2
4: required common2.Common2Struct2 structField2
}

service Test6 {
string Process(1: Test6Struct1 req)
string ProcessAnotherIDL(1: test5.Test5Struct2 req)
}
Loading

0 comments on commit 8b944ee

Please sign in to comment.