Skip to content

Commit

Permalink
chore: release v0.6.3 (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzekin committed May 5, 2023
2 parents b398b27 + a1b0e5c commit f7b5e2f
Show file tree
Hide file tree
Showing 35 changed files with 684 additions and 378 deletions.
11 changes: 8 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ The description of the title will be attached in Release Notes,
so please describe it from user-oriented, what this PR does / why we need it.
Please check your PR title with the below requirements:
-->
- [ ] This PR title match the format: \<type\>(optional scope): \<description\>
- [ ] This PR title match the format: `<type>(optional scope): <description>`.
- [ ] The description of this PR title is user-oriented and clear enough for others to understand.

- [ ] Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. [User docs repo](https://github.com/cloudwego/cloudwego.github.io).

#### (Optional) Translate the PR title into Chinese.

Expand All @@ -35,8 +35,13 @@ Provide more detailed info for review. If it is a perf type PR, perf data is sug
en:
zh(optional):

#### Which issue(s) this PR fixes:
#### (Optional) Which issue(s) this PR fixes:
<!--
Automatically closes linked issue when PR is merged.
Eg: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->

#### (Optional) The PR that updates user documentation:
<!--
If the current PR requires user awareness at the usage level, please submit a PR to update user docs. [User docs repo](https://github.com/cloudwego/cloudwego.github.io)
-->
21 changes: 10 additions & 11 deletions cmd/hz/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,16 @@ func Client(c *cli.Context) error {
}

func PluginMode() {
pluginName := filepath.Base(os.Args[0])
if util.IsWindows() {
pluginName = strings.TrimSuffix(pluginName, ".exe")
}
switch pluginName {
case meta.ThriftPluginName:
plugin := new(thrift.Plugin)
os.Exit(plugin.Run())
case meta.ProtocPluginName:
plugin := new(protobuf.Plugin)
os.Exit(plugin.Run())
mode := os.Getenv(meta.EnvPluginMode)
if len(os.Args) <= 1 && mode != "" {
switch mode {
case meta.ThriftPluginName:
plugin := new(thrift.Plugin)
os.Exit(plugin.Run())
case meta.ProtocPluginName:
plugin := new(protobuf.Plugin)
os.Exit(plugin.Run())
}
}
}

Expand Down
58 changes: 9 additions & 49 deletions cmd/hz/config/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,54 +71,6 @@ func lookupTool(idlType string) (string, error) {
}
}

exe, err := os.Executable()
if err != nil {
return "", fmt.Errorf("failed to get executable path: %s", err)
}
gopath, err := util.GetGOPATH()
if err != nil {
return "", err
}
// softlink the plugin to "$GOPATH/bin"
dir := gopath + string(os.PathSeparator) + "bin"
if tool == meta.TpCompilerProto {
pgh, err := exec.LookPath(meta.ProtocPluginName)
linkName := filepath.Join(dir, meta.ProtocPluginName)
if util.IsWindows() {
linkName = linkName + ".exe"
}
if err != nil {
err = link(exe, linkName)
if err != nil {
return "", err
}
} else {
err = link(exe, pgh)
if err != nil {
return "", err
}
}
}

if tool == meta.TpCompilerThrift {
tgh, err := exec.LookPath(meta.ThriftPluginName)
linkName := filepath.Join(dir, meta.ThriftPluginName)
if util.IsWindows() {
linkName = linkName + ".exe"
}
if err != nil {
err = link(exe, linkName)
if err != nil {
return "", err
}
} else {
err = link(exe, tgh)
if err != nil {
return "", err
}
}
}

return path, nil
}

Expand All @@ -136,6 +88,11 @@ func link(src, dst string) error {
}

func BuildPluginCmd(args *Argument) (*exec.Cmd, error) {
exe, err := os.Executable()
if err != nil {
return nil, fmt.Errorf("failed to detect current executable, err: %v", err)
}

argPacks, err := args.Pack()
if err != nil {
return nil, err
Expand All @@ -152,6 +109,7 @@ func BuildPluginCmd(args *Argument) (*exec.Cmd, error) {

if args.IdlType == meta.IdlThrift {
// thriftgo
os.Setenv(meta.EnvPluginMode, meta.ThriftPluginName)
cmd.Args = append(cmd.Args, meta.TpCompilerThrift)
for _, inc := range args.Includes {
cmd.Args = append(cmd.Args, "-i", inc)
Expand All @@ -167,7 +125,7 @@ func BuildPluginCmd(args *Argument) (*exec.Cmd, error) {
cmd.Args = append(cmd.Args,
"-o", args.ModelOutDir(),
"-g", thriftOpt,
"-p", "hertz:"+kas,
"-p", "hertz="+exe+":"+kas,
)
for _, p := range args.ThriftPlugins {
cmd.Args = append(cmd.Args, "-p", p)
Expand All @@ -177,6 +135,7 @@ func BuildPluginCmd(args *Argument) (*exec.Cmd, error) {
}
} else {
// protoc
os.Setenv(meta.EnvPluginMode, meta.ProtocPluginName)
cmd.Args = append(cmd.Args, meta.TpCompilerProto)
for _, inc := range args.Includes {
cmd.Args = append(cmd.Args, "-I", inc)
Expand All @@ -185,6 +144,7 @@ func BuildPluginCmd(args *Argument) (*exec.Cmd, error) {
cmd.Args = append(cmd.Args, "-I", filepath.Dir(inc))
}
cmd.Args = append(cmd.Args,
"--plugin=protoc-gen-hertz="+exe,
"--hertz_out="+args.OutDir,
"--hertz_opt="+kas,
)
Expand Down
3 changes: 3 additions & 0 deletions cmd/hz/generator/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ func (pkgGen *HttpPackageGenerator) updateHandler(handler interface{}, handlerTp
if !isExist {
return pkgGen.TemplateGenerator.Generate(handler, handlerTpl, filePath, noRepeat)
}
if pkgGen.HandlerByMethod { // method by handler, do not need to insert new content
return nil
}

file, err := ioutil.ReadFile(filePath)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion cmd/hz/meta/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package meta
import "runtime"

// Version hz version
const Version = "v0.6.2"
const Version = "v0.6.3"

// Mode hz run modes
type Mode int
Expand All @@ -29,6 +29,8 @@ const SysType = runtime.GOOS

const WindowsOS = "windows"

const EnvPluginMode = "HERTZ_PLUGIN_MODE"

// hz Commands
const (
CmdUpdate = "update"
Expand Down
Loading

0 comments on commit f7b5e2f

Please sign in to comment.