Plugin file name extension adapted to the host OS convention (.so on linux, .dll on windows, .dylib on Darwin/MacOS)
This commit is contained in:
parent
b6b09b2fb1
commit
02df7f1c1f
@ -76,6 +76,12 @@ func isFile(filePath string) bool {
|
||||
|
||||
func searchAmongPath(filename string, dirList []string) (filePath string) {
|
||||
var err error
|
||||
|
||||
suffix := SHAREDLIBRARY_EXTENSION
|
||||
if strings.HasSuffix(filename, ".debug") {
|
||||
suffix += ".debug"
|
||||
}
|
||||
|
||||
for _, dir := range dirList {
|
||||
if dir, err = ExpandPath(dir); err != nil {
|
||||
continue
|
||||
@ -84,6 +90,12 @@ func searchAmongPath(filename string, dirList []string) (filePath string) {
|
||||
filePath = fullPath
|
||||
break
|
||||
}
|
||||
|
||||
subdir := strings.TrimSuffix(filename, suffix)
|
||||
if fullPath := path.Join(dir, subdir, filename); isFile(fullPath) {
|
||||
filePath = fullPath
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
9
lib-ext-darwin.go
Normal file
9
lib-ext-darwin.go
Normal file
@ -0,0 +1,9 @@
|
||||
//go:build darwin
|
||||
|
||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||
// All rights reserved.
|
||||
|
||||
// lib-ext-darwin.go
|
||||
package expr
|
||||
|
||||
const SHAREDLIBRARY_EXTENSION = ".dylib"
|
||||
9
lib-ext-linux.go
Normal file
9
lib-ext-linux.go
Normal file
@ -0,0 +1,9 @@
|
||||
//go:build linux
|
||||
|
||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||
// All rights reserved.
|
||||
|
||||
// lib-ext-linux.go
|
||||
package expr
|
||||
|
||||
const SHAREDLIBRARY_EXTENSION = ".so"
|
||||
9
lib-ext-windows.go
Normal file
9
lib-ext-windows.go
Normal file
@ -0,0 +1,9 @@
|
||||
//go:build windows
|
||||
|
||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||
// All rights reserved.
|
||||
|
||||
// lib-ext-windows.go
|
||||
package expr
|
||||
|
||||
const SHAREDLIBRARY_EXTENSION = ".dll"
|
||||
@ -31,11 +31,11 @@ func pluginExists(name string) (exists bool) {
|
||||
func makePluginName(name string) (decorated string) {
|
||||
var template string
|
||||
if execName, err := os.Executable(); err != nil || !strings.Contains(execName, "debug") {
|
||||
template = "expr-%s-plugin.so"
|
||||
template = "expr-%s-plugin%s"
|
||||
} else {
|
||||
template = "expr-%s-plugin.so.debug"
|
||||
template = "expr-%s-plugin%s.debug"
|
||||
}
|
||||
decorated = fmt.Sprintf(template, name)
|
||||
decorated = fmt.Sprintf(template, name, SHAREDLIBRARY_EXTENSION)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -36,3 +37,23 @@ func TestMakePluginName(t *testing.T) {
|
||||
t.Errorf("makePluginName(%q) failed: Got: %q, Want: %q", name, got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadPluginName(t *testing.T) {
|
||||
name := "json"
|
||||
// want := "expr-" + name + "-plugin.so"
|
||||
want := 1
|
||||
|
||||
os.Setenv("PLUGINS", "${HOME}/go/src/git.portale-stac.it/go")
|
||||
// os.Setenv("EXPR_PLUGIN_PATH", "${PLUGINS}/expr-json-plugin:${PLUGINS}/expr-csv-plugin")
|
||||
os.Setenv("EXPR_PLUGIN_PATH", "${PLUGINS}")
|
||||
got, err := importPluginFromSearchPath(name)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("importPluginFromSearchPath(%q) failed: %v", name, err)
|
||||
return
|
||||
}
|
||||
|
||||
if got != want {
|
||||
t.Errorf("importPluginFromSearchPath(%q) failed: Got: %q, Want: %q", name, got, want)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user