refactor: relocate build plugin

This commit is contained in:
debugtalk
2022-05-29 12:32:39 +08:00
parent 88f9d63a83
commit 80986858f9
18 changed files with 95 additions and 214 deletions
+13 -11
View File
@@ -10,18 +10,20 @@ import (
"github.com/httprunner/funplugin"
"github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp/internal/build"
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
)
const (
goPluginFile = "debugtalk.so" // built from go plugin
hashicorpGoPluginFile = "debugtalk.bin" // built from hashicorp go plugin
hashicorpPyPluginFile = ".debugtalk_gen.py" // used for hashicorp python plugin, automatically generated by HRP
debugtalkPyFile = "debugtalk.py" // write by user
projectInfoFile = "proj.json" // used for ensuring root project
PluginGoBuiltFile = "debugtalk.so" // built from go official plugin
PluginHashicorpGoBuiltFile = "debugtalk.bin" // built from hashicorp go plugin
PluginGoSourceFile = "debugtalk.go" // golang function plugin source file
PluginGoSourceGenFile = "debugtalk_gen.go" // generated for hashicorp go plugin
PluginPySourceFile = "debugtalk.py" // python function plugin source file
PluginPySourceGenFile = ".debugtalk_gen.py" // generated for hashicorp python plugin
)
const projectInfoFile = "proj.json" // used for ensuring root project
func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, err error) {
// plugin file not found
if path == "" {
@@ -64,16 +66,16 @@ func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, err error) {
func locatePlugin(path string) (pluginPath string, err error) {
// priority: hashicorp plugin (debugtalk.bin > debugtalk.py) > go plugin (debugtalk.so)
pluginPath, err = locateFile(path, hashicorpGoPluginFile)
pluginPath, err = locateFile(path, PluginHashicorpGoBuiltFile)
if err == nil {
return
}
pluginPath, err = locateFile(path, debugtalkPyFile)
pluginPath, err = locateFile(path, PluginPySourceFile)
if err == nil {
// register funppy plugin
genPyPluginPath := filepath.Join(filepath.Dir(pluginPath), hashicorpPyPluginFile)
err = build.Run(pluginPath, genPyPluginPath)
genPyPluginPath := filepath.Join(filepath.Dir(pluginPath), PluginPySourceGenFile)
err = BuildPlugin(pluginPath, genPyPluginPath)
if err != nil {
log.Error().Err(err).Str("path", pluginPath).Msg("build plugin failed")
return
@@ -81,7 +83,7 @@ func locatePlugin(path string) (pluginPath string, err error) {
return genPyPluginPath, nil
}
pluginPath, err = locateFile(path, goPluginFile)
pluginPath, err = locateFile(path, PluginGoBuiltFile)
if err == nil {
return
}