Lookup share object file before compile plugin.
@@ -169,7 +169,13 @@ func builtinCommonInstanceMethods() []*BuiltInMethodObject {
fullPath := filepath.Join(goPath, "src", pkgPath)
_, pkgName := filepath.Split(fullPath)
pkgName = strings.Split(pkgName, ".")[0]
+ soName := filepath.Join("./", pkgName+".so")
+
+ // Open plugin first
+ p, err := plugin.Open(soName)
+ // If there's any issue open a plugin, assume it's not well compiled
+ if err != nil {
cmd := exec.Command("go", "build", "-buildmode=plugin", "-o", fmt.Sprintf("./%s.so", pkgName), fullPath)
out, err := cmd.CombinedOutput()
@@ -177,11 +183,11 @@ func builtinCommonInstanceMethods() []*BuiltInMethodObject {
return t.vm.initErrorObject(InternalError, "Error: %s from %s", string(out), strings.Join(cmd.Args, " "))
}
- soName := filepath.Join("./", pkgName+".so")
+ p, err = plugin.Open(soName)
- p, err := plugin.Open(soName)
if err != nil {
- panic(err)
+ return t.vm.initErrorObject(InternalError, "Error occurs when open %s package: %s", soName, err.Error())
+ }
}
return t.vm.initPluginObject(fullPath, p)
