Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/thrift_option
Browse files Browse the repository at this point in the history
HeyJavaBean committed Mar 25, 2024
2 parents 9275188 + dc0b3fb commit af1ae78
Showing 100 changed files with 5,949 additions and 575 deletions.
39 changes: 29 additions & 10 deletions .github/workflows/push-check.yml
Original file line number Diff line number Diff line change
@@ -30,15 +30,34 @@ jobs:

- name: Lint
run: |
go install mvdan.cc/[email protected]
echo "install done!"
set -e
if [[ -n "$(gofumpt -l -extra .)" ]]; then
echo "gofumpt found formatting issues."
gofumpt -l -extra .
exit 1
fi
test -z "$(gofumpt -l -extra .)"
echo "test done!"
go vet -stdmethods=false $(go list ./...)
echo "go vet done!"
codegen-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.17'
- name: Prepare
run: |
go install
go install github.com/cloudwego/kitex/tool/cmd/kitex@develop
LOCAL_REPO=$(pwd)
cd ..
git clone https://github.com/cloudwego/kitex-tests.git
cd kitex-tests/codegen
go mod init codegen-test
go mod edit -replace=github.com/apache/thrift=github.com/apache/[email protected]
go mod edit -replace github.com/cloudwego/thriftgo=${LOCAL_REPO}
go mod edit -replace github.com/cloudwego/kitex=github.com/cloudwego/kitex@develop
go mod tidy
bash -version
bash ./codegen_install_check.sh
- name: CodeGen
run: |
cd ../kitex-tests/codegen
tree
bash ./codegen_run.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -7,3 +7,4 @@ gen-*
.vscode
.idea
tool/trimmer/trimmer_test
output
14 changes: 14 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2023 ByteDance Inc.
//
// 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.

36 changes: 35 additions & 1 deletion args.go
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ import (

"github.com/cloudwego/thriftgo/generator"
"github.com/cloudwego/thriftgo/generator/backend"
"github.com/cloudwego/thriftgo/generator/golang"
"github.com/cloudwego/thriftgo/plugin"
)

@@ -99,7 +100,12 @@ func (a *Arguments) Targets() (specs []*generator.LangSpec, err error) {
if err != nil {
return nil, err
}

opts, err := a.checkOptions(desc.Options)
if err != nil {
return nil, err
}
// checkOptions may modify the content of the options
desc.Options = opts
spec := &generator.LangSpec{
Language: desc.Name,
Options: desc.Options,
@@ -109,6 +115,33 @@ func (a *Arguments) Targets() (specs []*generator.LangSpec, err error) {
return
}

// checkOptions used to validate the command parameters.
func (a *Arguments) checkOptions(opts []plugin.Option) ([]plugin.Option, error) {
params := plugin.Pack(opts)
cu := golang.NewCodeUtils(backend.DummyLogFunc())
cu.HandleOptions(params)
if cu.Features().EnableNestedStruct {
// In nested mode, if template is not 'slim', it is automatically converted to slim
if cu.Template() != "slim" {
found := false
for _, opt := range opts {
if opt.Name == "template" {
log.Printf("[WARN] EnableNestedStruct is only available under the \"slim\" template, so adapt the template to \"slim\"")
opt.Desc = "slim"
found = true
break
}
}
if !found {
log.Printf("[WARN] EnableNestedStruct is only available under the \"slim\" template, so adapt the template to \"slim\"")
opts = append(opts, plugin.Option{Name: "template", Desc: "slim"})
}

}
}
return opts, nil
}

// MakeLogFunc creates logging functions according to command line flags.
func (a *Arguments) MakeLogFunc() backend.LogFunc {
logs := backend.DummyLogFunc()
@@ -207,6 +240,7 @@ Options:
Keys and values are options passed to the backend.
Many options will not require values. Boolean options accept
"false", "true" and "" (empty is treated as "true").
Example: thriftgo -g go:naming_style=golint,ignore_initialisms,gen_setter,gen_deep_equal example.thrift
-p, --plugin STR Specify an external plugin to invoke.
STR has the form plugin[=path][:key1=val1[,key2[,key3=val3]]].
--check-keywords Check if any identifier using a keyword in common languages.
14 changes: 14 additions & 0 deletions extension/thrift_option/create_instance.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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.

package thrift_option

import (
14 changes: 14 additions & 0 deletions extension/thrift_option/option.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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.

package thrift_option

import (
14 changes: 14 additions & 0 deletions extension/thrift_option/option_error.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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.

package thrift_option

import (
14 changes: 14 additions & 0 deletions extension/thrift_option/option_error_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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.

package thrift_option

import (
14 changes: 14 additions & 0 deletions extension/thrift_option/option_getter.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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.

package thrift_option

import (
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 option_gen.annotation.entity
include "entity_struct.thrift"

Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 option_gen.annotation.entity

struct InnerStruct{
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 option_gen.annotation.validation

struct _StructOptions {
14 changes: 14 additions & 0 deletions extension/thrift_option/option_idl/test.thrift
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 option_gen
include "annotations/entity/entity.thrift"
include "annotations/validation/validation.thrift"
14 changes: 14 additions & 0 deletions extension/thrift_option/option_idl/test_grammar_error.thrift
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 option_gen
include "annotations/entity/entity.thrift"

14 changes: 14 additions & 0 deletions extension/thrift_option/option_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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.

package thrift_option

import (

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

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

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

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

Loading

0 comments on commit af1ae78

Please sign in to comment.